| Bytes | Lang | Time | Link |
|---|---|---|---|
| 014 | Japt | 240924T155512Z | Shaggy |
| 049 | Wolfram Language Mathematica | 211101T043414Z | att |
| 051 | Pari/GP | 211101T062532Z | alephalp |
| 052 | Raku | 211101T194539Z | Sean |
| 047 | Ruby | 211102T085107Z | G B |
| 076 | Python 3 | 211101T081835Z | loopy wa |
| 022 | Charcoal | 211101T094001Z | Neil |
| 013 | 05AB1E | 211101T110736Z | Kevin Cr |
| 067 | Ruby | 211101T104747Z | AZTECCO |
| 052 | Python 2 | 211101T081048Z | dingledo |
| 066 | JavaScript Node.js | 211101T071226Z | tsh |
| 110 | Python 3 | 211101T040105Z | hyper-ne |
Wolfram Language (Mathematica), 50 49 bytes
--Nest[i*=#&/@{##,i=1,1}{1,##,1}&@@#&,{-1},#]/-2&
Returns the (0-indexed) \$n\$th row.
Uses
\$\displaystyle A_{n+1}(m)=A_n(m-1)\oplus\bigoplus_{i\le m}A_n(i)\$,
where \$A_n(m)\$ is the \$m\$th element of row \$n\$.
This can be rewritten \$\displaystyle A_{n+1}(m)=A_n(m)\oplus\bigoplus_{i\le m-2}^{}A_n(i)\$.
Pari/GP, 51 bytes
n->for(i=a=1,n,a=a*x+a/(1-x)%x^(2*i+1));Vecrev(a)%2
0-indexed.
Explanation
See each row as a polynomial, starting with the constant term. a*x prepends a 0 to the list. a/(1-x) takes the cumulative sum of the list. %x^(2*i+1) truncates the list to the first 2*i+1 elements.
Raku, 52 bytes
1,{(1,{[+^] $^x,|(.[^3-1+$++]:v)}...*)[^(2+$_)]}...*
This is an expression for a lazy, infinite sequence of rows.
1, { ... } ... *is the main sequence expression.1is the first row, and the bracketed anonymous function generates the next row from the previous row, passed in$_.(1, { ... } ... *)[^(2 + $_)]likewise generates the elements of each row, starting with 1, from the previous element$^xand the previous row$_. The number of elements in each row is two greater than the size of the previous row:2 + $_.- The numbers to be xor-ed together are
$^x, the previous element of the current row, and.[^3 - 1 + $++]:v, a sliding three-index window across the previous row. The:vadverb causes indexes out of the array's range, both positive and negative, to be skipped. +^is the integer xor operator, and[+^]reduces the list of integers that contribute to the current element using that operator.
Python 3, 98, 92, 88, 77, 76 bytes
v=-4**64;W=w=v*v;v+=w;O=1
while[print(hex(O)[2::32])]:O*=w;O^=O//v&W//v;W*=w
Probably not competitive but I think mildly amusing. Takes advantage of Python arbitary size integers to perform cumulative xor. In fact we simply do a cumulative sum over digits using the divide by 9 (or rather base-1) trick and take the base large enough that carry never becomes an issue.
Runs "forever", only it maxes out at around m=2^23. That's not a principal limitation, just me being cheap on integer constants. n=2^127 (rowindex) which I hope is close enough to eternity.
UPDATE simplified the maths using @dingledooper's formula.
Charcoal, 23 22 bytes
FN«F⊕⊗ιI∨¬ι﹪№KM1²J±ⅈ⊕ⅉ
Try it online! Link is to verbose version of code. Outputs the first n rows as a triangle. Explanation:
FN«
For each row:
F⊕⊗ι
For each bit in the row...
I∨¬ι﹪№KM1²
... output the parity of the number of adjacent 1s, except for the very first bit, which is always a 1.
J±ⅈ⊕ⅉ
Jump to the start of the next row of bits.
05AB1E, 16 14 13 bytes
λb=Å»^}2β₁4*^
Port of @dingledooper's Python 2 answer, but using binary instead of octal integers, so make sure to upvote him/her as well!
-1 byte thanks to @CommandMaster.
Explanation:
λ # Start a recursive method,
# to generate an infinite sequence,
# starting at a(0)=1 by default
# Where every next a(n) is calculated as follows:
b # Convert the current implicit a(n-1) to a binary string
= # Output it with trailing newline (without popping)
Å» # Cumulative left-reduce its bits by:
^ # Bitwise-XORing
} # After the cumulative left-reduce,
2β # Convert it from a binary-list to an integer
₁ # Push a(n-1) again
4* # Multiply it by 4
^ # And Bitwise-XOR it to the integer
Ruby, 67 bytes
f=->r,c{c<0||c>r*2?0:r<1?1:([*c-2..c].sum{|x|f[r-1,x]}+f[r,c-1])%2}
- computes value at
rrow ,ccolumn - Values outside the triangle give 0
Python 2, 52 bytes
Outputs an infinite sequence of rows. As a bonus, it runs extremely slowly.
n=1
while 1:print'%o'%n;x=n;n*=64;exec'n^=x;x/=8;'*x
If the current row expressed in binary is n, the next row will be a(n) ^ n*4, where a(n) is the prefix xor sum of the bits. a(n) is also associated with OEIS A006068.
One annoying little thing about Python is that there is no format string to convert an integer to binary. The next best alternative is octal, which is what the code uses instead.
Python 2, 54 bytes
Adding 2 more bytes gets the program to a reasonable speed.
n=1
while 1:
print'%o'%n;x=n;n*=64
while x:n^=x;x/=8
JavaScript (Node.js), 66 bytes
f=r=>b=r?f(r-1).map(_=>a[++i]=a[i-2]^b[i-3]^b[i],a=[i=1,0])&&a:[1]
Input r, output an array for r-th row.
JavaScript (Node.js), 48 bytes
f=r=>r?(g=a=>a^a/4^b/2^b*4?g(a+1):a)(b=f(r-1)):1
Or output r-th row as an integer if it is allowed.
a
b c d
e f g h i
j k l m n o p
n = m xor g xor h xor i
= (l xor f xor g xor h) xor g xor h xor i
= l xor f xor i
Python 3, 110 bytes
def f(n):
if n<1:return[1]
k=[1];p=f(n-1)+[0,0]
for i in range(n*2):k+=[p[i-1]^p[i]^p[i+1]^k[-1]]
return k
A pretty basic and very sub-par solution to get things started.