WeixiangYan/CodeTransOcean huggingface dataset:
Task: String concatenation





Java: public class Str{
   public static void main(String[] args){
      String s = "hello";
      System.out.println(s + " literal");
      String s2 = s + " literal";
      System.out.println(s2);
   }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Concat.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str  PIC X(7) VALUE "Hello, ".
       01  Str2 PIC X(15).

       PROCEDURE DIVISION.
           DISPLAY "Str  : " Str
           STRING Str " World!" DELIMITED BY SIZE INTO Str2
           DISPLAY "Str2 : " Str2

           GOBACK
           .
Task: String concatenation







Python: s1 = "hello"
print s1 + " world"

s2 = s1 + " world"
print s2



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Concat.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str  PIC X(7) VALUE "Hello, ".
       01  Str2 PIC X(15).

       PROCEDURE DIVISION.
           DISPLAY "Str  : " Str
           STRING Str " World!" DELIMITED BY SIZE INTO Str2
           DISPLAY "Str2 : " Str2

           GOBACK
           .
Task: String concatenation








VB: Option Explicit

Sub String_Concatenation()
Dim str1 As String, str2 As String

    str1 = "Rosetta"
    Debug.Print str1
    Debug.Print str1 & " code!"
    str2 = str1 & " code..."
    Debug.Print str2 & " based on concatenation of : " & str1 & " and code..."
End Sub


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Concat.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str  PIC X(7) VALUE "Hello, ".
       01  Str2 PIC X(15).

       PROCEDURE DIVISION.
           DISPLAY "Str  : " Str
           STRING Str " World!" DELIMITED BY SIZE INTO Str2
           DISPLAY "Str2 : " Str2

           GOBACK
           .
Task: String concatenation




Go: package main

import "fmt"

func main() {
    
    s := "hello"

    
    fmt.Println(s)

    
    
    fmt.Println(s + " literal")

    
    s2 := s + " literal"

    
    fmt.Println(s2)
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Concat.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str  PIC X(7) VALUE "Hello, ".
       01  Str2 PIC X(15).

       PROCEDURE DIVISION.
           DISPLAY "Str  : " Str
           STRING Str " World!" DELIMITED BY SIZE INTO Str2
           DISPLAY "Str2 : " Str2

           GOBACK
           .
Task: String concatenation






PHP: <?php
$s = "hello";
echo $s . " literal" . "\n";
$s1 = $s . " literal";
echo $s1 . "\n";
?>
Task: String concatenation






PHP: <?php
$s = "hello";
echo $s . " literal" . "\n";
$s1 = $s . " literal";
echo $s1 . "\n";
?>






Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure String_Concatenation is
   S1 : constant String := "Hello";
   S2 : constant String := S1 & " literal";
begin
   Put_Line (S1);
   Put_Line (S2);
end String_Concatenation;
Task: String concatenation






PHP: <?php
$s = "hello";
echo $s . " literal" . "\n";
$s1 = $s . " literal";
echo $s1 . "\n";
?>




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Concat.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  Str  PIC X(7) VALUE "Hello, ".
       01  Str2 PIC X(15).

       PROCEDURE DIVISION.
           DISPLAY "Str  : " Str
           STRING Str " World!" DELIMITED BY SIZE INTO Str2
           DISPLAY "Str2 : " Str2

           GOBACK
           .
Task: Program termination



C#: if (problem)
{
   Environment.Exit(1);
}









Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}











Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}










Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Program termination




Go: func main() {
    if problem {
        return
    }
}








Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Program termination





Java: if(problem){
   System.exit(integerErrorCode); 
   
   
   
}







Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Program termination







Python: import sys
if problem:
    sys.exit(1)





Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Program termination








VB: 
If problem then End

If problem then Application.Quit





Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}
Task: Program termination





Java: if(problem){
   System.exit(integerErrorCode); 
   
   
   
}
Task: Program termination



C#: if (problem)
{
   Environment.Exit(1);
}
Task: Program termination







Python: import sys
if problem:
    sys.exit(1)
Task: Program termination








VB: 
If problem then End

If problem then Application.Quit
Task: Program termination




Go: func main() {
    if problem {
        return
    }
}
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}









Fortran: IF (condition) STOP [message]
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}










Fortran: IF (condition) STOP [message]
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}









COBOL: IF problem
    STOP RUN
END-IF
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}








COBOL: IF problem
    STOP RUN
END-IF
Task: Program termination






PHP: if (problem)
    exit(1);
Task: Program termination






PHP: if (problem)
    exit(1);






Ada: with Ada.Task_Identification;  use Ada.Task_Identification;

procedure Main is
   
begin
   
   if some_condition then
      Abort_Task (Current_Task);
   end if;
end Main;
Task: Thue-Morse



C#: using System;
using System.Text;

namespace ThueMorse
{
    class Program
    {
        static void Main(string[] args)
        {
            Sequence(6);
        }

        public static void Sequence(int steps)
        {
            var sb1 = new StringBuilder("0");
            var sb2 = new StringBuilder("1");
            for (int i = 0; i < steps; i++)
            {
                var tmp = sb1.ToString();
                sb1.Append(sb2);
                sb2.Append(tmp);
            }
            Console.WriteLine(sb1);
            Console.ReadLine();
        }
    }
}









Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Thue_Morse is
   
   function Replace(S: String) return String is
      
      (if S'Length = 0 then "" 
      else (if S(S'First) = '0' then "01" else "10") & 
	Replace(S(S'First+1 .. S'Last)));
      
   function Sequence (N: Natural) return String is
      (if N=0 then "0" else Replace(Sequence(N-1)));   
      
begin
   for I in 0 .. 6 loop
      Ada.Text_IO.Put_Line(Integer'Image(I) & ": " & Sequence(I));
   end loop;
end Thue_Morse;
Task: Thue-Morse

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]){
	char sequence[256+1] = "0";
	char inverse[256+1] = "1";
	char buffer[256+1];
	int i;
	
	for(i = 0; i < 8; i++){
		strcpy(buffer, sequence);
		strcat(sequence, inverse);
		strcat(inverse, buffer);
	}
	
	puts(sequence);
	return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Thue_Morse is
   
   function Replace(S: String) return String is
      
      (if S'Length = 0 then "" 
      else (if S(S'First) = '0' then "01" else "10") & 
	Replace(S(S'First+1 .. S'Last)));
      
   function Sequence (N: Natural) return String is
      (if N=0 then "0" else Replace(Sequence(N-1)));   
      
begin
   for I in 0 .. 6 loop
      Ada.Text_IO.Put_Line(Integer'Image(I) & ": " & Sequence(I));
   end loop;
end Thue_Morse;
Task: Thue-Morse


C++: #include <iostream>
#include <iterator>
#include <vector>
int main( int argc, char* argv[] ) {
    std::vector<bool> t;
    t.push_back( 0 );
    size_t len = 1;
    std::cout << t[0] << "\n";
    do {
        for( size_t x = 0; x < len; x++ )
            t.push_back( t[x] ? 0 : 1 );
        std::copy( t.begin(), t.end(), std::ostream_iterator<bool>( std::cout ) );
        std::cout << "\n";
        len = t.size();
    } while( len < 60 );
    return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Thue_Morse is
   
   function Replace(S: String) return String is
      
      (if S'Length = 0 then "" 
      else (if S(S'First) = '0' then "01" else "10") & 
	Replace(S(S'First+1 .. S'Last)));
      
   function Sequence (N: Natural) return String is
      (if N=0 then "0" else Replace(Sequence(N-1)));   
      
begin
   for I in 0 .. 6 loop
      Ada.Text_IO.Put_Line(Integer'Image(I) & ": " & Sequence(I));
   end loop;
end Thue_Morse;
Task: Thue-Morse




Go: 

package main

import (
    "fmt"
    "bytes"
)



func nextTMSequenceMember( tmBuffer * bytes.Buffer ) {
    
    for b, currLength, currBytes := 0, tmBuffer.Len(), tmBuffer.Bytes() ; b < currLength; b ++ {
        if currBytes[ b ] == '1' {
            tmBuffer.WriteByte( '0' )
        } else {
            tmBuffer.WriteByte( '1' )
        }
    }
}
    
func main() {
    var tmBuffer bytes.Buffer
    
    tmBuffer.WriteByte( '0' )
    fmt.Println( tmBuffer.String() )
    for i := 2; i <= 7; i ++ {
        nextTMSequenceMember( & tmBuffer )
        fmt.Println( tmBuffer.String() )
    }
}








Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Thue_Morse is
   
   function Replace(S: String) return String is
      
      (if S'Length = 0 then "" 
      else (if S(S'First) = '0' then "01" else "10") & 
	Replace(S(S'First+1 .. S'Last)));
      
   function Sequence (N: Natural) return String is
      (if N=0 then "0" else Replace(Sequence(N-1)));   
      
begin
   for I in 0 .. 6 loop
      Ada.Text_IO.Put_Line(Integer'Image(I) & ": " & Sequence(I));
   end loop;
end Thue_Morse;
Task: Thue-Morse





Java: public class ThueMorse {

    public static void main(String[] args) {
        sequence(6);
    }

    public static void sequence(int steps) {
        StringBuilder sb1 = new StringBuilder("0");
        StringBuilder sb2 = new StringBuilder("1");
        for (int i = 0; i < steps; i++) {
            String tmp = sb1.toString();
            sb1.append(sb2);
            sb2.append(tmp);
        }
        System.out.println(sb1);
    }
}







Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Thue_Morse is
   
   function Replace(S: String) return String is
      
      (if S'Length = 0 then "" 
      else (if S(S'First) = '0' then "01" else "10") & 
	Replace(S(S'First+1 .. S'Last)));
      
   function Sequence (N: Natural) return String is
      (if N=0 then "0" else Replace(Sequence(N-1)));   
      
begin
   for I in 0 .. 6 loop
      Ada.Text_IO.Put_Line(Integer'Image(I) & ": " & Sequence(I));
   end loop;
end Thue_Morse;
Task: Thue-Morse







Python: m='0'
print(m)
for i in range(0,6):
     m0=m
     m=m.replace('0','a')
     m=m.replace('1','0')
     m=m.replace('a','1')
     m=m0+m
     print(m)





Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Thue_Morse is
   
   function Replace(S: String) return String is
      
      (if S'Length = 0 then "" 
      else (if S(S'First) = '0' then "01" else "10") & 
	Replace(S(S'First+1 .. S'Last)));
      
   function Sequence (N: Natural) return String is
      (if N=0 then "0" else Replace(Sequence(N-1)));   
      
begin
   for I in 0 .. 6 loop
      Ada.Text_IO.Put_Line(Integer'Image(I) & ": " & Sequence(I));
   end loop;
end Thue_Morse;
Task: Thue-Morse








VB: Option Explicit

Sub Main()
Dim i&, t$
    For i = 1 To 8
        t = Thue_Morse(t)
        Debug.Print i & ":=> " & t
    Next
End Sub

Private Function Thue_Morse(s As String) As String
Dim k$
    If s = "" Then
        k = "0"
    Else
        k = s
        k = Replace(k, "1", "2")
        k = Replace(k, "0", "1")
        k = Replace(k, "2", "0")
    End If
    Thue_Morse = s & k
End Function




Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Thue_Morse is
   
   function Replace(S: String) return String is
      
      (if S'Length = 0 then "" 
      else (if S(S'First) = '0' then "01" else "10") & 
	Replace(S(S'First+1 .. S'Last)));
      
   function Sequence (N: Natural) return String is
      (if N=0 then "0" else Replace(Sequence(N-1)));   
      
begin
   for I in 0 .. 6 loop
      Ada.Text_IO.Put_Line(Integer'Image(I) & ": " & Sequence(I));
   end loop;
end Thue_Morse;
Task: Thue-Morse

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]){
	char sequence[256+1] = "0";
	char inverse[256+1] = "1";
	char buffer[256+1];
	int i;
	
	for(i = 0; i < 8; i++){
		strcpy(buffer, sequence);
		strcat(sequence, inverse);
		strcat(inverse, buffer);
	}
	
	puts(sequence);
	return 0;
}
Task: Thue-Morse



C#: using System;
using System.Text;

namespace ThueMorse
{
    class Program
    {
        static void Main(string[] args)
        {
            Sequence(6);
        }

        public static void Sequence(int steps)
        {
            var sb1 = new StringBuilder("0");
            var sb2 = new StringBuilder("1");
            for (int i = 0; i < steps; i++)
            {
                var tmp = sb1.ToString();
                sb1.Append(sb2);
                sb2.Append(tmp);
            }
            Console.WriteLine(sb1);
            Console.ReadLine();
        }
    }
}
Task: Thue-Morse


C++: #include <iostream>
#include <iterator>
#include <vector>
int main( int argc, char* argv[] ) {
    std::vector<bool> t;
    t.push_back( 0 );
    size_t len = 1;
    std::cout << t[0] << "\n";
    do {
        for( size_t x = 0; x < len; x++ )
            t.push_back( t[x] ? 0 : 1 );
        std::copy( t.begin(), t.end(), std::ostream_iterator<bool>( std::cout ) );
        std::cout << "\n";
        len = t.size();
    } while( len < 60 );
    return 0;
}
Task: Thue-Morse





Java: public class ThueMorse {

    public static void main(String[] args) {
        sequence(6);
    }

    public static void sequence(int steps) {
        StringBuilder sb1 = new StringBuilder("0");
        StringBuilder sb2 = new StringBuilder("1");
        for (int i = 0; i < steps; i++) {
            String tmp = sb1.toString();
            sb1.append(sb2);
            sb2.append(tmp);
        }
        System.out.println(sb1);
    }
}
Task: Thue-Morse







Python: m='0'
print(m)
for i in range(0,6):
     m0=m
     m=m.replace('0','a')
     m=m.replace('1','0')
     m=m.replace('a','1')
     m=m0+m
     print(m)
Task: Thue-Morse








VB: Option Explicit

Sub Main()
Dim i&, t$
    For i = 1 To 8
        t = Thue_Morse(t)
        Debug.Print i & ":=> " & t
    Next
End Sub

Private Function Thue_Morse(s As String) As String
Dim k$
    If s = "" Then
        k = "0"
    Else
        k = s
        k = Replace(k, "1", "2")
        k = Replace(k, "0", "1")
        k = Replace(k, "2", "0")
    End If
    Thue_Morse = s & k
End Function
Task: Thue-Morse




Go: 

package main

import (
    "fmt"
    "bytes"
)



func nextTMSequenceMember( tmBuffer * bytes.Buffer ) {
    
    for b, currLength, currBytes := 0, tmBuffer.Len(), tmBuffer.Bytes() ; b < currLength; b ++ {
        if currBytes[ b ] == '1' {
            tmBuffer.WriteByte( '0' )
        } else {
            tmBuffer.WriteByte( '1' )
        }
    }
}
    
func main() {
    var tmBuffer bytes.Buffer
    
    tmBuffer.WriteByte( '0' )
    fmt.Println( tmBuffer.String() )
    for i := 2; i <= 7; i ++ {
        nextTMSequenceMember( & tmBuffer )
        fmt.Println( tmBuffer.String() )
    }
}
Task: Thue-Morse



C#: using System;
using System.Text;

namespace ThueMorse
{
    class Program
    {
        static void Main(string[] args)
        {
            Sequence(6);
        }

        public static void Sequence(int steps)
        {
            var sb1 = new StringBuilder("0");
            var sb2 = new StringBuilder("1");
            for (int i = 0; i < steps; i++)
            {
                var tmp = sb1.ToString();
                sb1.Append(sb2);
                sb2.Append(tmp);
            }
            Console.WriteLine(sb1);
            Console.ReadLine();
        }
    }
}








Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse


C++: #include <iostream>
#include <iterator>
#include <vector>
int main( int argc, char* argv[] ) {
    std::vector<bool> t;
    t.push_back( 0 );
    size_t len = 1;
    std::cout << t[0] << "\n";
    do {
        for( size_t x = 0; x < len; x++ )
            t.push_back( t[x] ? 0 : 1 );
        std::copy( t.begin(), t.end(), std::ostream_iterator<bool>( std::cout ) );
        std::cout << "\n";
        len = t.size();
    } while( len < 60 );
    return 0;
}









Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]){
	char sequence[256+1] = "0";
	char inverse[256+1] = "1";
	char buffer[256+1];
	int i;
	
	for(i = 0; i < 8; i++){
		strcpy(buffer, sequence);
		strcat(sequence, inverse);
		strcat(inverse, buffer);
	}
	
	puts(sequence);
	return 0;
}










Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse




Go: 

package main

import (
    "fmt"
    "bytes"
)



func nextTMSequenceMember( tmBuffer * bytes.Buffer ) {
    
    for b, currLength, currBytes := 0, tmBuffer.Len(), tmBuffer.Bytes() ; b < currLength; b ++ {
        if currBytes[ b ] == '1' {
            tmBuffer.WriteByte( '0' )
        } else {
            tmBuffer.WriteByte( '1' )
        }
    }
}
    
func main() {
    var tmBuffer bytes.Buffer
    
    tmBuffer.WriteByte( '0' )
    fmt.Println( tmBuffer.String() )
    for i := 2; i <= 7; i ++ {
        nextTMSequenceMember( & tmBuffer )
        fmt.Println( tmBuffer.String() )
    }
}







Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse





Java: public class ThueMorse {

    public static void main(String[] args) {
        sequence(6);
    }

    public static void sequence(int steps) {
        StringBuilder sb1 = new StringBuilder("0");
        StringBuilder sb2 = new StringBuilder("1");
        for (int i = 0; i < steps; i++) {
            String tmp = sb1.toString();
            sb1.append(sb2);
            sb2.append(tmp);
        }
        System.out.println(sb1);
    }
}






Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse







Python: m='0'
print(m)
for i in range(0,6):
     m0=m
     m=m.replace('0','a')
     m=m.replace('1','0')
     m=m.replace('a','1')
     m=m0+m
     print(m)




Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse








VB: Option Explicit

Sub Main()
Dim i&, t$
    For i = 1 To 8
        t = Thue_Morse(t)
        Debug.Print i & ":=> " & t
    Next
End Sub

Private Function Thue_Morse(s As String) As String
Dim k$
    If s = "" Then
        k = "0"
    Else
        k = s
        k = Replace(k, "1", "2")
        k = Replace(k, "0", "1")
        k = Replace(k, "2", "0")
    End If
    Thue_Morse = s & k
End Function



Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse






PHP: <?php

function thueMorseSequence($length) {
    $sequence = '';
    for ($digit = $n = 0 ; $n < $length ; $n++) {
        $x = $n ^ ($n - 1);
        if (($x ^ ($x >> 1)) & 0x55555555) {
            $digit = 1 - $digit;
        }
        $sequence .= $digit;
    }
    return $sequence;
}

for ($n = 10 ; $n <= 100 ; $n += 10) {
    echo sprintf('%3d', $n), ' : ', thueMorseSequence($n), PHP_EOL;
}





Fortran: program thue_morse
  implicit none
  logical :: f(32) = .false.
  integer :: n = 1

  do
    write(*,*) f(1:n)
    if (n > size(f)/2) exit  
    f(n+1:2*n) = .not. f(1:n)
    n = n * 2
  end do
  
end program thue_morse
Task: Thue-Morse

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[]){
	char sequence[256+1] = "0";
	char inverse[256+1] = "1";
	char buffer[256+1];
	int i;
	
	for(i = 0; i < 8; i++){
		strcpy(buffer, sequence);
		strcat(sequence, inverse);
		strcat(inverse, buffer);
	}
	
	puts(sequence);
	return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. THUE-MORSE.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 STRINGS.
          03 CURRENT-STATE      PIC X(64).
          03 TEMP               PIC X(64).

       PROCEDURE DIVISION.
       BEGIN.
           MOVE "0" TO CURRENT-STATE.
           PERFORM THUE-MORSE-STEP 8 TIMES.
           DISPLAY CURRENT-STATE.
           STOP RUN.

       THUE-MORSE-STEP.
           MOVE CURRENT-STATE TO TEMP.
           INSPECT TEMP REPLACING ALL '0' BY 'X'.
           INSPECT TEMP REPLACING ALL '1' BY '0'.
           INSPECT TEMP REPLACING ALL 'X' BY '1'.
           STRING CURRENT-STATE DELIMITED BY SPACE,
                  TEMP DELIMITED BY SPACE
                  INTO CURRENT-STATE.