23
2
Introduction
XOR is a digital logic gate that implements an exclusive or. Most of the times, this is shown as ^
. The four possible outcomes in binary:
0 ^ 0 = 0
0 ^ 1 = 1
1 ^ 0 = 1
1 ^ 1 = 0
This can also be seen as addition modulo 2 in binary. In decimal, we need to convert the decimal to binary, 35 = 100011
and 25 = 11001
.To compute the XOR value, we place them on top of each other:
100011
11001 ^
--------
111010 = 58 in decimal
The task: When given an integer value N greater than 1, output an XOR table with the size N + 1. For example, N = 5:
0 1 2 3 4 5
1 0 3 2 5 4
2 3 0 1 6 7
3 2 1 0 7 6
4 5 6 7 0 1
5 4 7 6 1 0
You can see that there is one space in front of each number, because the highest amount in the table has length 1. However, if we take N = 9, we get the following grid:
0 1 2 3 4 5 6 7 8 9
1 0 3 2 5 4 7 6 9 8
2 3 0 1 6 7 4 5 10 11
3 2 1 0 7 6 5 4 11 10
4 5 6 7 0 1 2 3 12 13
5 4 7 6 1 0 3 2 13 12
6 7 4 5 2 3 0 1 14 15
7 6 5 4 3 2 1 0 15 14
8 9 10 11 12 13 14 15 0 1
9 8 11 10 13 12 15 14 1 0
The highest value has length 2, so the value is right-aligned to length 3 (highest length + 1).
Rules:
- Leading whitespace is not mandatory, only if used (or not) consistently
- You must output a table in the form shown above.
- The padding between columns should be as small as possible
- This is code-golf, so the submission with the least amount of bytes wins!
How much padding is allowed between columns? Only the minimal possible amount? – Martin Ender – 2015-12-27T16:01:46.383
@MartinBüttner Yes, the minimal possible amount. I'll add that to the description. – Adnan – 2015-12-27T16:02:22.797
Related http://codegolf.stackexchange.com/questions/67183/a-multiplication-table-for-the-cheela
– edc65 – 2015-12-27T16:13:04.723Looking at the examples
output an XOR table with the size N+1
– edc65 – 2015-12-27T16:38:22.367What is the max value for N? ... (for N==1000000 the size of the table would be near 10 Terabyte) – edc65 – 2015-12-27T17:52:32.190
@edc65 It should 'theoretically' work for N = 1000000, but I'll probably test up to 100 – Adnan – 2015-12-27T18:03:30.073
I'm looking at the diagonals of those squares now…
0
,1 1
,2 0 2
,3 3 3 3
,4 2 0 2 4
,5 5 1 1 5 5
…looks like there might be some interesting properties in there, à la Pascal's Triangle. – Blacklight Shining – 2015-12-28T09:51:29.363I think you need more clarification with regard to the padding. In particular, the example 9*9 grid doesn't look like it has minimal padding to me; there are two spaces between the first and second columns, and you could get away with one without even messing up alignment. – Blacklight Shining – 2015-12-28T09:55:01.227
@BlacklightShining but then the columns would be of different size, I think the padding is right as is now. – edc65 – 2015-12-28T11:00:11.700
Oh hey, it's my avatar! – histocrat – 2015-12-28T18:06:59.973
@histocrat That looks quite nice haha :) – Adnan – 2015-12-28T21:52:03.783
@edc65 Could be worded as minimal padding while keeping all columns the same width, then. – Blacklight Shining – 2015-12-29T22:49:16.070