WeixiangYan/CodeTransOcean huggingface dataset:
Task: Cycle detection



C#: 


using System;

namespace DetectCycles
{
  
  
  
  public class Cycles<T> where T : IEquatable<T>
  {
    
    
    
    
    
    
    
    
    
    
    
    
    
    public static Tuple<int,int> FindCycle(T x0, Func<T,T> yielder)
    {
      int power, lambda;
      T tortoise, hare;
      power = lambda = 1;
      tortoise = x0;
      hare = yielder(x0);

      
      while (!tortoise.Equals (hare)) {
        if (power == lambda) {
          tortoise = hare;
          power *= 2;
          lambda = 0;  
        }
        hare = yielder (hare);
        lambda += 1;
      }

      
      var mu = 0;
      tortoise = hare = x0;
      for (var times = 0; times < lambda; times++) 
        hare = yielder (hare);
      
      while (!tortoise.Equals (hare)) 
      {
        tortoise = yielder (tortoise);
        hare = yielder (hare);
        mu += 1;
      }

      return new Tuple<int,int> (lambda, mu);
    }
  }
}



using System;

namespace DetectCycles
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			
			Func<int,int> sequence = (int _x) => (_x * _x + 1) % 255;

			
			var x = 3;
			Console.Write(x);
			for (var times = 0; times < 40; times++) 
			{
				x = sequence(x);
				Console.Write(String.Format(",{0}", x));
			}
			Console.WriteLine();

			
			var cycle = Cycles<int>.FindCycle(3, sequence);
			var clength = cycle.Item1;
			var cstart = cycle.Item2;
			Console.Write(String.Format("Cycle length = {0}\nStart index = {1}\n", clength, cstart));
		}
	}
}
Task: Boolean values



C#: bool? value = null
Task: Rendezvous







Python: 
from __future__ import annotations

import asyncio
import sys

from typing import Optional
from typing import TextIO


class OutOfInkError(Exception):
    


class Printer:
    def __init__(self, name: str, backup: Optional[Printer]):
        self.name = name
        self.backup = backup

        self.ink_level: int = 5
        self.output_stream: TextIO = sys.stdout

    async def print(self, msg):
        if self.ink_level <= 0:
            if self.backup:
                await self.backup.print(msg)
            else:
                raise OutOfInkError(self.name)
        else:
            self.ink_level -= 1
            self.output_stream.write(f"({self.name}): {msg}\n")


async def main():
    reserve = Printer("reserve", None)
    main = Printer("main", reserve)

    humpty_lines = [
        "Humpty Dumpty sat on a wall.",
        "Humpty Dumpty had a great fall.",
        "All the king's horses and all the king's men,",
        "Couldn't put Humpty together again.",
    ]

    goose_lines = [
        "Old Mother Goose,",
        "When she wanted to wander,",
        "Would ride through the air,",
        "On a very fine gander.",
        "Jack's mother came in,",
        "And caught the goose soon,",
        "And mounting its back,",
        "Flew up to the moon.",
    ]

    async def print_humpty():
        for line in humpty_lines:
            try:
                task = asyncio.Task(main.print(line))
                await task
            except OutOfInkError:
                print("\t Humpty Dumpty out of ink!")
                break

    async def print_goose():
        for line in goose_lines:
            try:
                task = asyncio.Task(main.print(line))
                await task
            except OutOfInkError:
                print("\t Mother Goose out of ink!")
                break

    await asyncio.gather(print_goose(), print_humpty())


if __name__ == "__main__":
    asyncio.run(main(), debug=True)
Task: ABC words




Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
)

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    count := 0
    fmt.Println("Based on first occurrences only, the ABC words in", wordList, "are:")
    for _, bword := range bwords {
        a := bytes.IndexRune(bword, 'a')
        b := bytes.IndexRune(bword, 'b')
        c := bytes.IndexRune(bword, 'c')
        if a >= 0 && b > a && c > b {
            count++
            fmt.Printf("%2d: %s\n", count, string(bword))
        }
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 WORD            PIC X(32).
       
       WORKING-STORAGE SECTION.
       01 A               PIC 99.
       01 B               PIC 99.
       01 C               PIC 99.
       01 X               PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       READ-WORD.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORD.
           
       CHECK-WORD.
           MOVE ZERO TO A, B, C, X.
           INSPECT WORD TALLYING A FOR CHARACTERS BEFORE INITIAL 'a'.
           INSPECT WORD TALLYING B FOR CHARACTERS BEFORE INITIAL 'b'.
           INSPECT WORD TALLYING C FOR CHARACTERS BEFORE INITIAL 'c'.
           INSPECT WORD TALLYING X FOR CHARACTERS BEFORE INITIAL ' '.
           IF A IS LESS THAN B 
           AND B IS LESS THAN C 
           AND C IS LESS THAN X,
               DISPLAY WORD.
Task: Two identical strings




Go: package main

import (
    "fmt"
    "strconv"
)

func main() {
    i := int64(1)
    for {
        b2 := strconv.FormatInt(i, 2)
        b2 += b2
        d, _ := strconv.ParseInt(b2, 2, 64)
        if d >= 1000 {
            break
        }
        fmt.Printf("%3d : %s\n", d, b2)
        i++
    }
    fmt.Println("\nFound", i-1, "numbers.")
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  IDENTICAL-STRINGS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 INPUT-NUMBER            PIC 9(4).
          03 BINARY-REPRESENTATION   PIC 9(10).
          03 BIT                     REDEFINES BINARY-REPRESENTATION,
                                     PIC 9 OCCURS 10 TIMES.
          03 FIRST-SET-BIT           PIC 99.
          03 CURRENT-BIT             PIC 99.
          03 SECOND-BIT              PIC 99.
          03 BIT-VALUE               PIC 9(4).
          03 OUTPUT-NUMBER           PIC 9(4) VALUE ZERO.
          03 REMAINING-BITS          PIC 9(4)V9.
          03 FILLER                  REDEFINES REMAINING-BITS.
             05 REST                 PIC 9(4).
             05 FILLER               PIC 9.
                88 BIT-IS-SET        VALUE 5.

       01 OUTPUT-FORMAT.
          03 DECIMAL-OUTPUT          PIC Z(3)9.
          03 BINARY-OUTPUT           PIC Z(9)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM IDENTICAL-STRING
               VARYING INPUT-NUMBER FROM 1 BY 1
               UNTIL OUTPUT-NUMBER IS GREATER THAN 1000.
           STOP RUN.

       IDENTICAL-STRING.
           MOVE ZERO TO BINARY-REPRESENTATION.
           MOVE 10 TO CURRENT-BIT.
           MOVE INPUT-NUMBER TO REMAINING-BITS.
           PERFORM EXTRACT-BIT UNTIL REMAINING-BITS EQUAL ZERO.
           MOVE CURRENT-BIT TO FIRST-SET-BIT.
           MOVE 10 TO SECOND-BIT.
           PERFORM COPY-BIT UNTIL SECOND-BIT IS EQUAL TO FIRST-SET-BIT.
           MOVE ZERO TO OUTPUT-NUMBER.
           IF CURRENT-BIT IS EQUAL TO ZERO, MOVE 1 TO CURRENT-BIT.
           PERFORM INSERT-BIT
               VARYING CURRENT-BIT FROM CURRENT-BIT BY 1
               UNTIL CURRENT-BIT IS GREATER THAN 10.
           MOVE OUTPUT-NUMBER TO DECIMAL-OUTPUT.
           MOVE BINARY-REPRESENTATION TO BINARY-OUTPUT.
           IF OUTPUT-NUMBER IS LESS THAN 1000,
               DISPLAY DECIMAL-OUTPUT ": " BINARY-OUTPUT.

       EXTRACT-BIT.
           DIVIDE 2 INTO REMAINING-BITS.
           IF BIT-IS-SET, MOVE 1 TO BIT(CURRENT-BIT).
           SUBTRACT 1 FROM CURRENT-BIT.
           MOVE REST TO REMAINING-BITS.

       COPY-BIT.
           MOVE BIT(SECOND-BIT) TO BIT(CURRENT-BIT).
           SUBTRACT 1 FROM SECOND-BIT.
           SUBTRACT 1 FROM CURRENT-BIT.

       INSERT-BIT.
           COMPUTE BIT-VALUE = 2 ** (10 - CURRENT-BIT)
           MULTIPLY BIT(CURRENT-BIT) BY BIT-VALUE.
           ADD BIT-VALUE TO OUTPUT-NUMBER.
Task: Sum of first n cubes




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    fmt.Println("Cumulative sums of the first 50 cubes:")
    sum := 0
    for n := 0; n < 50; n++ {
        sum += n * n * n
        fmt.Printf("%9s ", rcu.Commatize(sum))
        if n%10 == 9 {
            fmt.Println()
        }
    }
    fmt.Println()






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  SUM-OF-CUBES.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 STEP         PIC 99.
          03 CUBE         PIC 9(7).
          03 CUBE-SUM     PIC 9(7) VALUE 0.
 
       01 OUTPUT-FORMAT.
          03 OUT-LINE     PIC X(40) VALUE SPACES.
          03 OUT-PTR      PIC 99 VALUE 1.
          03 OUT-NUM      PIC Z(7)9.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM ADD-CUBE VARYING STEP FROM 0 BY 1
               UNTIL STEP IS EQUAL TO 50.
           STOP RUN.

       ADD-CUBE.
           COMPUTE CUBE = STEP ** 3.
           ADD CUBE TO CUBE-SUM.
           MOVE CUBE-SUM TO OUT-NUM.
           STRING OUT-NUM DELIMITED BY SIZE INTO OUT-LINE
               WITH POINTER OUT-PTR.
           IF OUT-PTR IS EQUAL TO 41,
               DISPLAY OUT-LINE,
               MOVE 1 TO OUT-PTR.
Task: Count how many vowels and consonants occur in a string




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    const (
        vowels     = "aeiou"
        consonants = "bcdfghjklmnpqrstvwxyz"
    )
    strs := []string{
        "Forever Go programming language",
        "Now is the time for all good men to come to the aid of their country.",
    }
    for _, str := range strs {
        fmt.Println(str)
        str = strings.ToLower(str)
        vc, cc := 0, 0
        vmap := make(map[rune]bool)
        cmap := make(map[rune]bool)
        for _, c := range str {
            if strings.ContainsRune(vowels, c) {
                vc++
                vmap[c] = true
            } else if strings.ContainsRune(consonants, c) {
                cc++
                cmap[c] = true
            }
        }
        fmt.Printf("contains (total) %d vowels and %d consonants.\n", vc, cc)
        fmt.Printf("contains (distinct %d vowels and %d consonants.\n\n", len(vmap), len(cmap))
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. VOWELS-AND-CONSONANTS.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONSTANTS.
          03 LETTERS-DAT.
             05 FILLER      PIC X(5) VALUE "AEIOU".
             05 FILLER      PIC X(5) VALUE "aeiou".
             05 FILLER      PIC X(21) VALUE "BCDFGHJKLMNPQRSTVWXYZ".
             05 FILLER      PIC X(21) VALUE "bcdfghjklmnpqrstvwxyz".
          03 LETTERS        REDEFINES LETTERS-DAT.
             05 VOWELS      PIC X OCCURS 10 TIMES INDEXED BY V.
             05 CONSONANTS  PIC X OCCURS 42 TIMES INDEXED BY C.
      
       01 VARIABLES.
          03 IN-STR         PIC X(80).
          03 N-VOWELS       PIC 99.
          03 N-CONSONANTS   PIC 99.
      
       01 REPORT.
          03 R-VOWELS       PIC Z9.
          03 FILLER         PIC X(9) VALUE " vowels, ".
          03 R-CONSONANTS   PIC Z9.
          03 FILLER         PIC X(12) VALUE " consonants.".
         
       PROCEDURE DIVISION.
       BEGIN.
           MOVE "If not now, then when? If not us, then who?"
           TO IN-STR.
           PERFORM COUNT-AND-SHOW.
           STOP RUN.
          
       COUNT-AND-SHOW.
           DISPLAY IN-STR.
           PERFORM COUNT-VOWELS-AND-CONSONANTS.
           MOVE N-VOWELS TO R-VOWELS.
           MOVE N-CONSONANTS TO R-CONSONANTS.
           DISPLAY REPORT.
       
       COUNT-VOWELS-AND-CONSONANTS.
           MOVE ZERO TO N-VOWELS, N-CONSONANTS.
           SET V TO 1.
           PERFORM COUNT-VOWEL 10 TIMES.
           SET C TO 1.
           PERFORM COUNT-CONSONANT 42 TIMES.
        
       COUNT-VOWEL.
           INSPECT IN-STR TALLYING N-VOWELS FOR ALL VOWELS(V).
           SET V UP BY 1.
       
       COUNT-CONSONANT.
           INSPECT IN-STR TALLYING N-CONSONANTS FOR ALL CONSONANTS(C).
           SET C UP BY 1.
Task: Call a foreign-language function




Go: package main



import "C"
import (
    "fmt"
    "unsafe"
)

func main() {
    
    go1 := "hello C"
    
    c1 := C.CString(go1)
    
    go1 = ""
    
    c2 := C.strdup(c1)
    
    C.free(unsafe.Pointer(c1))
    
    go2 := C.GoString(c2)
    
    C.free(unsafe.Pointer(c2))
    
    fmt.Println(go2)
}






COBOL:        identification division.
       program-id. foreign.

       data division.
       working-storage section.
       01 hello.
          05 value z"Hello, world".
       01 duplicate    usage pointer.
       01 buffer       pic x(16) based.
       01 storage      pic x(16).

       procedure division.
       call "strdup" using hello returning duplicate
           on exception
               display "error calling strdup" upon syserr
       end-call
       if duplicate equal null then
           display "strdup returned null" upon syserr
       else
           set address of buffer to duplicate
           string buffer delimited by low-value into storage
           display function trim(storage)
           call "free" using by value duplicate
               on exception
                   display "error calling free" upon syserr
       end-if
       goback.
Task: Cousin primes




Go: package main

import "fmt"

func isPrime(n int) bool {
    switch {
    case n < 2:
        return false
    case n%2 == 0:
        return n == 2
    case n%3 == 0:
        return n == 3
    default:
        d := 5
        for d*d <= n {
            if n%d == 0 {
                return false
            }
            d += 2
            if n%d == 0 {
                return false
            }
            d += 4
        }
        return true
    }
}

func main() {
    count := 0
    fmt.Println("Cousin prime pairs whose elements are less than 1,000:")
    for i := 3; i <= 995; i += 2 {
        if isPrime(i) && isPrime(i+4) {
            fmt.Printf("%3d:%3d  ", i, i+4)
            count++
            if count%7 == 0 {
                fmt.Println()
            }
            if i != 3 {
                i += 4
            } else {
                i += 2
            }
        }
    }
    fmt.Printf("\n\n%d pairs found\n", count)
}






COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. COUSIN-PRIMES.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 PRIME-SIEVE.
           02 PRIME-FLAG        PIC 9 OCCURS 1000 INDEXED BY P, Q.
              88 PRIME          VALUE 1.
           02 STEP-SIZE         PIC 999.
           02 X                 PIC 999.
           02 P-START           PIC 999.
           02 AMOUNT            PIC 999 VALUE 0.
        01 OUTPUT-FORMAT.
           02 COUSIN1           PIC ZZ9.
           02 COUSIN2           PIC ZZ9.
           
        PROCEDURE DIVISION.
        BEGIN.
            PERFORM SIEVE.
            PERFORM TEST-COUSINS VARYING P FROM 2 BY 1
                UNTIL P IS GREATER THAN 996.
            MOVE AMOUNT TO COUSIN1.
            DISPLAY COUSIN1 ' pairs found.'
            STOP RUN.
        
        TEST-COUSINS.
            IF PRIME(P) AND PRIME(P + 4)
                SET X TO P 
                MOVE X TO COUSIN1
                ADD X, 4 GIVING COUSIN2
                DISPLAY COUSIN1 ' ' COUSIN2
                ADD 1 TO AMOUNT.
        
        SIEVE SECTION.
        BEGIN.
            PERFORM FLAG-PRIME VARYING Q FROM 1 BY 1
                UNTIL Q IS GREATER THAN 1000.
            PERFORM SIEVE-PRIME VARYING P FROM 2 BY 1
                UNTIL P IS GREATER THAN 32.
            GO TO DONE.
        
        SIEVE-PRIME.
            IF PRIME(P)
                SET X TO P
                COMPUTE P-START = X ** 2
                PERFORM UNFLAG-PRIME VARYING Q FROM P-START BY X
                    UNTIL Q IS GREATER THAN 1000.
                    
        FLAG-PRIME.   MOVE 1 TO PRIME-FLAG(Q).
        UNFLAG-PRIME. MOVE 0 TO PRIME-FLAG(Q).
        DONE. EXIT.
Task: Flow-control structures




Go: func main() {
inf:
    goto inf
}






COBOL:        PROGRAM-ID. Go-To-Example.

       PROCEDURE DIVISION.
       Foo.
           DISPLAY "Just a reminder: GO TOs are evil."

           GO TO Foo
           .
Task: Return multiple values




Go: func addsub(x, y int) (int, int) {
  return x + y, x - y
}






COBOL:        identification division.
       program-id. multiple-values.

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

       REPLACE ==:linked-items:== BY ==
       01 a usage binary-long.
       01 b pic x(10).
       01 c usage float-short.
       ==
       ==:record-item:== BY ==
       01 master.
          05 ma usage binary-long.
          05 mb pic x(10).
          05 mc usage float-short.
       ==.

       data division.
       working-storage section.
       :linked-items:

       :record-item:
       
       procedure division.
       sample-main.

       move 41 to a
       move "aaaaabbbbb" to b
       move function e to c

       display "Original: " a ", " b ", " c
       call "subprogram" using a b c
       display "Modified: " a ", " b ", " c
       
       move multiples() to master
       display "Multiple: " ma ", " mb ", " mc

       goback.
       end program multiple-values.

      
       identification division.
       program-id. subprogram.

       data division.
       linkage section.
       :linked-items:

       procedure division using a b c.
       add 1 to a
       inspect b converting "a" to "b"
       divide 2 into c
       goback.
       end program subprogram.

      
       identification division.
       function-id. multiples.

       data division.
       linkage section.
       :record-item:

       procedure division returning master.
       move 84 to ma
       move "multiple" to mb
       move function pi to mc
       goback.
       end function multiples.
Task: Substring_Top and tail




Go: package main

import (
    "fmt"
    "unicode/utf8"
)

func main() {
    
    s := "ASCII"
    fmt.Println("String:                ", s)
    fmt.Println("First byte removed:    ", s[1:])
    fmt.Println("Last byte removed:     ", s[:len(s)-1])
    fmt.Println("First and last removed:", s[1:len(s)-1])
    
    u := "Δημοτική"
    fmt.Println("String:                ", u)
    _, sizeFirst := utf8.DecodeRuneInString(u)
    fmt.Println("First rune removed:    ", u[sizeFirst:])
    _, sizeLast := utf8.DecodeLastRuneInString(u)
    fmt.Println("Last rune removed:     ", u[:len(u)-sizeLast])
    fmt.Println("First and last removed:", u[sizeFirst:len(u)-sizeLast])
}






COBOL:        identification division.
       program-id. toptail.

       data division.
       working-storage section.
       01 data-field.
          05 value "[this is a test]".

       procedure division.
       sample-main.
       display data-field
      
       display data-field(2:)
       display data-field(1:length of data-field - 1)
       display data-field(2:length of data-field - 2)
       goback.
       end program toptail.
Task: Boolean values




Go:  
package main

import (
	"fmt"
	"reflect"
	"strconv"
)

func main() {
	var n bool = true
	fmt.Println(n)        
	fmt.Printf("%T\n", n) 
	n = !n
	fmt.Println(n) 

	x := 5
	y := 8
	fmt.Println("x == y:", x == y) 
	fmt.Println("x < y:", x < y)   

	fmt.Println("\nConvert String into Boolean Data type\n")
	str1 := "japan"
	fmt.Println("Before :", reflect.TypeOf(str1)) 
	bolStr, _ := strconv.ParseBool(str1)
	fmt.Println("After :", reflect.TypeOf(bolStr)) 
}






COBOL:        01  some-bool               PIC 1 BIT.
Task: First 9 prime Fibonacci number




Go: package main

import "fmt"

func isPrime(n uint64) bool {
    if n < 2 {
        return false
    }
    if n%2 == 0 {
        return n == 2
    }
    if n%3 == 0 {
        return n == 3
    }
    d := uint64(5)
    for d*d <= n {
        if n%d == 0 {
            return false
        }
        d += 2
        if n%d == 0 {
            return false
        }
        d += 4
    }
    return true
}

func main() {
    f1 := uint64(1)
    f2 := f1
    count := 0
    limit := 12 
    fmt.Printf("The first %d prime Fibonacci numbers are:\n", limit)
    for count < limit {
        f3 := f1 + f2
        if isPrime(f3) {
            fmt.Printf("%d ", f3)
            count++
        }
        f1 = f2
        f2 = f3
    }
    fmt.Println()
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. PRIME-FIBONACCI.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 FIBONACCI-VARS.
          03 FIB                PIC 9(6).
          03 FIB-B              PIC 9(6).
          03 FIB-C              PIC 9(6).
          03 FIB-OUT            PIC Z(5)9.
       01 PRIME-VARS.   
          03 PRIME-FLAG         PIC X.
             88 PRIME           VALUE 'X'.
          03 DSOR               PIC 9(4).
          03 DSOR-SQ            PIC 9(6).
          03 DIV-RSLT           PIC 9(6)V9(3).
          03 FILLER             REDEFINES DIV-RSLT.
             05 FILLER          PIC 9(6).
             05 FILLER          PIC 9(3).
                88 DIVISIBLE    VALUE ZERO.
          
       PROCEDURE DIVISION.
       BEGIN.
           MOVE 1 TO FIB, FIB-B.
           PERFORM FIND-PRIME-FIBONACCI 9 TIMES.
           STOP RUN.
       
       FIND-PRIME-FIBONACCI.
           ADD FIB, FIB-B GIVING FIB-C.
           MOVE FIB-B TO FIB.
           MOVE FIB-C TO FIB-B.
           PERFORM CHECK-PRIME.
           IF NOT PRIME, GO TO FIND-PRIME-FIBONACCI.
           MOVE FIB TO FIB-OUT.
           DISPLAY FIB-OUT.
       
       CHECK-PRIME SECTION.
       BEGIN.
           MOVE SPACE TO PRIME-FLAG.
           IF FIB IS LESS THAN 5, GO TO TRIVIAL-PRIME.
           DIVIDE FIB BY 2 GIVING DIV-RSLT.
           IF DIVISIBLE, GO TO DONE.
           DIVIDE FIB BY 3 GIVING DIV-RSLT.
           IF DIVISIBLE, GO TO DONE.
           MOVE 5 TO DSOR.
           MOVE 25 TO DSOR-SQ.
           MOVE 'X' TO PRIME-FLAG.
           PERFORM TEST-DIVISOR 
           UNTIL NOT PRIME OR DSOR-SQ IS GREATER THAN FIB.
           GO TO DONE.
           
       TEST-DIVISOR.
           DIVIDE FIB BY DSOR GIVING DIV-RSLT.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 2 TO DSOR.
           DIVIDE FIB BY DSOR GIVING DIV-RSLT.
           IF DIVISIBLE, MOVE SPACE TO PRIME-FLAG.
           ADD 4 TO DSOR.
           MULTIPLY DSOR BY DSOR GIVING DSOR-SQ.
       
       TRIVIAL-PRIME.
           IF FIB IS EQUAL TO 2 OR 3, MOVE 'X' TO PRIME-FLAG.
       DONE.
           EXIT.
Task: Terminal control_Inverse video




Go: package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    tput("rev")
    fmt.Print("Rosetta")
    tput("sgr0")
    fmt.Println(" Code")
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. terminal-reverse-video.

       PROCEDURE DIVISION.
           DISPLAY "Reverse-Video" WITH REVERSE-VIDEO
           DISPLAY "Normal"

           GOBACK
           .
Task: Hello world_Line printer




Go: package main

import (
	"fmt"
	"os"
)

func main() {
	lp0, err := os.Create("/dev/lp0")

	if err != nil {
		panic(err)
	}

	defer lp0.Close()

	fmt.Fprintln(lp0, "Hello World!")
}






COBOL: IDENTIFICATION DIVISION.
PROGRAM-ID. GOODBYE-WORLD-PRINTER.

PROCEDURE DIVISION.
DISPLAY 'Hello World!'
	UPON PRINTER
END-DISPLAY.
STOP RUN.