WeixiangYan/CodeTransOcean huggingface dataset:
Task: Find the last Sunday of each month

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

int main(int argc, char *argv[])
{
        int days[] = {31,29,31,30,31,30,31,31,30,31,30,31};
        int m, y, w;

        if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1;
        days[1] -= (y % 4) || (!(y % 100) && (y % 400));
        w = y * 365 + 97 * (y - 1) / 400 + 4;

        for(m = 0; m < 12; m++) {
                w = (w + days[m]) % 7;
                printf("%d-%02d-%d\n", y, m + 1,days[m] - w);
        }

        return 0;
}









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

C: #include <stdio.h>
#include <math.h>

int main() {
    int i, p, low, high, pow = 1, osc;
    int oddSq[120];
    for (p = 0; p < 5; ++p) {
        low = (int)ceil(sqrt((double)pow));
        if (!(low%2)) ++low;
        pow *= 10;
        high = (int)sqrt((double)pow);
        for (i = low, osc = 0; i <= high; i += 2) {
            oddSq[osc++] = i * i;
        }
        printf("%d odd square from %d to %d:\n", osc, pow/10, pow);
        for (i = 0; i < osc; ++i) {
            printf("%d ", oddSq[i]);
            if (!((i+1)%10)) printf("\n");
        }
        printf("\n\n");
    }
    return 0;
}









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

C: #include <stdio.h>
#include <stdbool.h>

int digit_sum(int n) {
    int sum;
    for (sum = 0; n; n /= 10) sum += n % 10;
    return sum;
}


bool prime(int n) {
    if (n<4) return n>=2;
    for (int d=2; d*d <= n; d++)
        if (n%d == 0) return false;
    return true;
}

int main() {
    for (int i=1; i<100; i++)
        if (prime(digit_sum(i*i)) & prime(digit_sum(i*i*i)))
            printf("%d ", i);
    printf("\n");
    return 0;
}









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: Find squares n where n+1 is prime

C: #include <stdio.h>
#include <stdbool.h>
#include <math.h>

#define MAX 1000

void sieve(int n, bool *prime) {
    prime[0] = prime[1] = false;
    for (int i=2; i<=n; i++) prime[i] = true;
    for (int p=2; p*p<=n; p++) 
        if (prime[p])
            for (int c=p*p; c<=n; c+=p) prime[c] = false;
}

bool square(int n) {
    int sq = sqrt(n);
    return (sq * sq == n);
}

int main() {
    bool prime[MAX + 1];
    sieve(MAX, prime);
    for (int i=2; i<=MAX; i++) if (prime[i]) {
        int sq = i-1;
        if (square(sq)) printf("%d ", sq);
    }
    printf("\n");
    return 0;
}









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

C: #include <stdio.h>

void f(int n) {
    int i = 1;
    if (n < 1) {
        return;
    }
    while (1) {
        int sq = i * i;
        while (sq > n) {
            sq /= 10;
        }
        if (sq == n) {
            printf("%3d %9d %4d\n", n, i * i, i);
            return;
        }
        i++;
    }
}

int main() {
    int i;

    printf("Prefix    n^2    n\n");
    printf("");
    for (i = 1; i < 50; i++) {
        f(i);
    }

    return 0;
}









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

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

#define min(a, b) (a<=b?a:b)

void minab( unsigned int n ) {
    int i, j;
    for(i=0;i<n;i++) {
        for(j=0;j<n;j++) {
            printf( "%2d  ", min( min(i, n-1-i), min(j, n-1-j) ));
        }
        printf( "\n" );
    }
    return;
}

int main(void) {
    minab(10);
    return 0;
}









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

C: #include <stdio.h>

static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0,
                    0, 1, 0, 1, 0, 0, 0, 1, 0};

int isstrange(long n) {
    if (n < 10) return 0;
    for (; n >= 10; n /= 10) {
        if (!p[n%10 + (n/10)%10]) return 0;
    }
    return 1;
}

int main(void) {
    long n;
    int k = 0;

    for (n = 101; n < 500; n++) {
        if (isstrange(n)) {
            printf("%d%c", n, ++k%10 ? ' ' : '\n');
        }
    }
    return 0;
}









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

C: #include <stdio.h>

unsigned digit_sum(unsigned n) {
    unsigned sum = 0;
    do { sum += n % 10; }
    while(n /= 10);
    return sum;
}

unsigned a131382(unsigned n) {
    unsigned m;
    for (m = 1; n != digit_sum(m*n); m++);
    return m;
}

int main() {
    unsigned n;
    for (n = 1; n <= 70; n++) {
        printf("%9u", a131382(n));
        if (n % 10 == 0) printf("\n");
    }
    return 0;
}









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: Test integerness

C: #include <stdio.h>
#include <complex.h>
#include <math.h>


#define FMTSPEC(arg) _Generic((arg), \
    float: "%f", double: "%f", \
    long double: "%Lf", unsigned int: "%u", \
    unsigned long: "%lu", unsigned long long: "%llu", \
    int: "%d", long: "%ld", long long: "%lld", \
    default: "(invalid type (%p)")

#define CMPPARTS(x, y) ((long double complex)((long double)(x) + \
            I * (long double)(y)))

#define TEST_CMPL(i, j)\
    printf(FMTSPEC(i), i), printf(" + "), printf(FMTSPEC(j), j), \
    printf("i = %s\n", (isint(CMPPARTS(i, j)) ? "true" : "false"))

#define TEST_REAL(i)\
    printf(FMTSPEC(i), i), printf(" = %s\n", (isint(i) ? "true" : "false"))


static inline int isint(long double complex n)
{
    return cimagl(n) == 0 && nearbyintl(creall(n)) == creall(n);
}

int main(void)
{
    TEST_REAL(0);
    TEST_REAL(-0);
    TEST_REAL(-2);
    TEST_REAL(-2.00000000000001);
    TEST_REAL(5);
    TEST_REAL(7.3333333333333);
    TEST_REAL(3.141592653589);
    TEST_REAL(-9.223372036854776e18);
    TEST_REAL(5e-324);
    TEST_REAL(NAN);
    TEST_CMPL(6, 0);
    TEST_CMPL(0, 1);
    TEST_CMPL(0, 0);
    TEST_CMPL(3.4, 0);

    
    double complex test1 = 5 + 0*I,
                   test2 = 3.4f,
                   test3 = 3,
                   test4 = 0 + 1.2*I;

    printf("Test 1 (5+i) = %s\n", isint(test1) ? "true" : "false");
    printf("Test 2 (3.4+0i) = %s\n", isint(test2) ? "true" : "false");
    printf("Test 3 (3+0i) = %s\n", isint(test3) ? "true" : "false");
    printf("Test 4 (0+1.2i) = %s\n", isint(test4) ? "true" : "false");
}









COBOL: IDENTIFICATION DIVISION.
PROGRAM-ID. INTEGERNESS-PROGRAM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  INTEGERS-OR-ARE-THEY.
    05 POSSIBLE-INTEGER PIC S9(9)V9(9).
    05 DEFINITE-INTEGER PIC S9(9).
01  COMPLEX-NUMBER.
    05 REAL-PART        PIC S9(9)V9(9).
    05 IMAGINARY-PART   PIC S9(9)V9(9).
PROCEDURE DIVISION.
TEST-PARAGRAPH.
    MOVE ZERO TO IMAGINARY-PART.
    DIVIDE -28 BY 7 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    DIVIDE 28 BY 18 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    DIVIDE 3 BY 10000000000 GIVING POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
TEST-COMPLEX-PARAGRAPH.
    MOVE ZERO TO REAL-PART.
    MOVE 1 TO IMAGINARY-PART.
    MOVE REAL-PART TO POSSIBLE-INTEGER.
    PERFORM INTEGER-PARAGRAPH.
    STOP RUN.
INTEGER-PARAGRAPH.
    IF IMAGINARY-PART IS EQUAL TO ZERO THEN PERFORM REAL-PARAGRAPH,
    ELSE PERFORM COMPLEX-PARAGRAPH.
REAL-PARAGRAPH.
    MOVE POSSIBLE-INTEGER TO DEFINITE-INTEGER.
    IF DEFINITE-INTEGER IS EQUAL TO POSSIBLE-INTEGER
    THEN DISPLAY POSSIBLE-INTEGER ' IS AN INTEGER.',
    ELSE DISPLAY POSSIBLE-INTEGER ' IS NOT AN INTEGER.'.
COMPLEX-PARAGRAPH.
    DISPLAY REAL-PART '+' IMAGINARY-PART 'i IS NOT AN INTEGER.'.
Task: Print debugging statement

C: #include <stdio.h>

#define DEBUG_INT(x) printf( #x " at line %d\nresult: %d\n\n", __LINE__, x)

int add(int x, int y) {
  int result = x + y;
  DEBUG_INT(x);
  DEBUG_INT(y);
  DEBUG_INT(result);
  DEBUG_INT(result+1);
  return result;
}

int main() {
  add(2, 7);
  return 0;
}









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: IRC gateway




Go: package main

import (
    "crypto/tls"
    "fmt"
    "github.com/thoj/go-ircevent"
    "log"
    "os"
)

func main() {
    if len(os.Args) != 9 {
        fmt.Println("To use this gateway, you need to pass 8 command line arguments, namely:")
        fmt.Println("  <server1> <channel1> <nick1> <user1> <server2> <channel2> <nick2> <user2>")
        return
    }
    server1, channel1, nick1, user1 := os.Args[1], os.Args[2], os.Args[3], os.Args[4]
    server2, channel2, nick2, user2 := os.Args[5], os.Args[6], os.Args[7], os.Args[8]

    irc1 := irc.IRC(nick1, user1)
    irc1.VerboseCallbackHandler = true
    irc1.Debug = false
    irc1.UseTLS = true
    irc1.TLSConfig = &tls.Config{InsecureSkipVerify: true}

    irc2 := irc.IRC(nick2, user2)
    irc2.VerboseCallbackHandler = true
    irc2.Debug = false
    irc2.UseTLS = true
    irc2.TLSConfig = &tls.Config{InsecureSkipVerify: true}

    irc1.AddCallback("001", func(e *irc.Event) {
        irc1.Join(channel1)
        msg := fmt.Sprintf("<gateway> Hello %s. Please send your first message to %s.", nick1, nick2)
        irc1.Privmsg(nick1, msg)
        log.Println(msg)
    })

    irc1.AddCallback("366", func(e *irc.Event) {})

    irc1.AddCallback("PRIVMSG", func(e *irc.Event) {
        msg := fmt.Sprintf("<%s> %s", nick1, e.Message)
        irc2.Privmsg(nick2, msg)
        log.Println(msg)
    })

    irc2.AddCallback("001", func(e *irc.Event) {
        irc2.Join(channel2)
        msg := fmt.Sprintf("<gateway> Hello %s. Please wait for your first message from %s.", nick2, nick1)
        irc2.Privmsg(nick2, msg)
        log.Println(msg)
    })

    irc2.AddCallback("366", func(e *irc.Event) {})

    irc2.AddCallback("PRIVMSG", func(e *irc.Event) {
        msg := fmt.Sprintf("<%s> %s", nick2, e.Message)
        irc1.Privmsg(nick1, msg)
        log.Println(msg)
    })

    err1 := irc1.Connect(server1)
    if err1 != nil {
        log.Fatal(err1)
    }

    err2 := irc2.Connect(server2)
    if err2 != nil {
        log.Fatal(err2)
    }

    go irc2.Loop()
    irc1.Loop()
}
Task: Remote agent_Agent interface




Go: package ifc






type Streamer interface {
    Send(byte)
    Rec() byte
}



const Handshake = 'A'

const (
    CmdForward       = '^'
    CmdRight         = '>'
    CmdLeft          = '<'
    CmdGet           = '@'
    CmdDrop          = '!'
    EvGameOver       = '+'
    EvStop           = '.'
    EvColorRed       = 'R'
    EvColorGreen     = 'G'
    EvColorYellow    = 'Y'
    EvColorBlue      = 'B'
    EvBallRed        = 'r'
    EvBallGreen      = 'g'
    EvBallYellow     = 'y'
    EvBallBlue       = 'b'
    EvBump           = '|'
    EvSectorFull     = 'S'
    EvAgentFull      = 'A'
    EvNoBallInSector = 's'
    EvNoBallInAgent  = 'a'
)
Task: CalmoSoft primes


C++: #include <chrono>
#include <iostream>
#include <locale>
#include <numeric>
#include <sstream>

#include <primesieve.hpp>

bool is_prime(uint64_t n) {
    if (n < 2)
        return false;
    if (n % 2 == 0)
        return n == 2;
    if (n % 3 == 0)
        return n == 3;
    if (n % 5 == 0)
        return n == 5;
    static constexpr uint64_t wheel[] = {4, 2, 4, 2, 4, 6, 2, 6};
    uint64_t p = 7;
    for (;;) {
        for (uint64_t w : wheel) {
            if (p * p > n)
                return true;
            if (n % p == 0)
                return false;
            p += w;
        }
    }
}

template <typename Iterator>
std::string join(Iterator begin, Iterator end, std::string_view separator) {
    std::ostringstream os;
    if (begin != end) {
        os << *begin++;
        for (; begin != end; ++begin)
            os << separator << *begin;
    }
    return os.str();
}

int main() {
    std::cout.imbue(std::locale(""));
    auto start = std::chrono::high_resolution_clock::now();
    std::vector<uint64_t> primes;
    uint64_t from = 0;
    for (uint64_t limit : {100, 5000, 10000, 500000, 50000000}) {
        primesieve::generate_primes(from, limit, &primes);
        from = limit + 1;
        uint64_t sum =
            std::accumulate(primes.begin(), primes.end(), uint64_t(0));
        size_t last = primes.size();
        size_t longest = 1;
        std::vector<std::pair<size_t, uint64_t>> starts;
        for (size_t start = 0; start <= last - longest; ++start) {
            uint64_t s = sum;
            for (size_t finish = last; finish-- >= start + longest;) {
                if (is_prime(s)) {
                    size_t length = finish - start + 1;
                    if (length > longest) {
                        longest = length;
                        starts.clear();
                    }
                    starts.emplace_back(start, s);
                }
                s -= primes[finish];
            }
            sum -= primes[start];
        }
        std::cout << "For primes up to " << limit << ":\n"
                  << "The following sequence" << (starts.size() == 1 ? "" : "s")
                  << " of " << longest << " consecutive primes yield"
                  << (starts.size() == 1 ? "s" : "") << " a prime sum:\n";
        for (auto [start, sum] : starts) {
            auto begin = primes.begin() + start;
            auto end = begin + longest;
            const char* separator = " + ";
            if (longest > 12) {
                std::cout << join(begin, begin + 6, separator) << separator
                          << "..." << separator
                          << join(end - 6, end, separator);
            } else {
                std::cout << join(begin, end, separator);
            }
            std::cout << " = " << sum << '\n';
        }
        std::cout << '\n';
    }
    auto end = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> duration(end - start);
    std::cout << "Elapsed time: " << duration.count() << " seconds\n";
}