Task

Create a Thue-Morse sequence.



See also
   YouTube entry: The Fairest Sharing Sequence Ever
   YouTube entry: Math and OCD - My story with the Thue-Morse sequence
   Task: Fairshare between two and more


include "cowgol.coh";
 
# Find the N'th digit in the Thue-Morse sequence
sub tm(n: uint32): (d: uint8) is
    var n2 := n;
    while n2 != 0 loop
        n2 := n2 >> 1;
        n := n ^ n2;
    end loop;
    d := (n & 1) as uint8;
end sub;
 
# Print the first 64 digits
var i: uint32 := 0;
while i < 64 loop
    print_char('0' + tm(i));
    i := i + 1;
end loop;
print_nl();