Thue-Morse: Difference between revisions
Content added Content deleted
m (→{{header|Pascal}}: use a function with length set once. 50% faster than before. ^ v as alias for 0 1) |
(Added C implementation) |
||
Line 36: | Line 36: | ||
<lang AWK>BEGIN{print x="0"} |
<lang AWK>BEGIN{print x="0"} |
||
{gsub(/./," &",x);gsub(/ 0/,"01",x);gsub(/ 1/,"10",x);print x}</lang> |
{gsub(/./," &",x);gsub(/ 0/,"01",x);gsub(/ 1/,"10",x);print x}</lang> |
||
=={{header|C}}== |
|||
{{trans|Java}} |
|||
<lang c>#include <stdio.h> |
|||
#include <stdlib.h> |
|||
#include <string.h> |
|||
int main(int argc, char *argv[]){ |
|||
char *sequence = malloc(256+1); |
|||
char *inverse = malloc(256+1); |
|||
char *buffer = malloc(256+1); |
|||
int i; |
|||
strcpy(sequence, "0"); |
|||
strcpy(inverse, "1"); |
|||
for(i = 0; i < 8; i++){ |
|||
strcpy(buffer, sequence); |
|||
strcat(sequence, inverse); |
|||
strcat(inverse, buffer); |
|||
} |
|||
puts(sequence); |
|||
return 0; |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110 |
|||
</pre> |
|||
=={{header|C++}}== |
=={{header|C++}}== |