WeixiangYan/CodeTransOcean huggingface dataset:
Task: OpenGL pixel shader




Go: package main


import "C"
import "log"
import "unsafe"

var ps, vs, prog, r_mod C.GLuint
var angle = float32(0)


func render() {
    C.glClear(C.GL_COLOR_BUFFER_BIT)
    C.glUniform1f_macro(C.GLint(r_mod), C.GLfloat(C.rand())/C.GLfloat(C.RAND_MAX))
    C.glLoadIdentity()
    C.glRotatef(C.float(angle), C.float(angle*0.1), 1, 0)
    C.glBegin(C.GL_TRIANGLES)
    C.glVertex3f(-1, -0.5, 0)
    C.glVertex3f(0, 1, 0)
    C.glVertex3f(1, 0, 0)
    C.glEnd()
    angle += 0.02
    C.glutSwapBuffers()
}

func setShader() {
    f := "varying float x, y, z;" +
        "uniform float r_mod;" +
        "float rand(float s, float r) { return mod(mod(s, r + r_mod) * 112341.0, 1.0); }" +
        "void main() {" +
        "    gl_FragColor = vec4(rand(gl_FragCoord.x, x), rand(gl_FragCoord.y, y), rand(gl_FragCoord.z, z), 1.0);" +
        "}"

    v := "varying float x, y, z;" +
        "void main() {" +
        "    gl_Position = ftransform();" +
        "    x = gl_Position.x; y = gl_Position.y; z = gl_Position.z;" +
        "    x += y; y -= x; z += x - y;" +
        "}"

    fc, vc := C.CString(f), C.CString(v)
    defer C.free(unsafe.Pointer(fc))
    defer C.free(unsafe.Pointer(vc))

    vs = C.glCreateShader_macro(C.GL_VERTEX_SHADER)
    ps = C.glCreateShader_macro(C.GL_FRAGMENT_SHADER)
    C.glShaderSource_macro(ps, 1, &fc, nil)
    C.glShaderSource_macro(vs, 1, &vc, nil)

    C.glCompileShader_macro(vs)
    C.glCompileShader_macro(ps)

    prog = C.glCreateProgram_macro()
    C.glAttachShader_macro(prog, ps)
    C.glAttachShader_macro(prog, vs)

    C.glLinkProgram_macro(prog)
    C.glUseProgram_macro(prog)
    rms := C.CString("r_mod")
    r_mod = C.GLuint(C.glGetUniformLocation_macro(prog, rms))
    C.free(unsafe.Pointer(rms))
}

func main() {
    argc := C.int(0)
    C.glutInit(&argc, nil)
    C.glutInitDisplayMode(C.GLUT_DOUBLE | C.GLUT_RGB)
    C.glutInitWindowSize(200, 200)
    tl := "Pixel Shader"
    tlc := C.CString(tl)
    C.glutCreateWindow(tlc)
    defer C.free(unsafe.Pointer(tlc))
    C.glutIdleFunc(C.idleFunc())

    C.glewInit()
    glv := C.CString("GL_VERSION_2_0")
    if C.glewIsSupported(glv) == 0 {
        log.Fatal("GL 2.0 unsupported")
    }
    defer C.free(unsafe.Pointer(glv))

    setShader()
    C.glutMainLoop()
}
Task: Extra primes

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

unsigned int next_prime_digit_number(unsigned int n) {
    if (n == 0)
        return 2;
    switch (n % 10) {
    case 2:
        return n + 1;
    case 3:
    case 5:
        return n + 2;
    default:
        return 2 + next_prime_digit_number(n/10) * 10;
    }
}

bool is_prime(unsigned int n) {
    if (n < 2)
        return false;
    if ((n & 1) == 0)
        return n == 2;
    if (n % 3 == 0)
        return n == 3;
    if (n % 5 == 0)
        return n == 5;
    static const unsigned int wheel[] = { 4,2,4,2,4,6,2,6 };
    unsigned int p = 7;
    for (;;) {
        for (int w = 0; w < sizeof(wheel)/sizeof(wheel[0]); ++w) {
            if (p * p > n)
                return true;
            if (n % p == 0)
                return false;
            p += wheel[w];
        }
    }
}

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

int main() {
    setlocale(LC_ALL, "");
    const unsigned int limit1 = 10000;
    const unsigned int limit2 = 1000000000;
    const int last = 10;
    unsigned int p = 0, n = 0;
    unsigned int extra_primes[last];
    printf("Extra primes under %'u:\n", limit1);
    while ((p = next_prime_digit_number(p)) < limit2) {
        if (is_prime(digit_sum(p)) && is_prime(p)) {
            ++n;
            if (p < limit1)
                printf("%2u: %'u\n", n, p);
            extra_primes[n % last] = p;
        }
    }
    printf("\nLast %d extra primes under %'u:\n", last, limit2);
    for (int i = last - 1; i >= 0; --i)
        printf("%'u: %'u\n", n-i, extra_primes[(n-i) % last]);
    return 0;
}
Task: Sum data type

C: #include<stdio.h>

typedef union data{
        int i;
        float f;
        char c;
}united;

int main()
{
        united udat;

        udat.i = 5;
        udat.f = 3.14159;
        udat.c = 'C';

        printf("Integer   i = %d , address of i = %p\n",udat.i,&udat.i);
        printf("Float     f = %f , address of f = %p\n",udat.f,&udat.f);
        printf("Character c = %c , address of c = %p\n",udat.c,&udat.c);

        return 0;
}
Task: Air mass

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

#define DEG 0.017453292519943295769236907684886127134  
#define RE 6371000.0 
#define DD 0.001 
#define FIN 10000000.0 

static double rho(double a) {
    
    return exp(-a / 8500.0);
}

static double height(double a, double z, double d) {
    
    
    
    double aa = RE + a;
    double hh = sqrt(aa * aa + d * d - 2.0 * d * aa * cos((180 - z) * DEG));
    return hh - RE;
}

static double column_density(double a, double z) {
    
    double sum = 0.0, d = 0.0;
    while (d < FIN) {
        
        double delta = DD * d;
        if (delta < DD)
            delta = DD;
        sum += rho(height(a, z, d + 0.5 * delta)) * delta;
        d += delta;
    }
    return sum;
}

static double airmass(double a, double z) {
    return column_density(a, z) / column_density(a, 0.0);
}

int main() {
    puts("Angle     0 m              13700 m");
    puts("------------------------------------");
    for (double z = 0; z <= 90; z+= 5) {
        printf("%2.0f      %11.8f      %11.8f\n",
               z, airmass(0.0, z), airmass(13700.0, z));
    }
}
Task: Deceptive numbers

C: #include <stdio.h>

unsigned modpow(unsigned b, unsigned e, unsigned m)
{
    unsigned p = 1;
    while (e) {
        if (e & 1)
            p = p * b % m;
        b = b * b % m;
        e >>= 1;
    }
    return p;
}

int is_deceptive(unsigned n)
{
    unsigned x;
    if (n & 1 && n % 3 && n % 5) {
        for (x = 7; x * x <= n; x += 6) {
            if (!(n % x && n % (x + 4)))
                return modpow(10, n - 1, n * 9) == 1;
        }
    }
    return 0;
}

int main(void)
{
    unsigned c, i = 49;
    for (c = 0; c != 18; ++i) {
        if (is_deceptive(i)) {
            printf(" %u", i);
            ++c;
        }
    }
    return 0;
}
Task: Magnanimous numbers

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

typedef int bool;
typedef unsigned long long ull;

#define TRUE 1
#define FALSE 0


bool is_prime(ull n) {
    ull d;
    if (n < 2) return FALSE;
    if (!(n % 2)) return n == 2;
    if (!(n % 3)) return n == 3;
    d = 5;
    while (d * d <= n) {
        if (!(n % d)) return FALSE;
        d += 2;
        if (!(n % d)) return FALSE;
        d += 4;
    }
    return TRUE;
}

void ord(char *res, int n) {
    char suffix[3];
    int m = n % 100;
    if (m >= 4 && m <= 20) {
        sprintf(res,"%dth", n);
        return;
    }
    switch(m % 10) {
        case 1:
            strcpy(suffix, "st");
            break;
        case 2:
            strcpy(suffix, "nd");
            break;
        case 3:
            strcpy(suffix, "rd");
            break;
        default:
            strcpy(suffix, "th");
            break;
    }
    sprintf(res, "%d%s", n, suffix);
}

bool is_magnanimous(ull n) {
    ull p, q, r;
    if (n < 10) return TRUE;
    for (p = 10; ; p *= 10) {
        q = n / p;
        r = n % p;
        if (!is_prime(q + r)) return FALSE;
        if (q < 10) break;
    }
    return TRUE;
}

void list_mags(int from, int thru, int digs, int per_line) {
    ull i = 0;
    int c = 0;
    char res1[13], res2[13];
    if (from < 2) {
        printf("\nFirst %d magnanimous numbers:\n", thru);
    } else {
        ord(res1, from);
        ord(res2, thru);
        printf("\n%s through %s magnanimous numbers:\n", res1, res2);
    }
    for ( ; c < thru; ++i) {
        if (is_magnanimous(i)) {
            if (++c >= from) {
                printf("%*llu ", digs, i);
                if (!(c % per_line)) printf("\n");
            }
        }
    }
}
 
int main() {
    list_mags(1, 45, 3, 15);
    list_mags(241, 250, 1, 10);
    list_mags(391, 400, 1, 10);
    return 0;
}
Task: Smarandache prime-digital sequence

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

typedef uint32_t integer;

integer next_prime_digit_number(integer n) {
    if (n == 0)
        return 2;
    switch (n % 10) {
    case 2:
        return n + 1;
    case 3:
    case 5:
        return n + 2;
    default:
        return 2 + next_prime_digit_number(n/10) * 10;
    }
}

bool is_prime(integer 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 const integer wheel[] = { 4,2,4,2,4,6,2,6 };
    integer p = 7;
    for (;;) {
        for (int i = 0; i < 8; ++i) {
            if (p * p > n)
                return true;
            if (n % p == 0)
                return false;
            p += wheel[i];
        }
    }
}

int main() {
    setlocale(LC_ALL, "");
    const integer limit = 1000000000;
    integer n = 0, max = 0;
    printf("First 25 SPDS primes:\n");
    for (int i = 0; n < limit; ) {
        n = next_prime_digit_number(n);
        if (!is_prime(n))
            continue;
        if (i < 25) {
            if (i > 0)
                printf(" ");
            printf("%'u", n);
        }
        else if (i == 25)
            printf("\n");
        ++i;
        if (i == 100)
            printf("Hundredth SPDS prime: %'u\n", n);
        else if (i == 1000)
            printf("Thousandth SPDS prime: %'u\n", n);
        else if (i == 10000)
            printf("Ten thousandth SPDS prime: %'u\n", n);
        max = n;
    }
    printf("Largest SPDS prime less than %'u: %'u\n", limit, max);
    return 0;
}
Task: Ulam numbers

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

void fatal(const char* message) {
    fprintf(stderr, "%s\n", message);
    exit(1);
}

void* xmalloc(size_t n) {
    void* ptr = malloc(n);
    if (ptr == NULL)
        fatal("Out of memory");
    return ptr;
}

void* xrealloc(void* p, size_t n) {
    void* ptr = realloc(p, n);
    if (ptr == NULL)
        fatal("Out of memory");
    return ptr;
}

int* extend(int* array, int min_length, int* capacity) {
    int new_capacity = *capacity;
    if (new_capacity >= min_length)
        return array;
    while (new_capacity < min_length)
        new_capacity *= 2;
    array = xrealloc(array, new_capacity * sizeof(int));
    memset(array + *capacity, 0, (new_capacity - *capacity) * sizeof(int));
    *capacity = new_capacity;
    return array;
}

int ulam(int n) {
    int* ulams = xmalloc((n < 2 ? 2 : n) * sizeof(int));
    ulams[0] = 1;
    ulams[1] = 2;
    int sieve_length = 2;
    int sieve_capacity = 2;
    int* sieve = xmalloc(sieve_capacity * sizeof(int));
    sieve[0] = sieve[1] = 1;
    for (int u = 2, ulen = 2; ulen < n; ) {
        sieve_length = u + ulams[ulen - 2];
        sieve = extend(sieve, sieve_length, &sieve_capacity);
        for (int i = 0; i < ulen - 1; ++i)
            ++sieve[u + ulams[i] - 1];
        for (int i = u; i < sieve_length; ++i) {
            if (sieve[i] == 1) {
                u = i + 1;
                ulams[ulen++] = u;
                break;
            }
        }
    }
    int result = ulams[n - 1];
    free(ulams);
    free(sieve);
    return result;
}

int main() {
    clock_t start = clock();
    for (int n = 1; n <= 100000; n *= 10)
        printf("Ulam(%d) = %d\n", n, ulam(n));
    clock_t finish = clock();
    printf("Elapsed time: %.3f seconds\n", (finish - start + 0.0)/CLOCKS_PER_SEC);
    return 0;
}
Task: Palindromic gapful numbers

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

typedef uint64_t integer;

integer reverse(integer n) {
    integer rev = 0;
    while (n > 0) {
        rev = rev * 10 + (n % 10);
        n /= 10;
    }
    return rev;
}

typedef struct palgen_tag {
    integer power;
    integer next;
    int digit;
    bool even;
} palgen_t;

void init_palgen(palgen_t* palgen, int digit) {
    palgen->power = 10;
    palgen->next = digit * palgen->power - 1;
    palgen->digit = digit;
    palgen->even = false;
}

integer next_palindrome(palgen_t* p) {
    ++p->next;
    if (p->next == p->power * (p->digit + 1)) {
        if (p->even)
            p->power *= 10;
        p->next = p->digit * p->power;
        p->even = !p->even;
    }
    return p->next * (p->even ? 10 * p->power : p->power)
        + reverse(p->even ? p->next : p->next/10);
}

bool gapful(integer n) {
    integer m = n;
    while (m >= 10)
        m /= 10;
    return n % (n % 10 + 10 * m) == 0;
}

void print(int len, integer array[][len]) {
    for (int digit = 1; digit < 10; ++digit) {
        printf("%d: ", digit);
        for (int i = 0; i < len; ++i)
            printf(" %llu", array[digit - 1][i]);
        printf("\n");
    }
}

int main() {
    const int n1 = 20, n2 = 15, n3 = 10;
    const int m1 = 100, m2 = 1000;

    integer pg1[9][n1];
    integer pg2[9][n2];
    integer pg3[9][n3];

    for (int digit = 1; digit < 10; ++digit) {
        palgen_t pgen;
        init_palgen(&pgen, digit);
        for (int i = 0; i < m2; ) {
            integer n = next_palindrome(&pgen);
            if (!gapful(n))
                continue;
            if (i < n1)
                pg1[digit - 1][i] = n;
            else if (i < m1 && i >= m1 - n2)
                pg2[digit - 1][i - (m1 - n2)] = n;
            else if (i >= m2 - n3)
                pg3[digit - 1][i - (m2 - n3)] = n;
            ++i;
        }
    }

    printf("First %d palindromic gapful numbers ending in:\n", n1);
    print(n1, pg1);

    printf("\nLast %d of first %d palindromic gapful numbers ending in:\n", n2, m1);
    print(n2, pg2);

    printf("\nLast %d of first %d palindromic gapful numbers ending in:\n", n3, m2);
    print(n3, pg3);

    return 0;
}
Task: Find prime n such that reversed n is also prime




Go: package main

import "fmt"

func sieve(limit int) []bool {
    limit++
    
    c := make([]bool, limit) 
    c[0] = true
    c[1] = true
    for i := 4; i < limit; i += 2 {
        c[i] = true
    }
    p := 3 
    for {
        p2 := p * p
        if p2 >= limit {
            break
        }
        for i := p2; i < limit; i += 2 * p {
            c[i] = true
        }
        for {
            p += 2
            if !c[p] {
                break
            }
        }
    }
    return c
}

func reversed(n int) int {
    rev := 0
    for n > 0 {
        rev = rev*10 + n%10
        n /= 10
    }
    return rev
}

func main() {
    c := sieve(999)
    reversedPrimes := []int{2}
    for i := 3; i < 500; i += 2 {
        if !c[i] && !c[reversed(i)] {
            reversedPrimes = append(reversedPrimes, i)
        }
    }
    fmt.Println("Primes under 500 which are also primes when the digits are reversed:")
    for i, p := range reversedPrimes {
        fmt.Printf("%5d", p)
        if (i+1) % 10 == 0 {
            fmt.Println()
        }
    }
    fmt.Printf("\n\n%d such primes found.\n", len(reversedPrimes))
}
Task: File size distribution




Go: package main

import (
    "fmt"
    "log"
    "math"
    "os"
    "path/filepath"
)

func commatize(n int64) string {
    s := fmt.Sprintf("%d", n)
    if n < 0 {
        s = s[1:]
    }
    le := len(s)
    for i := le - 3; i >= 1; i -= 3 {
        s = s[0:i] + "," + s[i:]
    }
    if n >= 0 {
        return s
    }
    return "-" + s
}

func fileSizeDistribution(root string) {
    var sizes [12]int
    files := 0
    directories := 0
    totalSize := int64(0)
    walkFunc := func(path string, info os.FileInfo, err error) error {
        if err != nil {
            return err
        }
        files++
        if info.IsDir() {
            directories++
        }
        size := info.Size()
        if size == 0 {
            sizes[0]++
            return nil
        }
        totalSize += size
        logSize := math.Log10(float64(size))
        index := int(math.Floor(logSize))
        sizes[index+1]++
        return nil
    }
    err := filepath.Walk(root, walkFunc)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("File size distribution for '%s' :-\n\n", root)
    for i := 0; i < len(sizes); i++ {
        if i == 0 {
            fmt.Print("  ")
        } else {
            fmt.Print("+ ")
        }
        fmt.Printf("Files less than 10 ^ %-2d bytes : %5d\n", i, sizes[i])
    }
    fmt.Println("                                  -----")
    fmt.Printf("= Total number of files         : %5d\n", files)
    fmt.Printf("  including directories         : %5d\n", directories)
    c := commatize(totalSize)
    fmt.Println("\n  Total size of files           :", c, "bytes")
}

func main() {
    fileSizeDistribution("./")
}
Task: Mutex




Go: package main

import (
    "fmt"
    "sync"
    "time"
)

var value int
var m sync.Mutex
var wg sync.WaitGroup

func slowInc() {
    m.Lock()
    v := value
    time.Sleep(1e8)
    value = v+1
    m.Unlock()
    wg.Done()
}

func main() {
    wg.Add(2)
    go slowInc()
    go slowInc()
    wg.Wait()
    fmt.Println(value)
}
Task: Pseudo-random numbers_PCG32




Go: package main

import (
    "fmt"
    "math"
)

const CONST = 6364136223846793005

type Pcg32 struct{ state, inc uint64 }

func Pcg32New() *Pcg32 { return &Pcg32{0x853c49e6748fea9b, 0xda3e39cb94b95bdb} }

func (pcg *Pcg32) seed(seedState, seedSequence uint64) {
    pcg.state = 0
    pcg.inc = (seedSequence << 1) | 1
    pcg.nextInt()
    pcg.state = pcg.state + seedState
    pcg.nextInt()
}

func (pcg *Pcg32) nextInt() uint32 {
    old := pcg.state
    pcg.state = old*CONST + pcg.inc
    pcgshifted := uint32(((old >> 18) ^ old) >> 27)
    rot := uint32(old >> 59)
    return (pcgshifted >> rot) | (pcgshifted << ((-rot) & 31))
}

func (pcg *Pcg32) nextFloat() float64 {
    return float64(pcg.nextInt()) / (1 << 32)
}

func main() {
    randomGen := Pcg32New()
    randomGen.seed(42, 54)
    for i := 0; i < 5; i++ {
        fmt.Println(randomGen.nextInt())
    }

    var counts [5]int
    randomGen.seed(987654321, 1)
    for i := 0; i < 1e5; i++ {
        j := int(math.Floor(randomGen.nextFloat() * 5))
        counts[j]++
    }
    fmt.Println("\nThe counts for 100,000 repetitions are:")
    for i := 0; i < 5; i++ {
        fmt.Printf("  %d : %d\n", i, counts[i])
    }
}
Task: Pseudo-random numbers_Xorshift star




Go: package main

import (
    "fmt"
    "math"
)

const CONST = 0x2545F4914F6CDD1D

type XorshiftStar struct{ state uint64 }

func XorshiftStarNew(state uint64) *XorshiftStar { return &XorshiftStar{state} }

func (xor *XorshiftStar) seed(state uint64) { xor.state = state }

func (xor *XorshiftStar) nextInt() uint32 {
    x := xor.state
    x = x ^ (x >> 12)
    x = x ^ (x << 25)
    x = x ^ (x >> 27)
    xor.state = x
    return uint32((x * CONST) >> 32)
}

func (xor *XorshiftStar) nextFloat() float64 {
    return float64(xor.nextInt()) / (1 << 32)
}

func main() {
    randomGen := XorshiftStarNew(1234567)
    for i := 0; i < 5; i++ {
        fmt.Println(randomGen.nextInt())
    }

    var counts [5]int
    randomGen.seed(987654321)
    for i := 0; i < 1e5; i++ {
        j := int(math.Floor(randomGen.nextFloat() * 5))
        counts[j]++
    }
    fmt.Println("\nThe counts for 100,000 repetitions are:")
    for i := 0; i < 5; i++ {
        fmt.Printf("  %d : %d\n", i, counts[i])
    }
}
Task: Changeable words




Go: package main

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

func hammingDist(s1, s2 string) int {
    r1 := []rune(s1) 
    r2 := []rune(s2) 
    if len(r1) != len(r2) {
        return 0
    }
    count := 0
    for i := 0; i < len(r1); i++ {
        if r1[i] != r2[i] {
            count++
            if count == 2 {
                break 
            }
        }
    }
    return count
}

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    var words []string
    for _, bword := range bwords {
        s := string(bword)
        if utf8.RuneCountInString(s) > 11 {
            words = append(words, s)
        }
    }
    count := 0
    fmt.Println("Changeable words in", wordList, "\b:")
    for _, word1 := range words {
        for _, word2 := range words {
            if word1 != word2 && hammingDist(word1, word2) == 1 {
                count++
                fmt.Printf("%2d: %-14s -> %s\n", count, word1, word2)
            }
        }
    }
}
Task: Exactly three adjacent 3 in lists




Go: package main

import "fmt"

func main() {
    lists := [][]int{
        {9, 3, 3, 3, 2, 1, 7, 8, 5},
        {5, 2, 9, 3, 3, 7, 8, 4, 1},
        {1, 4, 3, 6, 7, 3, 8, 3, 2},
        {1, 2, 3, 4, 5, 6, 7, 8, 9},
        {4, 6, 8, 7, 2, 3, 3, 3, 1},
        {3, 3, 3, 1, 2, 4, 5, 1, 3},
        {0, 3, 3, 3, 3, 7, 2, 2, 6},
        {3, 3, 3, 3, 3, 4, 4, 4, 4},
    }
    for d := 1; d <= 4; d++ {
        fmt.Printf("Exactly %d adjacent %d's:\n", d, d)
        for _, list := range lists {
            var indices []int
            for i, e := range list {
                if e == d {
                    indices = append(indices, i)
                }
            }
            adjacent := false
            if len(indices) == d {
                adjacent = true
                for i := 1; i < len(indices); i++ {
                    if indices[i]-indices[i-1] != 1 {
                        adjacent = false
                        break
                    }
                }
            }
            fmt.Printf("%v -> %t\n", list, adjacent)
        }
        fmt.Println()
    }
}
Task: Input_Output for lines of text




Go: package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
)

func main() {
	
	
	
	var lines int
	n, err := fmt.Scanln(&lines)
	if n != 1 || err != nil {
		log.Fatal(err)
	}

	
	
	
	
	
	
	
	
	
	
	
	
	
	

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanLines) 
	for ; scanner.Scan() && lines > 0; lines-- {
		doStuff(scanner.Text())
	}
	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
	
	if lines > 0 {
		log.Fatalln("early", io.EOF)
	}
}

func doStuff(line string) {
	fmt.Println(line)
}
Task: Length of an arc between two angles




Go: package main

import (
    "fmt"
    "math"
)

func arcLength(radius, angle1, angle2 float64) float64 {
    return (360 - math.Abs(angle2-angle1)) * math.Pi * radius / 180
}

func main() {
    fmt.Println(arcLength(10, 10, 120))
}
Task: Draw pixel 2




Go: package main

import (
    "fmt"
    "image"
    "image/color"
    "image/draw"
    "math/rand"
    "time"
)

func main() {
    rect := image.Rect(0, 0, 640, 480)
    img := image.NewRGBA(rect)

    
    blue := color.RGBA{0, 0, 255, 255}
    draw.Draw(img, rect, &image.Uniform{blue}, image.ZP, draw.Src)

    
    yellow := color.RGBA{255, 255, 0, 255}
    width := img.Bounds().Dx()
    height := img.Bounds().Dy()
    rand.Seed(time.Now().UnixNano())
    x := rand.Intn(width)
    y := rand.Intn(height)
    img.Set(x, y, yellow)

    
    cmap := map[color.Color]string{blue: "blue", yellow: "yellow"}
    for i := 0; i < width; i++ {
        for j := 0; j < height; j++ {
            c := img.At(i, j)
            if cmap[c] == "yellow" {
                fmt.Printf("The color of the pixel at (%d, %d) is yellow\n", i, j)
            }
        }
    }
}
Task: Function definition




Go: func multiply(a, b float64) float64 {
   return a * b
}
Task: Comments






PHP: # this is commented
Task: Periodic table






PHP: <?php


class PeriodicTable
{
    private $aArray = array(1, 2, 5, 13, 57, 72, 89, 104);
    
    private $bArray = array(-1, 15, 25, 35, 72, 21, 58, 7);
    
    public function rowAndColumn($n)
    {
        $i = 7;
        while ($this->aArray[$i] > $n)
            $i--;
        $m = $n + $this->bArray[$i];
        return array(floor($m / 18) + 1, $m % 18 + 1);
    }
}

$pt = new PeriodicTable();

foreach ([1, 2, 29, 42, 57, 58, 72, 89, 90, 103] as $n) {
    list($r, $c) = $pt->rowAndColumn($n);
    echo $n, " -> ", $r, " ", $c, PHP_EOL;
} 
?>
Task: Call a function





Java: foo();             
Int x = bar();
Task: Copy a string





Java: String src = "Hello";
String newAlias = src;
String strCopy = new String(src);
Task: Include a file





Java: public class Class1 extends Class2
{
	
}