WeixiangYan/CodeTransOcean huggingface dataset:
Task: Array length





Java: String[] array  = ["apple", "orange"];
Int      length = array.size;







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

procedure Array_Length is
   Fruits : constant array (Positive range <>) of access constant String
      := (new String'("orange"),
          new String'("apple"));

begin
   for Fruit of Fruits loop
      Ada.Text_IO.Put (Integer'Image (Fruit'Length));
   end loop;

   Ada.Text_IO.Put_Line ("  Array Size : " & Integer'Image (Fruits'Length));
end Array_Length;
Task: Array length







Python: arr = ['apple', 'orange']  

def setup():
    println(len(arr))





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

procedure Array_Length is
   Fruits : constant array (Positive range <>) of access constant String
      := (new String'("orange"),
          new String'("apple"));

begin
   for Fruit of Fruits loop
      Ada.Text_IO.Put (Integer'Image (Fruit'Length));
   end loop;

   Ada.Text_IO.Put_Line ("  Array Size : " & Integer'Image (Fruits'Length));
end Array_Length;
Task: Array length








VB: Debug.Print "Array Length: " & UBound(Array("apple", "orange")) + 1




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

procedure Array_Length is
   Fruits : constant array (Positive range <>) of access constant String
      := (new String'("orange"),
          new String'("apple"));

begin
   for Fruit of Fruits loop
      Ada.Text_IO.Put (Integer'Image (Fruit'Length));
   end loop;

   Ada.Text_IO.Put_Line ("  Array Size : " & Integer'Image (Fruits'Length));
end Array_Length;
Task: Array length

C: #include <stdio.h>

int main()
{    
    const char *fruit[2] = { "apples", "oranges" };

    
    

    
    
    

    
    
    int length = sizeof(fruit) / sizeof(fruit[0]);

    printf("%d\n", length);

    return 0;
}
Task: Array length



C#: using System;

namespace ArrayLength
{
  class Program
  {
    public static void Main()
    {
      var array = new String[]("apple", "orange");
      Console.WriteLine(array.Count);
      delete(array);
    }
  }
}
Task: Array length


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

int main() 
{
    std::array<std::string, 2> fruit { "apples", "oranges" };
    std::cout << fruit.size();
    return 0;
}
Task: Array length





Java: String[] array  = ["apple", "orange"];
Int      length = array.size;
Task: Array length







Python: arr = ['apple', 'orange']  

def setup():
    println(len(arr))
Task: Array length








VB: Debug.Print "Array Length: " & UBound(Array("apple", "orange")) + 1
Task: Array length




Go: package main

import "fmt"

func main() {
	arr := [...]string{"apple", "orange", "pear"}

	fmt.Printf("Length of %v is %v.\n", arr, len(arr))
}
Task: Array length



C#: using System;

namespace ArrayLength
{
  class Program
  {
    public static void Main()
    {
      var array = new String[]("apple", "orange");
      Console.WriteLine(array.Count);
      delete(array);
    }
  }
}








Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length


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

int main() 
{
    std::array<std::string, 2> fruit { "apples", "oranges" };
    std::cout << fruit.size();
    return 0;
}









Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length

C: #include <stdio.h>

int main()
{    
    const char *fruit[2] = { "apples", "oranges" };

    
    

    
    
    

    
    
    int length = sizeof(fruit) / sizeof(fruit[0]);

    printf("%d\n", length);

    return 0;
}










Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length




Go: package main

import "fmt"

func main() {
	arr := [...]string{"apple", "orange", "pear"}

	fmt.Printf("Length of %v is %v.\n", arr, len(arr))
}







Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length





Java: String[] array  = ["apple", "orange"];
Int      length = array.size;






Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length







Python: arr = ['apple', 'orange']  

def setup():
    println(len(arr))




Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length








VB: Debug.Print "Array Length: " & UBound(Array("apple", "orange")) + 1



Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length






PHP: print count(['apple', 'orange']); // Returns 2





Fortran:       MODULE EXAMPLE
       CONTAINS
        SUBROUTINE ABOUND(A)
         CHARACTER*(*) A(:)	
          WRITE (6,*) "Lower bound",LBOUND(A),", Upper bound",UBOUND(A)
          WRITE (6,*) "Element size",LEN(A(LBOUND(A)))
          WRITE (6,*) A
        END SUBROUTINE ABOUND
      END MODULE EXAMPLE

      PROGRAM SHOWBOUNDS
       USE EXAMPLE
       CHARACTER*6 ARRAY(-1:1)
        ARRAY(-1) = "Apple"
        ARRAY(0) = "Orange"
        ARRAY(1) = ""
        CALL ABOUND(ARRAY)
        WRITE (6,*) "But, when it is at home..."
        WRITE (6,*) "L. bound",LBOUND(ARRAY),", U. bound",UBOUND(ARRAY)
      END
Task: Array length

C: #include <stdio.h>

int main()
{    
    const char *fruit[2] = { "apples", "oranges" };

    
    

    
    
    

    
    
    int length = sizeof(fruit) / sizeof(fruit[0]);

    printf("%d\n", length);

    return 0;
}









COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Array length



C#: using System;

namespace ArrayLength
{
  class Program
  {
    public static void Main()
    {
      var array = new String[]("apple", "orange");
      Console.WriteLine(array.Count);
      delete(array);
    }
  }
}







COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Array length


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

int main() 
{
    std::array<std::string, 2> fruit { "apples", "oranges" };
    std::cout << fruit.size();
    return 0;
}








COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Array length





Java: String[] array  = ["apple", "orange"];
Int      length = array.size;





COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Array length







Python: arr = ['apple', 'orange']  

def setup():
    println(len(arr))



COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Array length








VB: Debug.Print "Array Length: " & UBound(Array("apple", "orange")) + 1


COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Array length




Go: package main

import "fmt"

func main() {
	arr := [...]string{"apple", "orange", "pear"}

	fmt.Printf("Length of %v is %v.\n", arr, len(arr))
}






COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Array length






PHP: print count(['apple', 'orange']); // Returns 2
Task: Array length






PHP: print count(['apple', 'orange']); // Returns 2






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

procedure Array_Length is
   Fruits : constant array (Positive range <>) of access constant String
      := (new String'("orange"),
          new String'("apple"));

begin
   for Fruit of Fruits loop
      Ada.Text_IO.Put (Integer'Image (Fruit'Length));
   end loop;

   Ada.Text_IO.Put_Line ("  Array Size : " & Integer'Image (Fruits'Length));
end Array_Length;
Task: Array length






PHP: print count(['apple', 'orange']); // Returns 2




COBOL:        identification division.
       program-id. array-length.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 table-one.
          05 str-field pic x(7) occurs 0 to 5 depending on t1.

       77 t1           pic 99.

       procedure division.
       array-length-main.
       perform initialize-table
       perform display-table-info
       goback.

       initialize-table.
           move 1 to t1
           move "apples" to str-field(t1)

           add 1 to t1
           move "oranges" to str-field(t1).

      
           add 1 to t1
           move "bananas" to str-field(t1).
           subtract 1 from t1
       .

       display-table-info.
           display "Elements: " t1 ", using " length(table-one) " bytes"
           display table-one
       .

       end program array-length.
Task: Bulls and cows

C: #include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdbool.h>
#include <curses.h>
#include <string.h>

#define MAX_NUM_TRIES 72
#define LINE_BEGIN 7
#define LAST_LINE 18

int yp=LINE_BEGIN, xp=0;

char number[5];
char guess[5];

#define MAX_STR 256
void mvaddstrf(int y, int x, const char *fmt, ...)
{
  va_list args;
  char buf[MAX_STR];
  
  va_start(args, fmt);
  vsprintf(buf, fmt, args);
  move(y, x);
  clrtoeol();
  addstr(buf);
  va_end(args);
}

void ask_for_a_number()
{
  int i=0;
  char symbols[] = "123456789";

  move(5,0); clrtoeol();
  addstr("Enter four digits: ");
  while(i<4) {
    int c = getch();
    if ( (c >= '1') && (c <= '9') && (symbols[c-'1']!=0) ) {
      addch(c);
      symbols[c-'1'] = 0;
      guess[i++] = c;
    }
  }
}

void choose_the_number()
{
  int i=0, j;
  char symbols[] = "123456789";

  while(i<4) {
    j = rand() % 9;
    if ( symbols[j] != 0 ) {
      number[i++] = symbols[j];
      symbols[j] = 0;
    }
  }
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;

procedure Bulls_And_Cows is
   package Random_Natural is new Ada.Numerics.Discrete_Random (Natural);
   Number : String (1..4);
begin
   declare 
      use Random_Natural;
      Digit    : String   := "123456789";
      Size     : Positive := 9;
      Dice     : Generator;
      Position : Natural;
   begin
      Reset (Dice);
      for I in Number'Range loop
         Position := Random (Dice) mod Size + 1;
         Number (I) := Digit (Position);
         Digit (Position..Size - 1) := Digit (Position + 1..Size);
         Size := Size - 1;
      end loop;
   end;
   loop 
      Put ("Enter four digits:");
      declare
         Guess : String  := Get_Line;
         Bulls : Natural := 0;
         Cows  : Natural := 0;
      begin
         if Guess'Length /= 4 then
            raise Data_Error;
         end if;
         for I in Guess'Range loop
            for J in Number'Range loop                  
               if Guess (I) not in '1'..'9' or else (I < J and then Guess (I) = Guess (J)) then
                  raise Data_Error;
               end if;
               if Number (I) = Guess (J) then
                  if I = J then
                     Bulls := Bulls + 1;
                  else
                     Cows := Cows + 1;
                  end if;
               end if;
            end loop;
         end loop;
         exit when Bulls = 4;
         Put_Line (Integer'Image (Bulls) & " bulls," & Integer'Image (Cows) & " cows");
      exception
         when Data_Error => Put_Line ("You should enter four different digits 1..9");
      end;
   end loop;
end Bulls_And_Cows;
Task: Bulls and cows





Java: import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

public class BullsAndCows{
	public static void main(String[] args){
		Random gen= new Random();
		int target;
		while(hasDupes(target= (gen.nextInt(9000) + 1000)));
		String targetStr = target +"";
		boolean guessed = false;
		Scanner input = new Scanner(System.in);
		int guesses = 0;
		do{
			int bulls = 0;
			int cows = 0;
			System.out.print("Guess a 4-digit number with no duplicate digits: ");
			int guess;
			try{
				guess = input.nextInt();
				if(hasDupes(guess) || guess < 1000) continue;
			}catch(InputMismatchException e){
				continue;
			}
			guesses++;
			String guessStr = guess + "";
			for(int i= 0;i < 4;i++){
				if(guessStr.charAt(i) == targetStr.charAt(i)){
					bulls++;
				}else if(targetStr.contains(guessStr.charAt(i)+"")){
					cows++;
				}
			}
			if(bulls == 4){
				guessed = true;
			}else{
				System.out.println(cows+" Cows and "+bulls+" Bulls.");
			}
		}while(!guessed);
		System.out.println("You won after "+guesses+" guesses!");
	}

	public static boolean hasDupes(int num){
		boolean[] digs = new boolean[10];
		while(num > 0){
			if(digs[num%10]) return true;
			digs[num%10] = true;
			num/= 10;
		}
		return false;
	}
}







Ada: with Ada.Text_IO;  use Ada.Text_IO;
with Ada.Numerics.Discrete_Random;

procedure Bulls_And_Cows is
   package Random_Natural is new Ada.Numerics.Discrete_Random (Natural);
   Number : String (1..4);
begin
   declare 
      use Random_Natural;
      Digit    : String   := "123456789";
      Size     : Positive := 9;
      Dice     : Generator;
      Position : Natural;
   begin
      Reset (Dice);
      for I in Number'Range loop
         Position := Random (Dice) mod Size + 1;
         Number (I) := Digit (Position);
         Digit (Position..Size - 1) := Digit (Position + 1..Size);
         Size := Size - 1;
      end loop;
   end;
   loop 
      Put ("Enter four digits:");
      declare
         Guess : String  := Get_Line;
         Bulls : Natural := 0;
         Cows  : Natural := 0;
      begin
         if Guess'Length /= 4 then
            raise Data_Error;
         end if;
         for I in Guess'Range loop
            for J in Number'Range loop                  
               if Guess (I) not in '1'..'9' or else (I < J and then Guess (I) = Guess (J)) then
                  raise Data_Error;
               end if;
               if Number (I) = Guess (J) then
                  if I = J then
                     Bulls := Bulls + 1;
                  else
                     Cows := Cows + 1;
                  end if;
               end if;
            end loop;
         end loop;
         exit when Bulls = 4;
         Put_Line (Integer'Image (Bulls) & " bulls," & Integer'Image (Cows) & " cows");
      exception
         when Data_Error => Put_Line ("You should enter four different digits 1..9");
      end;
   end loop;
end Bulls_And_Cows;