WeixiangYan/CodeTransOcean huggingface dataset:
Task: Product of divisors




Go: package main

import "fmt"

func prodDivisors(n int) int {
    prod := 1
    i := 1
    k := 2
    if n%2 == 0 {
        k = 1
    }
    for i*i <= n {
        if n%i == 0 {
            prod *= i
            j := n / i
            if j != i {
                prod *= j
            }
        }
        i += k
    }
    return prod
}

func main() {
    fmt.Println("The products of positive divisors for the first 50 positive integers are:")
    for i := 1; i <= 50; i++ {
        fmt.Printf("%9d  ", prodDivisors(i))
        if i%5 == 0 {
            fmt.Println()
        }
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  PRODUCT-OF-DIVISORS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 DIVISOR-PRODUCTS    PIC 9(9) OCCURS 50 TIMES.
          03 NUM                 PIC 999.
          03 MUL                 PIC 999.
      
       01 OUTPUT-FORMAT.
          03 NUM-OUT             PIC Z(9)9.
          03 LINE-PTR            PIC 99 VALUE 1.
          03 OUT-LINE            PIC X(50) VALUE SPACES.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM INIT VARYING NUM FROM 1 BY 1
               UNTIL NUM IS GREATER THAN 50.
           PERFORM CALCULATE-MULTIPLES VARYING MUL FROM 1 BY 1
               UNTIL MUL IS GREATER THAN 50.
           PERFORM OUTPUT-NUM VARYING NUM FROM 1 BY 1
               UNTIL NUM IS GREATER THAN 50.
           STOP RUN.

       INIT.
           MOVE 1 TO DIVISOR-PRODUCTS(NUM).
       
       CALCULATE-MULTIPLES.
           PERFORM MULTIPLY-NUM VARYING NUM FROM MUL BY MUL
               UNTIL NUM IS GREATER THAN 50.
 
       MULTIPLY-NUM.
           MULTIPLY MUL BY DIVISOR-PRODUCTS(NUM).

       OUTPUT-NUM.
           MOVE DIVISOR-PRODUCTS(NUM) TO NUM-OUT.
           STRING NUM-OUT DELIMITED BY SIZE INTO OUT-LINE
               WITH POINTER LINE-PTR.
           IF LINE-PTR IS EQUAL TO 51,
               DISPLAY OUT-LINE,
               MOVE SPACES TO OUT-LINE,
               MOVE 1 TO LINE-PTR.
Task: Find the last Sunday of each month




Go: package main

import (
	"fmt"
	"time"
)

func main() {
	
	var year int
	var t time.Time
	var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
	
	for {
		fmt.Print("Please select a year: ")
		_, err := fmt.Scanf("%d", &year)
		if err != nil {
			fmt.Println(err)
			continue
		} else {
			break
		}
	}

	fmt.Println("Last Sundays of each month of", year)
	fmt.Println("==================================")

	for i := 1;i < 13; i++ {
		j := lastDay[i-1]
		if i == 2 {
			if time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC).Month() == time.Date(int(year), time.Month(i), j-1, 0, 0, 0, 0, time.UTC).Month() {
				j = 29
			} else {
				j = 28
			}
		}
		for {
			t = time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC)
			if t.Weekday() == 0 {
				fmt.Printf("%s: %d\n", time.Month(i), j)
				break
			}
			j = j - 1
		}
	}
}






COBOL:        program-id. last-sun.
       data division.
       working-storage section.
       1 wk-date.
        2 yr pic 9999.
        2 mo pic 99 value 1.
        2 da pic 99 value 1.
       1 rd-date redefines wk-date pic 9(8).
       1 binary.
        2 int-date pic 9(8).
        2 dow pic 9(4).
        2 sunday pic 9(4) value 7.
       procedure division.
           display "Enter a calendar year (1601 thru 9999): "
               with no advancing
           accept yr
           if yr >= 1601 and <= 9999
               continue
           else
               display "Invalid year"
               stop run
           end-if
           perform 12 times
               move 1 to da
               add 1 to mo
               if mo > 12              
                   move 12 to mo
                   move 31 to da
               end-if
               compute int-date = function
                   integer-of-date (rd-date)
               if mo =12 and da = 31   
                   continue
               else
                   subtract 1 from int-date
               end-if
               compute rd-date = function
                   date-of-integer (int-date)
               compute dow = function mod
                   ((int-date - 1) 7) + 1
               compute dow = function mod ((dow - sunday) 7)
               subtract dow from da
               display yr "-" mo "-" da
               add 1 to mo
           end-perform
           stop run
           .
       end program last-sun.
Task: Odd and square numbers




Go: package main

import (
    "fmt"
    "math"
)

func main() {
    pow := 1
    for p := 0; p < 5; p++ {
        low := int(math.Ceil(math.Sqrt(float64(pow))))
        if low%2 == 0 {
            low++
        }
        pow *= 10
        high := int(math.Sqrt(float64(pow)))
        var oddSq []int
        for i := low; i <= high; i += 2 {
            oddSq = append(oddSq, i*i)
        }
        fmt.Println(len(oddSq), "odd squares from", pow/10, "to", pow, "\b:")
        for i := 0; i < len(oddSq); i++ {
            fmt.Printf("%d ", oddSq[i])
            if (i+1)%10 == 0 {
                fmt.Println()
            }
        }
        fmt.Println("\n")
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ODD-AND-SQUARE.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 N              PIC 999.
          03 SQR            PIC 9999 VALUE 0.
          03 FILLER         REDEFINES SQR.
             05 FILLER      PIC 999.
             05 FILLER      PIC 9.
                88 ODD      VALUE 1, 3, 5, 7, 9.
          03 FMT            PIC ZZ9.
          
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CHECK VARYING N FROM 10 BY 1
                UNTIL SQR IS NOT LESS THAN 1000.
           STOP RUN.
       
       CHECK.
           MULTIPLY N BY N GIVING SQR.
           IF ODD, MOVE SQR TO FMT, DISPLAY FMT.
Task: Sum of square and cube digits of an integer are primes




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    for i := 1; i < 100; i++ {
        if !rcu.IsPrime(rcu.DigitSum(i*i, 10)) {
            continue
        }
        if rcu.IsPrime(rcu.DigitSum(i*i*i, 10)) {
            fmt.Printf("%d ", i)
        }
    }
    fmt.Println()
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. SQUARE-CUBE-DIGITS-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 NUMBER-SEARCH-VARS.
          03 CAND             PIC 9(6).
          03 SQUARE           PIC 9(6).
          03 CUBE             PIC 9(6).
          
       01 SUM-DIGITS-VARS.
          03 SUM-NUM          PIC 9(6).
          03 DIGITS           PIC 9 OCCURS 6 TIMES INDEXED BY D
                              REDEFINES SUM-NUM.
          03 SUM              PIC 99.
       
       01 PRIME-TEST-VARS.
          03 DIVISOR          PIC 99.
          03 DIV-TEST         PIC 99V9999.
          03 FILLER           REDEFINES DIV-TEST.
             05 FILLER        PIC 99.
             05 FILLER        PIC 9999.
                88 DIVISIBLE  VALUE ZERO.
          03 PRIME-FLAG       PIC X.
             88 PRIME         VALUE '*'.
       
       01 OUT-FMT             PIC Z9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CHECK-NUMBER VARYING CAND FROM 1 BY 1
           UNTIL CAND IS EQUAL TO 100.
           STOP RUN.
       
       CHECK-NUMBER.
           MULTIPLY CAND BY CAND GIVING SQUARE.
           MULTIPLY CAND BY SQUARE GIVING CUBE.
           MOVE SQUARE TO SUM-NUM.
           PERFORM SUM-DIGITS.
           PERFORM PRIME-TEST.
           IF PRIME,
               MOVE CUBE TO SUM-NUM,
               PERFORM SUM-DIGITS,
               PERFORM PRIME-TEST,
               IF PRIME,
                   MOVE CAND TO OUT-FMT,
                   DISPLAY OUT-FMT.
           
       SUM-DIGITS.
           MOVE ZERO TO SUM.
           PERFORM SUM-DIGIT VARYING D FROM 1 BY 1
           UNTIL D IS GREATER THAN 6.
           
       SUM-DIGIT.
           ADD DIGITS(D) TO SUM.
       
       PRIME-TEST.
           MOVE '*' TO PRIME-FLAG.
           PERFORM CHECK-DIVISOR VARYING DIVISOR FROM 2 BY 1
           UNTIL NOT PRIME, OR DIVISOR IS EQUAL TO SUM.
       
       CHECK-DIVISOR.
           DIVIDE SUM BY DIVISOR GIVING DIV-TEST.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
Task: Harmonic series




Go: package main

import (
    "fmt"
    "math/big"
)

func harmonic(n int) *big.Rat {
    sum := new(big.Rat)
    for i := int64(1); i <= int64(n); i++ {
        r := big.NewRat(1, i)
        sum.Add(sum, r)
    }
    return sum
}

func main() {
    fmt.Println("The first 20 harmonic numbers and the 100th, expressed in rational form, are:")
    numbers := make([]int, 21)
    for i := 1; i <= 20; i++ {
        numbers[i-1] = i
    }
    numbers[20] = 100
    for _, i := range numbers {
        fmt.Printf("%3d : %s\n", i, harmonic(i))
    }

    fmt.Println("\nThe first harmonic number to exceed the following integers is:")
    const limit = 10
    for i, n, h := 1, 1, 0.0; i <= limit; n++ {
        h += 1.0 / float64(n)
        if h > float64(i) {
            fmt.Printf("integer = %2d  -> n = %6d  ->  harmonic number = %9.6f (to 6dp)\n", i, n, h)
            i++
        }
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. HARMONIC.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARS.
          03 N           PIC 9(5) VALUE ZERO.
          03 HN          PIC 9(2)V9(12) VALUE ZERO.
          03 INT         PIC 99 VALUE ZERO.
       01 OUT-VARS.
          03 POS         PIC Z(4)9.
          03 FILLER      PIC X(3) VALUE SPACES.
          03 H-OUT       PIC Z9.9(12).

       PROCEDURE DIVISION.
       BEGIN.
           DISPLAY "First 20 harmonic numbers:"
           PERFORM SHOW-HARMONIC 20 TIMES.
           DISPLAY SPACES.
           MOVE ZERO TO N, HN.
           DISPLAY "First harmonic number to exceed whole number:"
           PERFORM EXCEED-INT 10 TIMES.
           STOP RUN.

       SHOW-HARMONIC.
           PERFORM NEXT-HARMONIC.
           MOVE HN TO H-OUT.
           DISPLAY H-OUT.

       EXCEED-INT.
           ADD 1 TO INT.
           PERFORM NEXT-HARMONIC UNTIL HN IS GREATER THAN INT.
           MOVE N TO POS.
           MOVE HN TO H-OUT.
           DISPLAY OUT-VARS.

       NEXT-HARMONIC.
           ADD 1 TO N.
           COMPUTE HN = HN + 1 / N.
Task: Find squares n where n+1 is prime




Go: package main

import (
    "fmt"
    "math"
    "rcu"
)

func main() {
    var squares []int
    limit := int(math.Sqrt(1000))
    i := 1
    for i <= limit {
        n := i * i
        if rcu.IsPrime(n + 1) {
            squares = append(squares, n)
        }
        if i == 1 {
            i = 2
        } else {
            i += 2
        }
    }
    fmt.Println("There are", len(squares), "square numbers 'n' where 'n+1' is prime, viz:")
    fmt.Println(squares)
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. SQUARE-PLUS-1-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 N                   PIC 999.
       01 P                   PIC 9999 VALUE ZERO.
       01 PRIMETEST.
          03 DSOR             PIC 9999.
          03 PRIME-FLAG       PIC X.
             88 PRIME         VALUE '*'.
          03 DIVTEST          PIC 9999V999.
          03 FILLER           REDEFINES DIVTEST.
             05 FILLER        PIC 9999.
             05 FILLER        PIC 999.
                88 DIVISIBLE  VALUE ZERO.
           
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CHECK-N VARYING N FROM 1 BY 1 
                UNTIL P IS GREATER THAN 1000.
           STOP RUN.
       
       CHECK-N.
           MULTIPLY N BY N GIVING P.
           ADD 1 TO P.
           PERFORM CHECK-PRIME.
           SUBTRACT 1 FROM P.
           IF PRIME, DISPLAY P.
           
       CHECK-PRIME.
           IF P IS LESS THAN 2, MOVE SPACE TO PRIME-FLAG,
           ELSE, MOVE '*' TO PRIME-FLAG.
           PERFORM CHECK-DSOR VARYING DSOR FROM 2 BY 1
               UNTIL NOT PRIME OR DSOR IS GREATER THAN N.
       
       CHECK-DSOR.
           DIVIDE P BY DSOR GIVING DIVTEST.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
Task: Smallest square that begins with n




Go: package main

import (
    "fmt"
    "math"
)

func isSquare(n int) bool {
    s := int(math.Sqrt(float64(n)))
    return s*s == n
}

func main() {
    var squares []int
outer:
    for i := 1; i < 50; i++ {
        if isSquare(i) {
            squares = append(squares, i)
        } else {
            n := i
            limit := 10
            for {
                n *= 10
                for j := 0; j < limit; j++ {
                    s := n + j
                    if isSquare(s) {
                        squares = append(squares, s)
                        continue outer
                    }
                }
                limit *= 10
            }
        }
    }
    fmt.Println("Smallest squares that begin with 'n' in [1, 49]:")
    for i, s := range squares {
        fmt.Printf("%5d  ", s)
        if ((i + 1) % 10) == 0 {
            fmt.Println()
        }
    }
    if (len(squares) % 10) != 0 {
        fmt.Println()
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. SMALLEST-SQUARE-BEGINS-WITH-N.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 N            PIC 99.
       01 SQUARE-NO    PIC 999.
       01 SQUARE       PIC 9(5).
       01 OUT-FMT      PIC Z(4)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SMALLEST-SQUARE THRU SQUARE-START-TEST
               VARYING N FROM 1 BY 1 UNTIL N IS EQUAL TO 50.
           STOP RUN.

       SMALLEST-SQUARE.
           MOVE ZERO TO SQUARE-NO.
       SQUARE-LOOP.
           ADD 1 TO SQUARE-NO.
           MULTIPLY SQUARE-NO BY SQUARE-NO GIVING SQUARE.
       SQUARE-START-TEST.
           IF SQUARE IS GREATER THAN N
               DIVIDE 10 INTO SQUARE
               GO TO SQUARE-START-TEST.
           IF SQUARE IS NOT EQUAL TO N
               GO TO SQUARE-LOOP.
           MULTIPLY SQUARE-NO BY SQUARE-NO GIVING OUT-FMT.
           DISPLAY OUT-FMT.
Task: Minimum number of cells after, before, above and below NxN squares




Go: package main

import "fmt"

func printMinCells(n int) {
    fmt.Printf("Minimum number of cells after, before, above and below %d x %d square:\n", n, n)
    p := 1
    if n > 20 {
        p = 2
    }
    for r := 0; r < n; r++ {
        cells := make([]int, n)
        for c := 0; c < n; c++ {
            nums := []int{n - r - 1, r, c, n - c - 1}
            min := n
            for _, num := range nums {
                if num < min {
                    min = num
                }
            }
            cells[c] = min
        }
        fmt.Printf("%*d \n", p, cells)
    }
}

func main() {
    for _, n := range []int{23, 10, 9, 2, 1} {
        printMinCells(n)
        fmt.Println()
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. MINIMUM-CELLS-N-BY-N.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 TABLE-SIZE        PIC 99 VALUE 10.
       01 X                 PIC 99.
       01 Y                 PIC 99.
       01 ITEM              PIC 99.
       01 MIN               PIC 99.
       
       01 FMT               PIC ZZ9.
       01 TABLE-LINE        PIC X(72).
       01 LINE-PTR          PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM MAKE-LINE VARYING Y FROM 0 BY 1 
               UNTIL Y IS EQUAL TO TABLE-SIZE.
           STOP RUN.
       
       MAKE-LINE.
           MOVE SPACES TO TABLE-LINE.
           MOVE 1 TO LINE-PTR.
           PERFORM ADD-ITEM VARYING X FROM 0 BY 1
               UNTIL X IS EQUAL TO TABLE-SIZE.
           DISPLAY TABLE-LINE.
           
       ADD-ITEM.
           PERFORM FIND-MINIMUM-VALUE.
           MOVE MIN TO FMT.
           STRING FMT DELIMITED BY SIZE INTO TABLE-LINE 
               WITH POINTER LINE-PTR.
       
       FIND-MINIMUM-VALUE.
           MOVE X TO MIN.
           MOVE Y TO ITEM.
           PERFORM CHECK-MINIMUM.
           COMPUTE ITEM = TABLE-SIZE - Y - 1.
           PERFORM CHECK-MINIMUM.
           COMPUTE ITEM = TABLE-SIZE - X - 1.
           PERFORM CHECK-MINIMUM.
       
       CHECK-MINIMUM.
           IF ITEM IS LESS THAN MIN, MOVE ITEM TO MIN.
Task: Strange plus numbers




Go: package main

import "fmt"

func isPrime(n int) bool {
    return n == 2 || n == 3 || n == 5 || n == 7 || n == 11 || n == 13 || n == 17
}

func main() {
    count := 0
    var d []int
    fmt.Println("Strange plus numbers in the open interval (100, 500) are:\n")
    for i := 101; i < 500; i++ {
        d = d[:0]
        j := i
        for j > 0 {
            d = append(d, j%10)
            j /= 10
        }
        if isPrime(d[0]+d[1]) && isPrime(d[1]+d[2]) {
            fmt.Printf("%d ", i)
            count++
            if count%10 == 0 {
                fmt.Println()
            }
        }
    }
    if count%10 != 0 {
        fmt.Println()
    }
    fmt.Printf("\n%d strange plus numbers in all.\n", count)
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. STRANGE-PLUS-NUMBERS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE            PIC 999.
          03 DIGITS               REDEFINES CANDIDATE,
                                  PIC 9 OCCURS 3 TIMES.
          03 LEFT-PAIR            PIC 99.
             88 LEFT-PAIR-PRIME   VALUES 2, 3, 5, 7, 11, 13, 17.
          03 RIGHT-PAIR           PIC 99. 
             88 RIGHT-PAIR-PRIME  VALUES 2, 3, 5, 7, 11, 13, 17.
       01 OUT.
          03 ROW                  PIC X(40) VALUE SPACES.
          03 PTR                  PIC 99 VALUE 1.
       
       PROCEDURE DIVISION. 
       BEGIN. 
           PERFORM CHECK-STRANGE-NUMBER
           VARYING CANDIDATE FROM 100 BY 1
           UNTIL CANDIDATE IS GREATER THAN 500.
           DISPLAY ROW.
           STOP RUN.

       CHECK-STRANGE-NUMBER. 
           ADD DIGITS(1), DIGITS(2) GIVING LEFT-PAIR.
           ADD DIGITS(2), DIGITS(3) GIVING RIGHT-PAIR. 
           IF LEFT-PAIR-PRIME AND RIGHT-PAIR-PRIME,
               PERFORM WRITE-STRANGE-NUMBER.

       WRITE-STRANGE-NUMBER.
           STRING CANDIDATE DELIMITED BY SIZE INTO ROW
           WITH POINTER PTR.
           ADD 1 TO PTR.
           IF PTR IS GREATER THAN 40,
               DISPLAY ROW,
               MOVE SPACES TO ROW,
               MOVE 1 TO PTR.
Task: Minimum multiple of m where digital sum equals m




Go: package main

import "rcu"

func main() {
    var res []int
    for n := 1; n <= 70; n++ {
        m := 1
        for rcu.DigitSum(m*n, 10) != n {
            m++
        }
        res = append(res, m)
    }
    rcu.PrintTable(res, 7, 10, true)
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. A131382.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 MAXIMUM      PIC 99 VALUE 40.
          03 N            PIC 999.
          03 M            PIC 9(9).
          03 N-TIMES-M    PIC 9(9).
          03 DIGITS       PIC 9 OCCURS 9 TIMES,
                          REDEFINES N-TIMES-M,
                          INDEXED BY D.
          03 DIGITSUM     PIC 999 VALUE ZERO.
       01 OUTFMT.
          03 FILLER       PIC XX VALUE "A(".
          03 N-OUT        PIC Z9.
          03 FILLER       PIC X(4) VALUE ") = ".
          03 M-OUT        PIC Z(8)9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM CALC-A131382 VARYING N FROM 1 BY 1
           UNTIL N IS GREATER THAN MAXIMUM.
           STOP RUN.
       
       CALC-A131382.
           PERFORM FIND-LEAST-M VARYING M FROM 1 BY 1
           UNTIL DIGITSUM IS EQUAL TO N.
           SUBTRACT 1 FROM M.
           MOVE N TO N-OUT.
           MOVE M TO M-OUT.
           DISPLAY OUTFMT.
           
       FIND-LEAST-M.
           MOVE ZERO TO DIGITSUM.
           MULTIPLY N BY M GIVING N-TIMES-M.
           PERFORM ADD-DIGIT VARYING D FROM 1 BY 1
           UNTIL D IS GREATER THAN 9.
       
       ADD-DIGIT.
           ADD DIGITS(D) TO DIGITSUM.
Task: Selective file copy




Go: package main

import (
    "encoding/json"
    "log"
    "os"
    "bytes"
    "errors"
    "strings"
)


type s1 struct {
    A string
    B string
    C int
    D string
}


type s2 struct {
    A string
    C intString 
    X string
}

type intString string

func (i *intString) UnmarshalJSON(b []byte) error {
    if len(b) == 0 || bytes.IndexByte([]byte("0123456789-"), b[0]) < 0 {
        return errors.New("Unmarshal intString expected JSON number")
    }
    *i = intString(b)
    return nil
}


func NewS2() *s2 {
    return &s2{X: "XXXXX"}
}

func main() {
    
    o1, err := os.Create("o1.json")
    if err != nil {
        log.Fatal(err)
    }
    e := json.NewEncoder(o1)
    for i := 1; i <= 5; i++ {
        err := e.Encode(s1{
            strings.Repeat("A", i),
            strings.Repeat("B", i),
            i,
            strings.Repeat("D", i),
        })
        if err != nil {
            log.Fatal(err)
        }
    }
    o1.Close()

    
    in, err := os.Open("o1.json")
    if err != nil {
        log.Fatal(err)
    }
    out, err := os.Create("out.json")
    if err != nil {
        log.Fatal(err)
    }
    
    d := json.NewDecoder(in)
    e = json.NewEncoder(out)
    for d.More() {
        
        
        
        
        s := NewS2()
        if err = d.Decode(s); err != nil {
            log.Fatal(err)
        }
        if err = e.Encode(s); err != nil {
            log.Fatal(err)
        }
    }
}






COBOL:        01 ws-input-record.
       :INPUT-RECORD:
Task: Print debugging statement




Go: package main

import (
    "fmt"
    "runtime"
)

type point struct {
    x, y float64
}

func add(x, y int) int {
    result := x + y
    debug("x", x)
    debug("y", y)
    debug("result", result)
    debug("result+1", result+1)
    return result
}

func debug(s string, x interface{}) {
    _, _, lineNo, _ := runtime.Caller(1)
    fmt.Printf("%q at line %d type '%T'\nvalue: %#v\n\n", s, lineNo, x, x)
}

func main() {
    add(2, 7)
    b := true
    debug("b", b)
    s := "Hello"
    debug("s", s)
    p := point{2, 3}
    debug("p", p)
    q := &p
    debug("q", q)
}






COBOL: gcobol
      
      
      
      
       identification division.
       program-id. steptrace.

       data division.
       working-storage section.

       procedure division.
       steptrace-main.

       display "explicit line" upon syserr

    >>Ddisplay "debug line" upon syserr

       display "from " FUNCTION MODULE-ID " in " FUNCTION MODULE-SOURCE
       goback.
       end program steptrace.
Task: String comparison





Java: public class Compare
{
	
    
    public static void compare (String A, String B)
    {
        if (A.equals(B))
            System.debug(A + ' and  ' + B + ' are lexically equal.');
        else
            System.debug(A + ' and  ' + B + ' are not lexically equal.');

        if (A.equalsIgnoreCase(B))
            System.debug(A + ' and  ' + B + ' are case-insensitive lexically equal.');
        else
            System.debug(A + ' and  ' + B + ' are not case-insensitive lexically equal.');
 
        if (A.compareTo(B) < 0)
            System.debug(A + ' is lexically before ' + B);
        else if (A.compareTo(B) > 0)
            System.debug(A + ' is lexically after ' + B);
 
        if (A.compareTo(B) >= 0)
            System.debug(A + ' is not lexically before ' + B);
        if (A.compareTo(B) <= 0)
            System.debug(A + ' is not lexically after ' + B);
 
        System.debug('The lexical relationship is: ' + A.compareTo(B));
    }
}





COBOL: "hello" = "hello"   
"helloo" <> "hello" 
"aello" < "hello"