WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sum and product of an array





Java: public class SumProd
{
 public static void main(final String[] args)
 {
  int sum = 0;
  int prod = 1;
  int[] arg = {1,2,3,4,5};
  for (int i : arg)
  {
   sum += i;
   prod *= i;
  }
 }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .
Task: Sum and product of an array







Python: numbers = [1, 2, 3]
total = sum(numbers)

product = 1
for i in numbers:
    product *= i



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .
Task: Sum and product of an array








VB: Sub Demo()
Dim arr
    arr = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    Debug.Print "sum : " & Application.WorksheetFunction.Sum(arr)
    Debug.Print "product : " & Application.WorksheetFunction.Product(arr)
End Sub


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .
Task: Sum and product of an array




Go: package main

import "fmt"

func main() {
    sum, prod := 0, 1
    for _, x := range []int{1,2,5} {
        sum += x
        prod *= x
    }
    fmt.Println(sum, prod)
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .
Task: Sum and product of an array






PHP: $array = array(1,2,3,4,5,6,7,8,9);
echo array_sum($array);
echo array_product($array);
Task: Sum and product of an array






PHP: $array = array(1,2,3,4,5,6,7,8,9);
echo array_sum($array);
echo array_product($array);






Ada: type Int_Array is array(Integer range <>) of Integer;

array : Int_Array := (1,2,3,4,5,6,7,8,9,10);
Sum : Integer := 0;
for I in array'range loop
   Sum := Sum + array(I);
end loop;
Task: Sum and product of an array






PHP: $array = array(1,2,3,4,5,6,7,8,9);
echo array_sum($array);
echo array_product($array);




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. array-sum-and-product.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       78  Array-Size              VALUE 10.
       01  array-area              VALUE "01020304050607080910".
           03  array               PIC 99 OCCURS Array-Size TIMES.

       01  array-sum               PIC 9(8).
       01  array-product           PIC 9(10) VALUE 1.

       01  i                       PIC 99.

       PROCEDURE DIVISION.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Array-Size < i
               ADD array (i) TO array-sum
               MULTIPLY array (i) BY array-product
           END-PERFORM

           DISPLAY "Sum:     " array-sum
           DISPLAY "Product: " array-product

           GOBACK
           .
Task: 100 doors



C#: namespace ConsoleApplication1
{
    using System;
    class Program
    {
        static void Main(string[] args)
        {
            bool[] doors = new bool[100];

            
            for (int d = 0; d < 100; d++) doors[d] = false;

            
            for (int p = 0; p < 100; p++)
            {
                
                for (int d = 0; d < 100; d++)
                {
                    if ((d + 1) % (p + 1) == 0)
                    {
                        doors[d] = !doors[d];
                    }
                }
            }

            
            Console.WriteLine("Passes Completed!!!  Here are the results: \r\n");
            for (int d = 0; d < 100; d++)
            {
                if (doors[d])
                {
                    Console.WriteLine(String.Format("Door #{0}: Open", d + 1));
                }
                else
                {
                    Console.WriteLine(String.Format("Door #{0}: Closed", d + 1));
                }
            }
            Console.ReadKey(true);
        }
    }
}









Ada: with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Doors is
    type Door_State is (Closed, Open);
    type Door_List is array(Positive range 1..100) of Door_State;
    The_Doors : Door_List := (others => Closed);
 begin
    for I in 1..100 loop
       for J in The_Doors'range loop
          if J mod I = 0 then
             if The_Doors(J) = Closed then
                 The_Doors(J) := Open;
             else
                The_Doors(J) := Closed;
             end if;
          end if;
       end loop;
    end loop;
    for I in The_Doors'range loop
       Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
    end loop;
 end Doors;
Task: 100 doors

C: #include <stdio.h>

int main()
{
  char is_open[100] = { 0 };
  int pass, door;

  
  for (pass = 0; pass < 100; ++pass)
    for (door = pass; door < 100; door += pass+1)
      is_open[door] = !is_open[door];

  
  for (door = 0; door < 100; ++door)
    printf("door #%d is %s.\n", door+1, (is_open[door]? "open" : "closed"));

  return 0;
}











Ada: with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Doors is
    type Door_State is (Closed, Open);
    type Door_List is array(Positive range 1..100) of Door_State;
    The_Doors : Door_List := (others => Closed);
 begin
    for I in 1..100 loop
       for J in The_Doors'range loop
          if J mod I = 0 then
             if The_Doors(J) = Closed then
                 The_Doors(J) := Open;
             else
                The_Doors(J) := Closed;
             end if;
          end if;
       end loop;
    end loop;
    for I in The_Doors'range loop
       Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
    end loop;
 end Doors;
Task: 100 doors


C++: #include <iostream>

int main()
{
  bool is_open[100] = { false };

  
  for (int pass = 0; pass < 100; ++pass)
    for (int door = pass; door < 100; door += pass+1)
      is_open[door] = !is_open[door];

  
  for (int door = 0; door < 100; ++door)
    std::cout << "door #" << door+1 << (is_open[door]? " is open." : " is closed.") << std::endl;
  return 0;
}










Ada: with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Doors is
    type Door_State is (Closed, Open);
    type Door_List is array(Positive range 1..100) of Door_State;
    The_Doors : Door_List := (others => Closed);
 begin
    for I in 1..100 loop
       for J in The_Doors'range loop
          if J mod I = 0 then
             if The_Doors(J) = Closed then
                 The_Doors(J) := Open;
             else
                The_Doors(J) := Closed;
             end if;
          end if;
       end loop;
    end loop;
    for I in The_Doors'range loop
       Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
    end loop;
 end Doors;
Task: 100 doors




Go: package main

import "fmt"

func main() {
    doors := [100]bool{}

    
    for pass := 1; pass <= 100; pass++ {
        for door := pass-1; door < 100; door += pass {
            doors[door] = !doors[door]
        }
    }

    
    for i, v := range doors {
        if v {
            fmt.Print("1")
        } else {
            fmt.Print("0")
        }

        if i%10 == 9 {
            fmt.Print("\n")
        } else {
            fmt.Print(" ")
        }

    }
}








Ada: with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Doors is
    type Door_State is (Closed, Open);
    type Door_List is array(Positive range 1..100) of Door_State;
    The_Doors : Door_List := (others => Closed);
 begin
    for I in 1..100 loop
       for J in The_Doors'range loop
          if J mod I = 0 then
             if The_Doors(J) = Closed then
                 The_Doors(J) := Open;
             else
                The_Doors(J) := Closed;
             end if;
          end if;
       end loop;
    end loop;
    for I in The_Doors'range loop
       Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
    end loop;
 end Doors;
Task: 100 doors





Java: module OneHundredDoors
    {
    @Inject Console console;

    void run()
        {
        Boolean[] doors = new Boolean[100];
        for (Int pass : 0 ..< 100)
            {
            for (Int door = pass; door < 100; door += 1+pass)
                {
                doors[door] = !doors[door];
                }
            }

        console.print($"open doors: {doors.mapIndexed((d, i) -> d ? i+1 : 0).filter(i -> i > 0)}");
        }
    }







Ada: with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Doors is
    type Door_State is (Closed, Open);
    type Door_List is array(Positive range 1..100) of Door_State;
    The_Doors : Door_List := (others => Closed);
 begin
    for I in 1..100 loop
       for J in The_Doors'range loop
          if J mod I = 0 then
             if The_Doors(J) = Closed then
                 The_Doors(J) := Open;
             else
                The_Doors(J) := Closed;
             end if;
          end if;
       end loop;
    end loop;
    for I in The_Doors'range loop
       Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
    end loop;
 end Doors;
Task: 100 doors







Python: var doors = falses(100)

for a in 1..100: for b in a..a..100:
    doors[b] = not doors[b]

for a in 1..100:
    print "Door $a is ${(doors[a]) ? 'open.': 'closed.'}"





Ada: with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Doors is
    type Door_State is (Closed, Open);
    type Door_List is array(Positive range 1..100) of Door_State;
    The_Doors : Door_List := (others => Closed);
 begin
    for I in 1..100 loop
       for J in The_Doors'range loop
          if J mod I = 0 then
             if The_Doors(J) = Closed then
                 The_Doors(J) := Open;
             else
                The_Doors(J) := Closed;
             end if;
          end if;
       end loop;
    end loop;
    for I in The_Doors'range loop
       Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
    end loop;
 end Doors;
Task: 100 doors








VB: dim x as integer, y as integer
dim door(1 to 100) as byte


for x = 1 to 100 : door(x) = 0 : next


for y = 1 to 100
    for x = y to 100 step y
        door(x) = not door(x)
    next x
next y


for x = 1 to 100
    if door(x) then print "Door " + str$(x) + " = open"
next 

while inkey$="":wend
end




Ada: with Ada.Text_Io; use Ada.Text_Io;
 
 procedure Doors is
    type Door_State is (Closed, Open);
    type Door_List is array(Positive range 1..100) of Door_State;
    The_Doors : Door_List := (others => Closed);
 begin
    for I in 1..100 loop
       for J in The_Doors'range loop
          if J mod I = 0 then
             if The_Doors(J) = Closed then
                 The_Doors(J) := Open;
             else
                The_Doors(J) := Closed;
             end if;
          end if;
       end loop;
    end loop;
    for I in The_Doors'range loop
       Put_Line(Integer'Image(I) & " is " & Door_State'Image(The_Doors(I)));
    end loop;
 end Doors;
Task: 100 doors

C: #include <stdio.h>

int main()
{
  char is_open[100] = { 0 };
  int pass, door;

  
  for (pass = 0; pass < 100; ++pass)
    for (door = pass; door < 100; door += pass+1)
      is_open[door] = !is_open[door];

  
  for (door = 0; door < 100; ++door)
    printf("door #%d is %s.\n", door+1, (is_open[door]? "open" : "closed"));

  return 0;
}
Task: 100 doors



C#: namespace ConsoleApplication1
{
    using System;
    class Program
    {
        static void Main(string[] args)
        {
            bool[] doors = new bool[100];

            
            for (int d = 0; d < 100; d++) doors[d] = false;

            
            for (int p = 0; p < 100; p++)
            {
                
                for (int d = 0; d < 100; d++)
                {
                    if ((d + 1) % (p + 1) == 0)
                    {
                        doors[d] = !doors[d];
                    }
                }
            }

            
            Console.WriteLine("Passes Completed!!!  Here are the results: \r\n");
            for (int d = 0; d < 100; d++)
            {
                if (doors[d])
                {
                    Console.WriteLine(String.Format("Door #{0}: Open", d + 1));
                }
                else
                {
                    Console.WriteLine(String.Format("Door #{0}: Closed", d + 1));
                }
            }
            Console.ReadKey(true);
        }
    }
}
Task: 100 doors


C++: #include <iostream>

int main()
{
  bool is_open[100] = { false };

  
  for (int pass = 0; pass < 100; ++pass)
    for (int door = pass; door < 100; door += pass+1)
      is_open[door] = !is_open[door];

  
  for (int door = 0; door < 100; ++door)
    std::cout << "door #" << door+1 << (is_open[door]? " is open." : " is closed.") << std::endl;
  return 0;
}
Task: 100 doors





Java: module OneHundredDoors
    {
    @Inject Console console;

    void run()
        {
        Boolean[] doors = new Boolean[100];
        for (Int pass : 0 ..< 100)
            {
            for (Int door = pass; door < 100; door += 1+pass)
                {
                doors[door] = !doors[door];
                }
            }

        console.print($"open doors: {doors.mapIndexed((d, i) -> d ? i+1 : 0).filter(i -> i > 0)}");
        }
    }
Task: 100 doors







Python: var doors = falses(100)

for a in 1..100: for b in a..a..100:
    doors[b] = not doors[b]

for a in 1..100:
    print "Door $a is ${(doors[a]) ? 'open.': 'closed.'}"
Task: 100 doors








VB: dim x as integer, y as integer
dim door(1 to 100) as byte


for x = 1 to 100 : door(x) = 0 : next


for y = 1 to 100
    for x = y to 100 step y
        door(x) = not door(x)
    next x
next y


for x = 1 to 100
    if door(x) then print "Door " + str$(x) + " = open"
next 

while inkey$="":wend
end
Task: 100 doors




Go: package main

import "fmt"

func main() {
    doors := [100]bool{}

    
    for pass := 1; pass <= 100; pass++ {
        for door := pass-1; door < 100; door += pass {
            doors[door] = !doors[door]
        }
    }

    
    for i, v := range doors {
        if v {
            fmt.Print("1")
        } else {
            fmt.Print("0")
        }

        if i%10 == 9 {
            fmt.Print("\n")
        } else {
            fmt.Print(" ")
        }

    }
}
Task: 100 doors



C#: namespace ConsoleApplication1
{
    using System;
    class Program
    {
        static void Main(string[] args)
        {
            bool[] doors = new bool[100];

            
            for (int d = 0; d < 100; d++) doors[d] = false;

            
            for (int p = 0; p < 100; p++)
            {
                
                for (int d = 0; d < 100; d++)
                {
                    if ((d + 1) % (p + 1) == 0)
                    {
                        doors[d] = !doors[d];
                    }
                }
            }

            
            Console.WriteLine("Passes Completed!!!  Here are the results: \r\n");
            for (int d = 0; d < 100; d++)
            {
                if (doors[d])
                {
                    Console.WriteLine(String.Format("Door #{0}: Open", d + 1));
                }
                else
                {
                    Console.WriteLine(String.Format("Door #{0}: Closed", d + 1));
                }
            }
            Console.ReadKey(true);
        }
    }
}








Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program
Task: 100 doors


C++: #include <iostream>

int main()
{
  bool is_open[100] = { false };

  
  for (int pass = 0; pass < 100; ++pass)
    for (int door = pass; door < 100; door += pass+1)
      is_open[door] = !is_open[door];

  
  for (int door = 0; door < 100; ++door)
    std::cout << "door #" << door+1 << (is_open[door]? " is open." : " is closed.") << std::endl;
  return 0;
}









Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program
Task: 100 doors

C: #include <stdio.h>

int main()
{
  char is_open[100] = { 0 };
  int pass, door;

  
  for (pass = 0; pass < 100; ++pass)
    for (door = pass; door < 100; door += pass+1)
      is_open[door] = !is_open[door];

  
  for (door = 0; door < 100; ++door)
    printf("door #%d is %s.\n", door+1, (is_open[door]? "open" : "closed"));

  return 0;
}










Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program
Task: 100 doors




Go: package main

import "fmt"

func main() {
    doors := [100]bool{}

    
    for pass := 1; pass <= 100; pass++ {
        for door := pass-1; door < 100; door += pass {
            doors[door] = !doors[door]
        }
    }

    
    for i, v := range doors {
        if v {
            fmt.Print("1")
        } else {
            fmt.Print("0")
        }

        if i%10 == 9 {
            fmt.Print("\n")
        } else {
            fmt.Print(" ")
        }

    }
}







Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program
Task: 100 doors





Java: module OneHundredDoors
    {
    @Inject Console console;

    void run()
        {
        Boolean[] doors = new Boolean[100];
        for (Int pass : 0 ..< 100)
            {
            for (Int door = pass; door < 100; door += 1+pass)
                {
                doors[door] = !doors[door];
                }
            }

        console.print($"open doors: {doors.mapIndexed((d, i) -> d ? i+1 : 0).filter(i -> i > 0)}");
        }
    }






Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program
Task: 100 doors







Python: var doors = falses(100)

for a in 1..100: for b in a..a..100:
    doors[b] = not doors[b]

for a in 1..100:
    print "Door $a is ${(doors[a]) ? 'open.': 'closed.'}"




Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program
Task: 100 doors








VB: dim x as integer, y as integer
dim door(1 to 100) as byte


for x = 1 to 100 : door(x) = 0 : next


for y = 1 to 100
    for x = y to 100 step y
        door(x) = not door(x)
    next x
next y


for x = 1 to 100
    if door(x) then print "Door " + str$(x) + " = open"
next 

while inkey$="":wend
end



Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program
Task: 100 doors






PHP: <?php
for ($i = 1; $i <= 100; $i++) {
	$root = sqrt($i);
	$state = ($root == ceil($root)) ? 'open' : 'closed';
	echo "Door {$i}: {$state}\n";
}
?>





Fortran: program doors
    implicit none
    integer, allocatable :: door(:)
    character(6), parameter :: s(0:1) = [character(6) :: "closed", "open"]
    integer :: i, n
  
    print "(A)", "Number of doors?"
    read *, n
    allocate (door(n))
    door = 1
    do i = 1, n
        door(i:n:i) = 1 - door(i:n:i)
        print "(A,G0,2A)", "door ", i, " is ", s(door(i))
    end do
end program