WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sum to 100




Go: package main

import (
	"fmt"
	"sort"
)

const pow3_8 = 3 * 3 * 3 * 3 * 3 * 3 * 3 * 3 
const pow3_9 = 3 * pow3_8                    
const maxExprs = 2 * pow3_8                  

type op uint8

const (
	Add  op = iota 
	Sub            
	Join           
)




type code uint16


func (c code) evaluate() (sum int) {
	num, pow := 0, 1
	for k := 9; k >= 1; k-- {
		num += pow * k
		switch op(c % 3) {
		case Add:
			sum += num
			num, pow = 0, 1
		case Sub:
			sum -= num
			num, pow = 0, 1
		case Join:
			pow *= 10
		}
		c /= 3
	}
	return sum
}

func (c code) String() string {
	buf := make([]byte, 0, 18)
	a, b := code(pow3_9), code(pow3_8)
	for k := 1; k <= 9; k++ {
		switch op((c % a) / b) {
		case Add:
			if k > 1 {
				buf = append(buf, '+')
			}
		case Sub:
			buf = append(buf, '-')
		}
		buf = append(buf, '0'+byte(k))
		a, b = b, b/3
	}
	return string(buf)
}

type sumCode struct {
	sum  int
	code code
}
type sumCodes []sumCode

type sumCount struct {
	sum   int
	count int
}
type sumCounts []sumCount


func (p sumCodes) Len() int            { return len(p) }
func (p sumCodes) Swap(i, j int)       { p[i], p[j] = p[j], p[i] }
func (p sumCodes) Less(i, j int) bool  { return p[i].sum < p[j].sum }
func (p sumCounts) Len() int           { return len(p) }
func (p sumCounts) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
func (p sumCounts) Less(i, j int) bool { return p[i].count > p[j].count }


func (sc sumCode) String() string {
	return fmt.Sprintf("% 10d = %v", sc.sum, sc.code)
}
func (sc sumCount) String() string {
	return fmt.Sprintf("% 10d has %d solutions", sc.sum, sc.count)
}

func main() {
	
	expressions := make(sumCodes, 0, maxExprs/2)
	counts := make(sumCounts, 0, 1715)
	for c := code(0); c < maxExprs; c++ {
		
		
		
		sum := c.evaluate()
		if sum >= 0 {
			expressions = append(expressions, sumCode{sum, c})
		}
	}
	sort.Sort(expressions)

	
	sc := sumCount{expressions[0].sum, 1}
	for _, e := range expressions[1:] {
		if e.sum == sc.sum {
			sc.count++
		} else {
			counts = append(counts, sc)
			sc = sumCount{e.sum, 1}
		}
	}
	counts = append(counts, sc)
	sort.Sort(counts)

	

	fmt.Println("All solutions that sum to 100:")
	i := sort.Search(len(expressions), func(i int) bool {
		return expressions[i].sum >= 100
	})
	for _, e := range expressions[i:] {
		if e.sum != 100 {
			break
		}
		fmt.Println(e)
	}

	fmt.Println("\nThe positive sum with maximum number of solutions:")
	fmt.Println(counts[0])

	fmt.Println("\nThe lowest positive number that can't be expressed:")
	s := 1
	for _, e := range expressions {
		if e.sum == s {
			s++
		} else if e.sum > s {
			fmt.Printf("% 10d\n", s)
			break
		}
	}

	fmt.Println("\nThe ten highest numbers that can be expressed:")
	for _, e := range expressions[len(expressions)-10:] {
		fmt.Println(e)
	}
}
Task: Array concatenation



C#: using System;

namespace RosettaCode
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = { 1, 2, 3 };
            int[] b = { 4, 5, 6 };

            int[] c = new int[a.Length + b.Length];
            a.CopyTo(c, 0);
            b.CopyTo(c, a.Length);

            foreach(int n in c)
            {
                Console.WriteLine(n.ToString());
            }
        }
    }
}









Ada: type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6);
Task: Array concatenation

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

#define ARRAY_CONCAT(TYPE, A, An, B, Bn) \
  (TYPE *)array_concat((const void *)(A), (An), (const void *)(B), (Bn), sizeof(TYPE));

void *array_concat(const void *a, size_t an,
                   const void *b, size_t bn, size_t s)
{
  char *p = malloc(s * (an + bn));
  memcpy(p, a, an*s);
  memcpy(p + an*s, b, bn*s);
  return p;
}


const int a[] = { 1, 2, 3, 4, 5 };
const int b[] = { 6, 7, 8, 9, 0 };

int main(void)
{
  unsigned int i;

  int *c = ARRAY_CONCAT(int, a, 5, b, 5);

  for(i = 0; i < 10; i++)
    printf("%d\n", c[i]);

  free(c);
  return EXIT_SUCCCESS;
}











Ada: type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6);
Task: Array concatenation


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

int main()
{
  std::vector<int> a(3), b(4);
  a[0] = 11; a[1] = 12; a[2] = 13;
  b[0] = 21; b[1] = 22; b[2] = 23; b[3] = 24;

  a.insert(a.end(), b.begin(), b.end());

  for (int i = 0; i < a.size(); ++i)
    std::cout << "a[" << i << "] = " << a[i] << "\n";
}










Ada: type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6);
Task: Array concatenation




Go: package main

import "fmt"

func main() {
    
    
    a := []int{1, 2, 3}
    b := []int{7, 12, 60} 
    c := append(a, b...)
    fmt.Println(c)

    
    
    
    i := []interface{}{1, 2, 3}
    j := []interface{}{"Crosby", "Stills", "Nash", "Young"}
    k := append(i, j...) 
    fmt.Println(k)

    
    
    
    
    
    
    
    l := [...]int{1, 2, 3}
    m := [...]int{7, 12, 60} 
    var n [len(l) + len(m)]int
    copy(n[:], l[:]) 
    copy(n[len(l):], m[:])
    fmt.Println(n)

}








Ada: type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6);
Task: Array concatenation





Java: String[] fruits = ["apples", "oranges"];
String[] grains = ["wheat", "corn"];
String[] all    = fruits + grains;







Ada: type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6);
Task: Array concatenation







Python: arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr4 = arr1 + arr2
assert arr4 == [1, 2, 3, 4, 5, 6]
arr4.extend(arr3)
assert arr4 == [1, 2, 3, 4, 5, 6, 7, 8, 9]





Ada: type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6);
Task: Array concatenation








VB: DEFINT A(1 to 4) = {1, 2, 3, 4}
DEFINT B(1 to 4) = {10, 20, 30, 40}


Redim A(1 to 8) as integer
MEMCPY(varptr(A(5)), varptr(B(1)), Sizeof(integer)*4)




Ada: type T is array (Positive range <>) of Integer;
X : T := (1, 2, 3);
Y : T := X & (4, 5, 6);
Task: Array concatenation

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

#define ARRAY_CONCAT(TYPE, A, An, B, Bn) \
  (TYPE *)array_concat((const void *)(A), (An), (const void *)(B), (Bn), sizeof(TYPE));

void *array_concat(const void *a, size_t an,
                   const void *b, size_t bn, size_t s)
{
  char *p = malloc(s * (an + bn));
  memcpy(p, a, an*s);
  memcpy(p + an*s, b, bn*s);
  return p;
}


const int a[] = { 1, 2, 3, 4, 5 };
const int b[] = { 6, 7, 8, 9, 0 };

int main(void)
{
  unsigned int i;

  int *c = ARRAY_CONCAT(int, a, 5, b, 5);

  for(i = 0; i < 10; i++)
    printf("%d\n", c[i]);

  free(c);
  return EXIT_SUCCCESS;
}
Task: Array concatenation



C#: using System;

namespace RosettaCode
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = { 1, 2, 3 };
            int[] b = { 4, 5, 6 };

            int[] c = new int[a.Length + b.Length];
            a.CopyTo(c, 0);
            b.CopyTo(c, a.Length);

            foreach(int n in c)
            {
                Console.WriteLine(n.ToString());
            }
        }
    }
}
Task: Array concatenation


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

int main()
{
  std::vector<int> a(3), b(4);
  a[0] = 11; a[1] = 12; a[2] = 13;
  b[0] = 21; b[1] = 22; b[2] = 23; b[3] = 24;

  a.insert(a.end(), b.begin(), b.end());

  for (int i = 0; i < a.size(); ++i)
    std::cout << "a[" << i << "] = " << a[i] << "\n";
}
Task: Array concatenation





Java: String[] fruits = ["apples", "oranges"];
String[] grains = ["wheat", "corn"];
String[] all    = fruits + grains;
Task: Array concatenation







Python: arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr4 = arr1 + arr2
assert arr4 == [1, 2, 3, 4, 5, 6]
arr4.extend(arr3)
assert arr4 == [1, 2, 3, 4, 5, 6, 7, 8, 9]
Task: Array concatenation








VB: DEFINT A(1 to 4) = {1, 2, 3, 4}
DEFINT B(1 to 4) = {10, 20, 30, 40}


Redim A(1 to 8) as integer
MEMCPY(varptr(A(5)), varptr(B(1)), Sizeof(integer)*4)
Task: Array concatenation




Go: package main

import "fmt"

func main() {
    
    
    a := []int{1, 2, 3}
    b := []int{7, 12, 60} 
    c := append(a, b...)
    fmt.Println(c)

    
    
    
    i := []interface{}{1, 2, 3}
    j := []interface{}{"Crosby", "Stills", "Nash", "Young"}
    k := append(i, j...) 
    fmt.Println(k)

    
    
    
    
    
    
    
    l := [...]int{1, 2, 3}
    m := [...]int{7, 12, 60} 
    var n [len(l) + len(m)]int
    copy(n[:], l[:]) 
    copy(n[len(l):], m[:])
    fmt.Println(n)

}
Task: Array concatenation



C#: using System;

namespace RosettaCode
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = { 1, 2, 3 };
            int[] b = { 4, 5, 6 };

            int[] c = new int[a.Length + b.Length];
            a.CopyTo(c, 0);
            b.CopyTo(c, a.Length);

            foreach(int n in c)
            {
                Console.WriteLine(n.ToString());
            }
        }
    }
}








Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation


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

int main()
{
  std::vector<int> a(3), b(4);
  a[0] = 11; a[1] = 12; a[2] = 13;
  b[0] = 21; b[1] = 22; b[2] = 23; b[3] = 24;

  a.insert(a.end(), b.begin(), b.end());

  for (int i = 0; i < a.size(); ++i)
    std::cout << "a[" << i << "] = " << a[i] << "\n";
}









Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation

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

#define ARRAY_CONCAT(TYPE, A, An, B, Bn) \
  (TYPE *)array_concat((const void *)(A), (An), (const void *)(B), (Bn), sizeof(TYPE));

void *array_concat(const void *a, size_t an,
                   const void *b, size_t bn, size_t s)
{
  char *p = malloc(s * (an + bn));
  memcpy(p, a, an*s);
  memcpy(p + an*s, b, bn*s);
  return p;
}


const int a[] = { 1, 2, 3, 4, 5 };
const int b[] = { 6, 7, 8, 9, 0 };

int main(void)
{
  unsigned int i;

  int *c = ARRAY_CONCAT(int, a, 5, b, 5);

  for(i = 0; i < 10; i++)
    printf("%d\n", c[i]);

  free(c);
  return EXIT_SUCCCESS;
}










Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation




Go: package main

import "fmt"

func main() {
    
    
    a := []int{1, 2, 3}
    b := []int{7, 12, 60} 
    c := append(a, b...)
    fmt.Println(c)

    
    
    
    i := []interface{}{1, 2, 3}
    j := []interface{}{"Crosby", "Stills", "Nash", "Young"}
    k := append(i, j...) 
    fmt.Println(k)

    
    
    
    
    
    
    
    l := [...]int{1, 2, 3}
    m := [...]int{7, 12, 60} 
    var n [len(l) + len(m)]int
    copy(n[:], l[:]) 
    copy(n[len(l):], m[:])
    fmt.Println(n)

}







Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation





Java: String[] fruits = ["apples", "oranges"];
String[] grains = ["wheat", "corn"];
String[] all    = fruits + grains;






Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation







Python: arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr4 = arr1 + arr2
assert arr4 == [1, 2, 3, 4, 5, 6]
arr4.extend(arr3)
assert arr4 == [1, 2, 3, 4, 5, 6, 7, 8, 9]




Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation








VB: DEFINT A(1 to 4) = {1, 2, 3, 4}
DEFINT B(1 to 4) = {10, 20, 30, 40}


Redim A(1 to 8) as integer
MEMCPY(varptr(A(5)), varptr(B(1)), Sizeof(integer)*4)



Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation






PHP: $arr1 = array(1, 2, 3);
$arr2 = array(4, 5, 6);
$arr3 = array_merge($arr1, $arr2);





Fortran: program Concat_Arrays
  implicit none

  
  integer, dimension(3) :: a = [1, 2, 3] 
  integer, dimension(3) :: b = [4, 5, 6] 
  integer, dimension(:), allocatable :: c, d
  
  allocate(c(size(a)+size(b)))
  c(1 : size(a)) = a
  c(size(a)+1 : size(a)+size(b)) = b
  print*, c

  
  d = [a, b] 
  print*, d
end program Concat_Arrays
Task: Array concatenation

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

#define ARRAY_CONCAT(TYPE, A, An, B, Bn) \
  (TYPE *)array_concat((const void *)(A), (An), (const void *)(B), (Bn), sizeof(TYPE));

void *array_concat(const void *a, size_t an,
                   const void *b, size_t bn, size_t s)
{
  char *p = malloc(s * (an + bn));
  memcpy(p, a, an*s);
  memcpy(p + an*s, b, bn*s);
  return p;
}


const int a[] = { 1, 2, 3, 4, 5 };
const int b[] = { 6, 7, 8, 9, 0 };

int main(void)
{
  unsigned int i;

  int *c = ARRAY_CONCAT(int, a, 5, b, 5);

  for(i = 0; i < 10; i++)
    printf("%d\n", c[i]);

  free(c);
  return EXIT_SUCCCESS;
}









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

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

       data division.
       working-storage section.
       01 table-one.
          05 int-field pic 999 occurs 0 to 5 depending on t1.
       01 table-two.
          05 int-field pic 9(4) occurs 0 to 10 depending on t2.

       77 t1           pic 99.
       77 t2           pic 99.

       77 show         pic z(4).

       procedure division.
       array-concat-main.
       perform initialize-tables
       perform concatenate-tables
       perform display-result
       goback.

       initialize-tables.
           move 4 to t1
           perform varying tally from 1 by 1 until tally > t1
               compute int-field of table-one(tally) = tally * 3
           end-perform

           move 3 to t2
           perform varying tally from 1 by 1 until tally > t2
               compute int-field of table-two(tally) = tally * 6
           end-perform
       .

       concatenate-tables.
           perform varying tally from 1 by 1 until tally > t1
               add 1 to t2
               move int-field of table-one(tally)
                 to int-field of table-two(t2)
           end-perform
       .

       display-result.
           perform varying tally from 1 by 1 until tally = t2
               move int-field of table-two(tally) to show
               display trim(show) ", " with no advancing
           end-perform
           move int-field of table-two(tally) to show
           display trim(show)
       .

       end program array-concat.
Task: Array concatenation



C#: using System;

namespace RosettaCode
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] a = { 1, 2, 3 };
            int[] b = { 4, 5, 6 };

            int[] c = new int[a.Length + b.Length];
            a.CopyTo(c, 0);
            b.CopyTo(c, a.Length);

            foreach(int n in c)
            {
                Console.WriteLine(n.ToString());
            }
        }
    }
}







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

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

       data division.
       working-storage section.
       01 table-one.
          05 int-field pic 999 occurs 0 to 5 depending on t1.
       01 table-two.
          05 int-field pic 9(4) occurs 0 to 10 depending on t2.

       77 t1           pic 99.
       77 t2           pic 99.

       77 show         pic z(4).

       procedure division.
       array-concat-main.
       perform initialize-tables
       perform concatenate-tables
       perform display-result
       goback.

       initialize-tables.
           move 4 to t1
           perform varying tally from 1 by 1 until tally > t1
               compute int-field of table-one(tally) = tally * 3
           end-perform

           move 3 to t2
           perform varying tally from 1 by 1 until tally > t2
               compute int-field of table-two(tally) = tally * 6
           end-perform
       .

       concatenate-tables.
           perform varying tally from 1 by 1 until tally > t1
               add 1 to t2
               move int-field of table-one(tally)
                 to int-field of table-two(t2)
           end-perform
       .

       display-result.
           perform varying tally from 1 by 1 until tally = t2
               move int-field of table-two(tally) to show
               display trim(show) ", " with no advancing
           end-perform
           move int-field of table-two(tally) to show
           display trim(show)
       .

       end program array-concat.
Task: Array concatenation


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

int main()
{
  std::vector<int> a(3), b(4);
  a[0] = 11; a[1] = 12; a[2] = 13;
  b[0] = 21; b[1] = 22; b[2] = 23; b[3] = 24;

  a.insert(a.end(), b.begin(), b.end());

  for (int i = 0; i < a.size(); ++i)
    std::cout << "a[" << i << "] = " << a[i] << "\n";
}








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

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

       data division.
       working-storage section.
       01 table-one.
          05 int-field pic 999 occurs 0 to 5 depending on t1.
       01 table-two.
          05 int-field pic 9(4) occurs 0 to 10 depending on t2.

       77 t1           pic 99.
       77 t2           pic 99.

       77 show         pic z(4).

       procedure division.
       array-concat-main.
       perform initialize-tables
       perform concatenate-tables
       perform display-result
       goback.

       initialize-tables.
           move 4 to t1
           perform varying tally from 1 by 1 until tally > t1
               compute int-field of table-one(tally) = tally * 3
           end-perform

           move 3 to t2
           perform varying tally from 1 by 1 until tally > t2
               compute int-field of table-two(tally) = tally * 6
           end-perform
       .

       concatenate-tables.
           perform varying tally from 1 by 1 until tally > t1
               add 1 to t2
               move int-field of table-one(tally)
                 to int-field of table-two(t2)
           end-perform
       .

       display-result.
           perform varying tally from 1 by 1 until tally = t2
               move int-field of table-two(tally) to show
               display trim(show) ", " with no advancing
           end-perform
           move int-field of table-two(tally) to show
           display trim(show)
       .

       end program array-concat.
Task: Array concatenation





Java: String[] fruits = ["apples", "oranges"];
String[] grains = ["wheat", "corn"];
String[] all    = fruits + grains;





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

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

       data division.
       working-storage section.
       01 table-one.
          05 int-field pic 999 occurs 0 to 5 depending on t1.
       01 table-two.
          05 int-field pic 9(4) occurs 0 to 10 depending on t2.

       77 t1           pic 99.
       77 t2           pic 99.

       77 show         pic z(4).

       procedure division.
       array-concat-main.
       perform initialize-tables
       perform concatenate-tables
       perform display-result
       goback.

       initialize-tables.
           move 4 to t1
           perform varying tally from 1 by 1 until tally > t1
               compute int-field of table-one(tally) = tally * 3
           end-perform

           move 3 to t2
           perform varying tally from 1 by 1 until tally > t2
               compute int-field of table-two(tally) = tally * 6
           end-perform
       .

       concatenate-tables.
           perform varying tally from 1 by 1 until tally > t1
               add 1 to t2
               move int-field of table-one(tally)
                 to int-field of table-two(t2)
           end-perform
       .

       display-result.
           perform varying tally from 1 by 1 until tally = t2
               move int-field of table-two(tally) to show
               display trim(show) ", " with no advancing
           end-perform
           move int-field of table-two(tally) to show
           display trim(show)
       .

       end program array-concat.
Task: Array concatenation







Python: arr1 = [1, 2, 3]
arr2 = [4, 5, 6]
arr3 = [7, 8, 9]
arr4 = arr1 + arr2
assert arr4 == [1, 2, 3, 4, 5, 6]
arr4.extend(arr3)
assert arr4 == [1, 2, 3, 4, 5, 6, 7, 8, 9]



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

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

       data division.
       working-storage section.
       01 table-one.
          05 int-field pic 999 occurs 0 to 5 depending on t1.
       01 table-two.
          05 int-field pic 9(4) occurs 0 to 10 depending on t2.

       77 t1           pic 99.
       77 t2           pic 99.

       77 show         pic z(4).

       procedure division.
       array-concat-main.
       perform initialize-tables
       perform concatenate-tables
       perform display-result
       goback.

       initialize-tables.
           move 4 to t1
           perform varying tally from 1 by 1 until tally > t1
               compute int-field of table-one(tally) = tally * 3
           end-perform

           move 3 to t2
           perform varying tally from 1 by 1 until tally > t2
               compute int-field of table-two(tally) = tally * 6
           end-perform
       .

       concatenate-tables.
           perform varying tally from 1 by 1 until tally > t1
               add 1 to t2
               move int-field of table-one(tally)
                 to int-field of table-two(t2)
           end-perform
       .

       display-result.
           perform varying tally from 1 by 1 until tally = t2
               move int-field of table-two(tally) to show
               display trim(show) ", " with no advancing
           end-perform
           move int-field of table-two(tally) to show
           display trim(show)
       .

       end program array-concat.