WeixiangYan/CodeTransOcean huggingface dataset:
Task: Modular arithmetic




Go: package main

import "fmt"





type ring interface {
    add(ringElement, ringElement) ringElement
    mul(ringElement, ringElement) ringElement
    mulIdent() ringElement
}

type ringElement interface{}



func ringPow(r ring, a ringElement, p uint) (pow ringElement) {
    for pow = r.mulIdent(); p > 0; p-- {
        pow = r.mul(pow, a)
    }
    return
}




type oneRing interface {
    ring
    one() ringElement 
}




func f(r oneRing, x ringElement) ringElement {
    return r.add(r.add(ringPow(r, x, 100), x), r.one())
}




type modRing uint 

func (m modRing) add(a, b ringElement) ringElement {
    return (a.(uint) + b.(uint)) % uint(m)
}

func (m modRing) mul(a, b ringElement) ringElement {
    return (a.(uint) * b.(uint)) % uint(m)
}

func (modRing) mulIdent() ringElement { return uint(1) }

func (modRing) one() ringElement { return uint(1) }




func main() {
    fmt.Println(f(modRing(13), uint(10)))
}







Fortran: module modular_arithmetic
  implicit none

  type :: modular
     integer :: val
     integer :: modulus
  end type modular

  interface operator(+)
     module procedure modular_modular_add
     module procedure modular_integer_add
  end interface operator(+)

  interface operator(**)
     module procedure modular_integer_pow
  end interface operator(**)

contains

  function modular_modular_add (a, b) result (c)
    type(modular), intent(in) :: a
    type(modular), intent(in) :: b
    type(modular) :: c

    if (a%modulus /= b%modulus) error stop
    c%val = modulo (a%val + b%val, a%modulus)
    c%modulus = a%modulus
  end function modular_modular_add

  function modular_integer_add (a, i) result (c)
    type(modular), intent(in) :: a
    integer, intent(in) :: i
    type(modular) :: c

    c%val = modulo (a%val + i, a%modulus)
    c%modulus = a%modulus
  end function modular_integer_add

  function modular_integer_pow (a, i) result (c)
    type(modular), intent(in) :: a
    integer, intent(in) :: i
    type(modular) :: c

    
    
    
    

    integer :: modulus
    integer :: base
    integer :: exponent

    modulus = a%modulus
    exponent = i

    if (modulus < 1) error stop
    if (exponent < 0) error stop

    c%modulus = modulus
    if (modulus == 1) then
       c%val = 0
    else
       c%val = 1
       base = modulo (a%val, modulus)
       do while (exponent > 0)
          if (modulo (exponent, 2) /= 0) then
             c%val = modulo (c%val * base, modulus)
          end if
          exponent = exponent / 2
          base = modulo (base * base, modulus)
       end do
    end if
  end function modular_integer_pow

end module modular_arithmetic




#define f(x) ((x)**100 + (x) + 1)

program modular_arithmetic_task
  use, intrinsic :: iso_fortran_env
  use, non_intrinsic :: modular_arithmetic
  implicit none

  type(modular) :: x, y

  x = modular(10, 13)
  y = f(x)

  write (*, '("    modulus 13:  ", I0)') y%val
  write (*, '("floating point:  ", E55.50)') f(10.0_real64)

end program modular_arithmetic_task
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}









Ada: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;

procedure String_Append is
   Str : Unbounded_String := To_Unbounded_String("Hello");
begin
   Append(Str, ", world!");
   Put_Line(Str);
end String_Append;
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}











Ada: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;

procedure String_Append is
   Str : Unbounded_String := To_Unbounded_String("Hello");
begin
   Append(Str, ", world!");
   Put_Line(Str);
end String_Append;
Task: String append


C++: #include <iostream>
#include <string>

int main( ) {
   std::string greeting( "Hello" ) ;
   greeting.append( " , world!" ) ;
   std::cout << greeting << std::endl ;
   return 0 ;
}










Ada: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;

procedure String_Append is
   Str : Unbounded_String := To_Unbounded_String("Hello");
begin
   Append(Str, ", world!");
   Put_Line(Str);
end String_Append;
Task: String append




Go: s := "foo"
s += "bar"








Ada: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;

procedure String_Append is
   Str : Unbounded_String := To_Unbounded_String("Hello");
begin
   Append(Str, ", world!");
   Put_Line(Str);
end String_Append;
Task: String append





Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());







Ada: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;

procedure String_Append is
   Str : Unbounded_String := To_Unbounded_String("Hello");
begin
   Append(Str, ", world!");
   Put_Line(Str);
end String_Append;
Task: String append







Python: 


str = "12345678";
str += "9!";
print(str)





Ada: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;

procedure String_Append is
   Str : Unbounded_String := To_Unbounded_String("Hello");
begin
   Append(Str, ", world!");
   Put_Line(Str);
end String_Append;
Task: String append








VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function




Ada: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Text_IO.Unbounded_Io; use Ada.Text_IO.Unbounded_IO;

procedure String_Append is
   Str : Unbounded_String := To_Unbounded_String("Hello");
begin
   Append(Str, ", world!");
   Put_Line(Str);
end String_Append;
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}
Task: String append


C++: #include <iostream>
#include <string>

int main( ) {
   std::string greeting( "Hello" ) ;
   greeting.append( " , world!" ) ;
   std::cout << greeting << std::endl ;
   return 0 ;
}
Task: String append





Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());
Task: String append







Python: 


str = "12345678";
str += "9!";
print(str)
Task: String append








VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function
Task: String append




Go: s := "foo"
s += "bar"
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}








Fortran: program main

 character(len=:),allocatable :: str

 str = 'hello'
 str = str//' world'

 write(*,*) str

end program main
Task: String append


C++: #include <iostream>
#include <string>

int main( ) {
   std::string greeting( "Hello" ) ;
   greeting.append( " , world!" ) ;
   std::cout << greeting << std::endl ;
   return 0 ;
}









Fortran: program main

 character(len=:),allocatable :: str

 str = 'hello'
 str = str//' world'

 write(*,*) str

end program main
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}










Fortran: program main

 character(len=:),allocatable :: str

 str = 'hello'
 str = str//' world'

 write(*,*) str

end program main
Task: String append





Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());






Fortran: program main

 character(len=:),allocatable :: str

 str = 'hello'
 str = str//' world'

 write(*,*) str

end program main
Task: String append







Python: 


str = "12345678";
str += "9!";
print(str)




Fortran: program main

 character(len=:),allocatable :: str

 str = 'hello'
 str = str//' world'

 write(*,*) str

end program main
Task: String append








VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function



Fortran: program main

 character(len=:),allocatable :: str

 str = 'hello'
 str = str//' world'

 write(*,*) str

end program main
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}









COBOL:       identification division.                                         
       program-id. string-append.                                       

       data division.
       working-storage section.
       01 some-string.
          05 elements pic x occurs 0 to 80 times depending on limiter.
       01 limiter     usage index value 7.
       01 current     usage index.

       procedure division.
       append-main.

       move "Hello, " to some-string

      
       set current to length of some-string
       set limiter up by 5
       move "world" to some-string(current + 1:)
       display some-string

       goback.
       end program string-append.
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}







COBOL:       identification division.                                         
       program-id. string-append.                                       

       data division.
       working-storage section.
       01 some-string.
          05 elements pic x occurs 0 to 80 times depending on limiter.
       01 limiter     usage index value 7.
       01 current     usage index.

       procedure division.
       append-main.

       move "Hello, " to some-string

      
       set current to length of some-string
       set limiter up by 5
       move "world" to some-string(current + 1:)
       display some-string

       goback.
       end program string-append.
Task: String append


C++: #include <iostream>
#include <string>

int main( ) {
   std::string greeting( "Hello" ) ;
   greeting.append( " , world!" ) ;
   std::cout << greeting << std::endl ;
   return 0 ;
}








COBOL:       identification division.                                         
       program-id. string-append.                                       

       data division.
       working-storage section.
       01 some-string.
          05 elements pic x occurs 0 to 80 times depending on limiter.
       01 limiter     usage index value 7.
       01 current     usage index.

       procedure division.
       append-main.

       move "Hello, " to some-string

      
       set current to length of some-string
       set limiter up by 5
       move "world" to some-string(current + 1:)
       display some-string

       goback.
       end program string-append.
Task: String append





Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());





COBOL:       identification division.                                         
       program-id. string-append.                                       

       data division.
       working-storage section.
       01 some-string.
          05 elements pic x occurs 0 to 80 times depending on limiter.
       01 limiter     usage index value 7.
       01 current     usage index.

       procedure division.
       append-main.

       move "Hello, " to some-string

      
       set current to length of some-string
       set limiter up by 5
       move "world" to some-string(current + 1:)
       display some-string

       goback.
       end program string-append.
Task: String append







Python: 


str = "12345678";
str += "9!";
print(str)



COBOL:       identification division.                                         
       program-id. string-append.                                       

       data division.
       working-storage section.
       01 some-string.
          05 elements pic x occurs 0 to 80 times depending on limiter.
       01 limiter     usage index value 7.
       01 current     usage index.

       procedure division.
       append-main.

       move "Hello, " to some-string

      
       set current to length of some-string
       set limiter up by 5
       move "world" to some-string(current + 1:)
       display some-string

       goback.
       end program string-append.
Task: String append








VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function


COBOL:       identification division.                                         
       program-id. string-append.                                       

       data division.
       working-storage section.
       01 some-string.
          05 elements pic x occurs 0 to 80 times depending on limiter.
       01 limiter     usage index value 7.
       01 current     usage index.

       procedure division.
       append-main.

       move "Hello, " to some-string

      
       set current to length of some-string
       set limiter up by 5
       move "world" to some-string(current + 1:)
       display some-string

       goback.
       end program string-append.
Task: String append




Go: s := "foo"
s += "bar"






COBOL:       identification division.                                         
       program-id. string-append.                                       

       data division.
       working-storage section.
       01 some-string.
          05 elements pic x occurs 0 to 80 times depending on limiter.
       01 limiter     usage index value 7.
       01 current     usage index.

       procedure division.
       append-main.

       move "Hello, " to some-string

      
       set current to length of some-string
       set limiter up by 5
       move "world" to some-string(current + 1:)
       display some-string

       goback.
       end program string-append.
Task: Count in octal



C#: using System;

class Program
{
    static void Main()
    {
        var number = 0;
        do
        {
            Console.WriteLine(Convert.ToString(number, 8));
        } while (++number > 0);
    }
}









Ada: with Ada.Text_IO;

procedure Octal is
   package IIO is new Ada.Text_IO.Integer_IO(Integer);
begin
   for I in 0 .. Integer'Last loop
      IIO.Put(I, Base => 8);
      Ada.Text_IO.New_Line;
   end loop;
end Octal;
Task: Count in octal

C: #include <stdio.h>

int main()
{
        unsigned int i = 0;
        do { printf("%o\n", i++); } while(i);
        return 0;
}











Ada: with Ada.Text_IO;

procedure Octal is
   package IIO is new Ada.Text_IO.Integer_IO(Integer);
begin
   for I in 0 .. Integer'Last loop
      IIO.Put(I, Base => 8);
      Ada.Text_IO.New_Line;
   end loop;
end Octal;
Task: Count in octal


C++: #include <iostream>

int main()
{
  unsigned i = 0;
  do
  {
    std::cout << std::oct << i << std::endl;
    ++i;
  } while(i != 0);
  return 0;
}










Ada: with Ada.Text_IO;

procedure Octal is
   package IIO is new Ada.Text_IO.Integer_IO(Integer);
begin
   for I in 0 .. Integer'Last loop
      IIO.Put(I, Base => 8);
      Ada.Text_IO.New_Line;
   end loop;
end Octal;
Task: Count in octal




Go: package main

import (
    "fmt"
    "math"
)

func main() {
    for i := int8(0); ; i++ {
        fmt.Printf("%o\n", i)
        if i == math.MaxInt8 {
            break
        }
    }
}








Ada: with Ada.Text_IO;

procedure Octal is
   package IIO is new Ada.Text_IO.Integer_IO(Integer);
begin
   for I in 0 .. Integer'Last loop
      IIO.Put(I, Base => 8);
      Ada.Text_IO.New_Line;
   end loop;
end Octal;
Task: Count in octal





Java: public class Count{
    public static void main(String[] args){
        for(int i = 0;i >= 0;i++){
            System.out.println(Integer.toOctalString(i)); 
        }
    }
}







Ada: with Ada.Text_IO;

procedure Octal is
   package IIO is new Ada.Text_IO.Integer_IO(Integer);
begin
   for I in 0 .. Integer'Last loop
      IIO.Put(I, Base => 8);
      Ada.Text_IO.New_Line;
   end loop;
end Octal;
Task: Count in octal







Python: import sys
for n in xrange(sys.maxint):
    print oct(n)





Ada: with Ada.Text_IO;

procedure Octal is
   package IIO is new Ada.Text_IO.Integer_IO(Integer);
begin
   for I in 0 .. Integer'Last loop
      IIO.Put(I, Base => 8);
      Ada.Text_IO.New_Line;
   end loop;
end Octal;
Task: Count in octal








VB: For i = 0 To 20
	WScript.StdOut.WriteLine Oct(i)
Next




Ada: with Ada.Text_IO;

procedure Octal is
   package IIO is new Ada.Text_IO.Integer_IO(Integer);
begin
   for I in 0 .. Integer'Last loop
      IIO.Put(I, Base => 8);
      Ada.Text_IO.New_Line;
   end loop;
end Octal;
Task: Count in octal

C: #include <stdio.h>

int main()
{
        unsigned int i = 0;
        do { printf("%o\n", i++); } while(i);
        return 0;
}
Task: Count in octal



C#: using System;

class Program
{
    static void Main()
    {
        var number = 0;
        do
        {
            Console.WriteLine(Convert.ToString(number, 8));
        } while (++number > 0);
    }
}
Task: Count in octal


C++: #include <iostream>

int main()
{
  unsigned i = 0;
  do
  {
    std::cout << std::oct << i << std::endl;
    ++i;
  } while(i != 0);
  return 0;
}
Task: Count in octal





Java: public class Count{
    public static void main(String[] args){
        for(int i = 0;i >= 0;i++){
            System.out.println(Integer.toOctalString(i)); 
        }
    }
}
Task: Count in octal







Python: import sys
for n in xrange(sys.maxint):
    print oct(n)
Task: Count in octal








VB: For i = 0 To 20
	WScript.StdOut.WriteLine Oct(i)
Next
Task: Count in octal




Go: package main

import (
    "fmt"
    "math"
)

func main() {
    for i := int8(0); ; i++ {
        fmt.Printf("%o\n", i)
        if i == math.MaxInt8 {
            break
        }
    }
}
Task: Count in octal



C#: using System;

class Program
{
    static void Main()
    {
        var number = 0;
        do
        {
            Console.WriteLine(Convert.ToString(number, 8));
        } while (++number > 0);
    }
}








Fortran: program Octal
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0
  


  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program
Task: Count in octal


C++: #include <iostream>

int main()
{
  unsigned i = 0;
  do
  {
    std::cout << std::oct << i << std::endl;
    ++i;
  } while(i != 0);
  return 0;
}









Fortran: program Octal
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0
  


  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program
Task: Count in octal

C: #include <stdio.h>

int main()
{
        unsigned int i = 0;
        do { printf("%o\n", i++); } while(i);
        return 0;
}










Fortran: program Octal
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0
  


  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program
Task: Count in octal





Java: public class Count{
    public static void main(String[] args){
        for(int i = 0;i >= 0;i++){
            System.out.println(Integer.toOctalString(i)); 
        }
    }
}






Fortran: program Octal
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0
  


  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program
Task: Count in octal







Python: import sys
for n in xrange(sys.maxint):
    print oct(n)




Fortran: program Octal
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0
  


  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program
Task: Count in octal








VB: For i = 0 To 20
	WScript.StdOut.WriteLine Oct(i)
Next



Fortran: program Octal
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0
  


  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program
Task: Count in octal






PHP: <?php
for ($n = 0; is_int($n); $n++) {
  echo decoct($n), "\n";
}
?>





Fortran: program Octal
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 0
  


  do while(n >= 0)
    write(*, "(o0)") n
    n = n + 1
  end do
end program
Task: Count in octal

C: #include <stdio.h>

int main()
{
        unsigned int i = 0;
        do { printf("%o\n", i++); } while(i);
        return 0;
}









COBOL:        >>SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. count-in-octal.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
    FUNCTION dec-to-oct
    .
DATA DIVISION.
WORKING-STORAGE SECTION.
01  i                                   PIC 9(18).

PROCEDURE DIVISION.
    PERFORM VARYING i FROM 1 BY 1 UNTIL i = 0
        DISPLAY FUNCTION dec-to-oct(i)
    END-PERFORM
    .
END PROGRAM count-in-octal.


IDENTIFICATION DIVISION.
FUNCTION-ID. dec-to-oct.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01  rem                                 PIC 9.

01  dec                                 PIC 9(18).

LINKAGE SECTION.
01  dec-arg                             PIC 9(18).

01  oct                                 PIC 9(18).

PROCEDURE DIVISION USING dec-arg RETURNING oct.
    MOVE dec-arg TO dec 
    PERFORM WITH TEST AFTER UNTIL dec = 0
        MOVE FUNCTION REM(dec, 8) TO rem
        STRING rem, oct DELIMITED BY SPACES INTO oct
        DIVIDE 8 INTO dec
    END-PERFORM
    .
END FUNCTION dec-to-oct.