WeixiangYan/CodeTransOcean huggingface dataset:
Task: Maximum triangle path sum

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

#define max(x,y)  ((x) > (y) ? (x) : (y))

int tri[] = {
        55,
	94, 48,
	95, 30, 96,
	77, 71, 26, 67,
	97, 13, 76, 38, 45,
	7, 36, 79, 16, 37, 68,
	48, 7, 9, 18, 70, 26, 6,
	18, 72, 79, 46, 59, 79, 29, 90,
	20, 76, 87, 11, 32, 7, 7, 49, 18,
	27, 83, 58, 35, 71, 11, 25, 57, 29, 85,
	14, 64, 36, 96, 27, 11, 58, 56, 92, 18, 55,
	2, 90, 3, 60, 48, 49, 41, 46, 33, 36, 47, 23,
	92, 50, 48, 2, 36, 59, 42, 79, 72, 20, 82, 77, 42,
	56, 78, 38, 80, 39, 75, 2, 71, 66, 66, 1, 3, 55, 72,
	44, 25, 67, 84, 71, 67, 11, 61, 40, 57, 58, 89, 40, 56, 36,
	85, 32, 25, 85, 57, 48, 84, 35, 47, 62, 17, 1, 1, 99, 89, 52,
	6, 71, 28, 75, 94, 48, 37, 10, 23, 51, 6, 48, 53, 18, 74, 98, 15,
	27, 2, 92, 23, 8, 71, 76, 84, 15, 52, 92, 63, 81, 10, 44, 10, 69, 93
};

int main(void)
{
    const int len  = sizeof(tri) / sizeof(tri[0]);
    const int base = (sqrt(8*len + 1) - 1) / 2;
    int step       = base - 1;
    int stepc      = 0;

    int i;
    for (i = len - base - 1; i >= 0; --i) {
        tri[i] += max(tri[i + step], tri[i + step + 1]);
        if (++stepc == step) {
            step--;
            stepc = 0;
        }
    }

    printf("%d\n", tri[0]);
    return 0;
}




Go: package main

import (
    "fmt"
    "strconv"
    "strings"
)

const t = `               55
                        94 48
                       95 30 96
                     77 71 26 67
                    97 13 76 38 45
                  07 36 79 16 37 68
                 48 07 09 18 70 26 06
               18 72 79 46 59 79 29 90
              20 76 87 11 32 07 07 49 18
            27 83 58 35 71 11 25 57 29 85
           14 64 36 96 27 11 58 56 92 18 55
         02 90 03 60 48 49 41 46 33 36 47 23
        92 50 48 02 36 59 42 79 72 20 82 77 42
      56 78 38 80 39 75 02 71 66 66 01 03 55 72
     44 25 67 84 71 67 11 61 40 57 58 89 40 56 36
   85 32 25 85 57 48 84 35 47 62 17 01 01 99 89 52
  06 71 28 75 94 48 37 10 23 51 06 48 53 18 74 98 15
27 02 92 23 08 71 76 84 15 52 92 63 81 10 44 10 69 93`

func main() {
    lines := strings.Split(t, "\n")
    f := strings.Fields(lines[len(lines)-1])
    d := make([]int, len(f))
    var err error
    for i, s := range f {
        if d[i], err = strconv.Atoi(s); err != nil {
            panic(err)
        }
    }
    d1 := d[1:]
    var l, r, u int
    for row := len(lines) - 2; row >= 0; row-- {
        l = d[0]
        for i, s := range strings.Fields(lines[row]) {
            if u, err = strconv.Atoi(s); err != nil {
                panic(err)
            }
            if r = d1[i]; l > r {
                d[i] = u + l
            } else {
                d[i] = u + r
            }
            l = r
        }
    }
    fmt.Println(d[0])
}
Task: Run as a daemon or service

C: #include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
	extern char *__progname;
	time_t clock;
	int fd;

	if (argc != 2) {
		fprintf(stderr, "usage: %s file\n", __progname);
		exit(1);
	}

	
	fd = open(argv[1], O_WRONLY | O_APPEND | O_CREAT, 0666);
	if (fd < 0)
		err(1, argv[1]);

	
	if (daemon(0, 0) < 0)
		err(1, "daemon");

	
	if (dup2(fd, STDOUT_FILENO) < 0) {
		syslog(LOG_ERR, "dup2: %s", strerror(errno));
		exit(1);
	}
	close(fd);

	
	for (;;) {
		time(&clock);
		fputs(ctime(&clock), stdout);
		if (fflush(stdout) == EOF) {
			syslog(LOG_ERR, "%s: %s", argv[1], strerror(errno));
			exit(1);
		}
		sleep(1);	
	}
}




Go: package main

import (
    "fmt"
    "github.com/sevlyar/go-daemon"
    "log"
    "os"
    "time"
)

func work() {
    f, err := os.Create("daemon_output.txt")
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()
    ticker := time.NewTicker(time.Second)
    go func() {
        for t := range ticker.C {
            fmt.Fprintln(f, t) 
        }
    }()
    time.Sleep(60 * time.Second) 
    ticker.Stop()
    log.Print("ticker stopped")
}

func main() {
    cntxt := &daemon.Context{
        PidFileName: "pid",
        PidFilePerm: 0644,
        LogFileName: "log",
        LogFilePerm: 0640,
        WorkDir:     "./",
        Umask:       027,
        Args:        []string{"[Rosetta Code daemon example]"},
    }

    d, err := cntxt.Reborn()
    if err != nil {
        log.Fatal("Unable to run: ", err)
    }
    if d != nil {
        return
    }
    defer cntxt.Release()

    log.Print("- - - - - - - - - - - - - - -")
    log.Print("daemon started")

    work()
}
Task: Coprime triplets

C: 


#include <stdio.h>

int Gcd(int v1, int v2)
{
	
	int a, b, r;
	if (v1 < v2)
	{
		a = v2;
		b = v1;
	}
	else
	{
		a = v1;
		b = v2;
	}
	do
	{
		r = a % b;
		if (r == 0)
		{
			break;
		}
		else
		{
			a = b;
			b = r;
		}
	} while (1 == 1);
	return b;
}

int NotInList(int num, int numtrip, int *tripletslist)
{
	
	for (int i = 0; i < numtrip; i++)
	{
		if (num == tripletslist[i])
		{
			return 0;
		}
	}
	return 1;
} 	

int main()
{
	int coprime[50];
	int gcd1, gcd2;
	int ntrip = 2;
	int n = 3;
	
	
	coprime[0] = 1;
	coprime[1] = 2;

	while ( n < 50)
	{
		gcd1 = Gcd(n, coprime[ntrip-1]);
		gcd2 = Gcd(n, coprime[ntrip-2]);
		
		if (gcd1 == 1 && gcd2 == 1 && NotInList(n, ntrip, coprime))
		{
			coprime[ntrip++] = n;
			
			n = 3;
		}
		else
		{
			
			n++;
		}
	}
	
	
	printf("\n");
	for (int i = 0; i < ntrip; i++)
	{
		printf("%2d ", coprime[i]);
		if ((i+1) % 10 == 0)
		{
			printf("\n");
		}
	}
	
	printf("\n\nNumber of elements in coprime triplets: %d\n\n", ntrip);
	
	return 0;
}




Go: package main

import (
    "fmt"
    "rcu"
)

func contains(a []int, v int) bool {
    for _, e := range a {
        if e == v {
            return true
        }
    }
    return false
}

func main() {
    const limit = 50
    cpt := []int{1, 2}
    for {
        m := 1
        l := len(cpt)
        for contains(cpt, m) || rcu.Gcd(m, cpt[l-1]) != 1 || rcu.Gcd(m, cpt[l-2]) != 1 {
            m++
        }
        if m >= limit {
            break
        }
        cpt = append(cpt, m)
    }
    fmt.Printf("Coprime triplets under %d:\n", limit)
    for i, t := range cpt {
        fmt.Printf("%2d ", t)
        if (i+1)%10 == 0 {
            fmt.Println()
        }
    }
    fmt.Printf("\n\nFound %d such numbers\n", len(cpt))
}
Task: Variable declaration reset

C: #include <stdio.h>

int main() {
    int i, gprev = 0;
    int s[7] = {1, 2, 2, 3, 4, 4, 5};

    
    for (i = 0; i < 7; ++i) {

        int curr = s[i];
        int prev = 0;

        if (i > 0 && curr == prev) printf("%d\n", i);
        prev = curr;
    }

    
    for (i = 0; i < 7; ++i) {
        int curr = s[i];
        if (i > 0 && curr == gprev) printf("%d\n", i);
        gprev = curr;
    }

    return 0;
}




Go: package main

import "fmt"

func main() {
    s := []int{1, 2, 2, 3, 4, 4, 5}

    
    
    for i := 0; i < len(s); i++ {
        curr := s[i]
        var prev int
        if i > 0 && curr == prev {
            fmt.Println(i)
        }
        prev = curr
    }

    
    
    var prev int
    for i := 0; i < len(s); i++ {
        curr := s[i]
        if i > 0 && curr == prev {
            fmt.Println(i)
        }
        prev = curr
    }
}
Task: SOAP

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

size_t write_data(void *ptr, size_t size, size_t nmeb, void *stream){
    return fwrite(ptr,size,nmeb,stream);
}

size_t read_data(void *ptr, size_t size, size_t nmeb, void *stream){
    return fread(ptr,size,nmeb,stream);
}

void callSOAP(char* URL, char * inFile, char * outFile) {

    FILE * rfp = fopen(inFile, "r");
    if(!rfp) 
        perror("Read File Open:");

    FILE * wfp = fopen(outFile, "w+");
    if(!wfp)
        perror("Write File Open:");

    struct curl_slist *header = NULL;
		header = curl_slist_append (header, "Content-Type:text/xml");
		header = curl_slist_append (header, "SOAPAction: rsc");
		header = curl_slist_append (header, "Transfer-Encoding: chunked");
		header = curl_slist_append (header, "Expect:");
    CURL *curl;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL, URL);
        curl_easy_setopt(curl, CURLOPT_POST, 1L);
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_data);
        curl_easy_setopt(curl, CURLOPT_READDATA, rfp); 
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, wfp);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)-1);
        curl_easy_setopt(curl, CURLOPT_VERBOSE,1L);            
        curl_easy_perform(curl);

        curl_easy_cleanup(curl);
    }
}

int main(int argC,char* argV[])
{
	if(argC!=4)
		printf("Usage : %s <URL of WSDL> <Input file path> <Output File Path>",argV[0]);
	else
		callSOAP(argV[1],argV[2],argV[3]);
	return 0;
}




Go: package main

import (
    "fmt"
    "github.com/tiaguinho/gosoap"
    "log"
)

type CheckVatResponse struct {
    CountryCode string `xml:"countryCode"`
    VatNumber   string `xml:"vatNumber"`
    RequestDate string `xml:"requestDate"`
    Valid       string `xml:"valid"`
    Name        string `xml:"name"`
    Address     string `xml:"address"`
}

var (
    rv CheckVatResponse
)

func check(err error) {
    if err != nil {
        log.Fatal(err)
    }
}

func main() {
    
    soap, err := gosoap.SoapClient("http:

    
    params := gosoap.Params{
        "vatNumber":   "6388047V",
        "countryCode": "IE",
    }

    
    err = soap.Call("checkVat", params)
    check(err)

    
    err = soap.Unmarshal(&rv)
    check(err)

    
    fmt.Println("Country Code  : ", rv.CountryCode)
    fmt.Println("Vat Number    : ", rv.VatNumber)
    fmt.Println("Request Date  : ", rv.RequestDate)
    fmt.Println("Valid         : ", rv.Valid)
    fmt.Println("Name          : ", rv.Name)
    fmt.Println("Address       : ", rv.Address)
}
Task: Pragmatic directives

C: 
#include<stdio.h> 


#define Hi printf("Hi There.");



#define start int main(){
#define end return 0;}

start

Hi


#warning "Don't you have anything better to do ?"

#ifdef __unix__
#warning "What are you doing still working on Unix ?"
printf("\nThis is an Unix system.");
#elif _WIN32
#warning "You couldn't afford a 64 bit ?"
printf("\nThis is a 32 bit Windows system.");
#elif _WIN64
#warning "You couldn't afford an Apple ?"
printf("\nThis is a 64 bit Windows system.");
#endif

end
Task: Numbers with equal rises and falls

C: #include <stdio.h>


int riseEqFall(int num) {
    int rdigit = num % 10;
    int netHeight = 0;
    while (num /= 10) {
        netHeight += ((num % 10) > rdigit) - ((num % 10) < rdigit);
        rdigit = num % 10;
    }
    return netHeight == 0;
}


int nextNum() {
    static int num = 0;
    do {num++;} while (!riseEqFall(num));
    return num;
}

int main(void) {
    int total, num;
    
    
    printf("The first 200 numbers are: \n");
    for (total = 0; total < 200; total++)
        printf("%d ", nextNum());
    
    
    printf("\n\nThe 10,000,000th number is: ");
    for (; total < 10000000; total++) num = nextNum();
    printf("%d\n", num);
    
    return 0;
}




Go: package main

import "fmt"

func risesEqualsFalls(n int) bool {
    if n < 10 {
        return true
    }
    rises := 0
    falls := 0
    prev := -1
    for n > 0 {
        d := n % 10
        if prev >= 0 {
            if d < prev {
                rises = rises + 1
            } else if d > prev {
                falls = falls + 1
            }
        }
        prev = d
        n /= 10   
    }
    return rises == falls
}

func main() {
    fmt.Println("The first 200 numbers in the sequence are:")
    count := 0
    n := 1
    for {
        if risesEqualsFalls(n) {
            count++
            if count <= 200 {
                fmt.Printf("%3d ", n)
                if count%20 == 0 {
                    fmt.Println()
                }
            }
            if count == 1e7 {
                fmt.Println("\nThe 10 millionth number in the sequence is ", n)
                break
            }
        }
        n++
    }
}
Task: Terminal control_Cursor movement

C: #include<conio.h>
#include<dos.h>

char *strings[] = {"The cursor will move one position to the left", 
  		   "The cursor will move one position to the right",
 		   "The cursor will move vetically up one line", 
 		   "The cursor will move vertically down one line", 
 		   "The cursor will move to the beginning of the line", 
 		   "The cursor will move to the end of the line", 
 		   "The cursor will move to the top left corner of the screen", 
 		   "The cursor will move to the bottom right corner of the screen"};
 		             
int main()
{
	int i,j,MAXROW,MAXCOL;
	struct text_info tInfo;
	gettextinfo(&tInfo);
	MAXROW = tInfo.screenheight;
	MAXCOL = tInfo.screenwidth;
	
	clrscr();
	cprintf("This is a demonstration of cursor control using gotoxy(). Press any key to continue.");
	getch();
	
	for(i=0;i<8;i++)
	{
		clrscr();
		gotoxy(5,MAXROW/2);
		
		cprintf("%s",strings[i]);
		getch();
		
		switch(i){
			case 0:gotoxy(wherex()-1,wherey());
			break;
			case 1:gotoxy(wherex()+1,wherey());
			break;
			case 2:gotoxy(wherex(),wherey()-1);
			break;
			case 3:gotoxy(wherex(),wherey()+1);
			break;
			case 4:for(j=0;j<strlen(strings[i]);j++){
				   gotoxy(wherex()-1,wherey());
				   delay(100);
			       }
			break;
			case 5:gotoxy(wherex()-strlen(strings[i]),wherey());
			       for(j=0;j<strlen(strings[i]);j++){
				   gotoxy(wherex()+1,wherey());
				   delay(100);
			       }
			break;
			case 6:while(wherex()!=1)
			       {
				     gotoxy(wherex()-1,wherey());
				     delay(100);
		               }
			       while(wherey()!=1)
			       {
			             gotoxy(wherex(),wherey()-1);
			             delay(100);
			       }
			break;
			case 7:while(wherex()!=MAXCOL)
			       {
				     gotoxy(wherex()+1,wherey());
				     delay(100);
			       }
			       while(wherey()!=MAXROW)
			       {
				     gotoxy(wherex(),wherey()+1);
				     delay(100);
			       }
			break;
			};
			getch();
	}
	
	clrscr();
	cprintf("End of demonstration.");
	getch();
	return 0;
}




Go: package main

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

func main() {
    tput("clear") 
    tput("cup", "6", "3") 
    time.Sleep(1 * time.Second)
    tput("cub1") 
    time.Sleep(1 * time.Second)
    tput("cuf1") 
    time.Sleep(1 * time.Second)
    tput("cuu1") 
    time.Sleep(1 * time.Second)
    
    tput("cud", "1") 
    time.Sleep(1 * time.Second)
    tput("cr") 
    time.Sleep(1 * time.Second)
    
    var h, w int
    cmd := exec.Command("stty", "size")
    cmd.Stdin = os.Stdin
    d, _ := cmd.Output()
    fmt.Sscan(string(d), &h, &w)
    
    tput("hpa", strconv.Itoa(w-1))
    time.Sleep(2 * time.Second)
    
    tput("home")
    time.Sleep(2 * time.Second)
    
    tput("cup", strconv.Itoa(h-1), strconv.Itoa(w-1))
    time.Sleep(3 * time.Second)
}

func tput(args ...string) error {
    cmd := exec.Command("tput", args...)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}
Task: Start from a main routine

C: #include<stdio.h>

#define start main()

int start
{
	printf("Hello World !");
	return 0;
}




Go: package main

import "fmt"

var count = 0

func foo() {
    fmt.Println("foo called")
}

func init() {
    fmt.Println("first init called")
    foo()
}

func init() {
    fmt.Println("second init called")
    main()
}

func main() {
    count++
    fmt.Println("main called when count is", count)
}
Task: Summation of primes

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

int isprime( int p ) {
    int i;
    if(p==2) return 1;
    if(!(p%2)) return 0;
    for(i=3; i*i<=p; i+=2) {
       if(!(p%i)) return 0;
    }
    return 1;
}

int main( void ) {
    int p;
    long int s = 2;
    for(p=3;p<2000000;p+=2) {
        if(isprime(p)) s+=p;
    }
    printf( "%ld\n", s );
    return 0;
}




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    sum := 0
    for _, p := range rcu.Primes(2e6 - 1) {
        sum += p
    }
    fmt.Printf("The sum of all primes below 2 million is %s.\n", rcu.Commatize(sum))
}
Task: Koch curve

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

#define pi M_PI

typedef struct{
	double x,y;
}point;

void kochCurve(point p1,point p2,int times){
	point p3,p4,p5;
	double theta = pi/3;
	
	if(times>0){
		p3 = (point){(2*p1.x+p2.x)/3,(2*p1.y+p2.y)/3};
		p5 = (point){(2*p2.x+p1.x)/3,(2*p2.y+p1.y)/3};
		
		p4 = (point){p3.x + (p5.x - p3.x)*cos(theta) + (p5.y - p3.y)*sin(theta),p3.y - (p5.x - p3.x)*sin(theta) + (p5.y - p3.y)*cos(theta)};
		
		kochCurve(p1,p3,times-1);
		kochCurve(p3,p4,times-1);
		kochCurve(p4,p5,times-1);
		kochCurve(p5,p2,times-1);
	}
	
	else{
		line(p1.x,p1.y,p2.x,p2.y);
	}
}

int main(int argC, char** argV)
{
	int w,h,r;
	point p1,p2;
	
	if(argC!=4){
		printf("Usage : %s <window width> <window height> <recursion level>",argV[0]);
	}
	
	else{
		w = atoi(argV[1]);
		h = atoi(argV[2]);
		r = atoi(argV[3]);
		
		initwindow(w,h,"Koch Curve");
		
		p1 = (point){10,h-10};
		p2 = (point){w-10,h-10};
		
		kochCurve(p1,p2,r);
		
		getch();
	
		closegraph();
	}
	
	return 0;
}




Go: package main

import (
    "github.com/fogleman/gg"
    "math"
)

var dc = gg.NewContext(512, 512)

func koch(x1, y1, x2, y2 float64, iter int) {
    angle := math.Pi / 3 
    x3 := (x1*2 + x2) / 3
    y3 := (y1*2 + y2) / 3
    x4 := (x1 + x2*2) / 3
    y4 := (y1 + y2*2) / 3
    x5 := x3 + (x4-x3)*math.Cos(angle) + (y4-y3)*math.Sin(angle)
    y5 := y3 - (x4-x3)*math.Sin(angle) + (y4-y3)*math.Cos(angle)
    if iter > 0 {
        iter--
        koch(x1, y1, x3, y3, iter)
        koch(x3, y3, x5, y5, iter)
        koch(x5, y5, x4, y4, iter)
        koch(x4, y4, x2, y2, iter)
    } else {
        dc.LineTo(x1, y1)
        dc.LineTo(x3, y3)
        dc.LineTo(x5, y5)
        dc.LineTo(x4, y4)
        dc.LineTo(x2, y2)
    }
}

func main() {
    dc.SetRGB(1, 1, 1) 
    dc.Clear()
    koch(100, 100, 400, 400, 4)
    dc.SetRGB(0, 0, 1) 
    dc.SetLineWidth(2)
    dc.Stroke()
    dc.SavePNG("koch.png")
}
Task: Draw pixel 2

C: #include<graphics.h>
#include<stdlib.h>
#include<time.h>

int main()
{
	srand(time(NULL));
	
	initwindow(640,480,"Yellow Random Pixel");
	
	putpixel(rand()%640,rand()%480,YELLOW);
	
	getch();
	
	return 0;
}




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: Count how many vowels and consonants occur in a string

C: 

#include <stdio.h>

char vowels[] = {'a','e','i','o','u','\n'};

int len(char * str) {
	int i = 0;
	while (str[i] != '\n') i++;
	return i;
}

int  isvowel(char c){
	int b = 0;
	int v = len(vowels);
	for(int i = 0; i < v;i++) {
		if(c == vowels[i]) {
			b = 1;
			break; 
		}
	}
	return b;
}

int isletter(char c){
	return ((c >= 'a') && (c <= 'z') || (c >= 'A') && (c <= 'Z'));
}

int isconsonant(char c){
	return isletter(c) && !isvowel(c);
}

int cVowels(char * str) {
	int i = 0;
	int count = 0;
	while (str[i] != '\n') {
		if (isvowel(str[i])) {
			count++;;
		}
		i++;
	}
	return count;
}

int cConsonants(char * str ) {
	int i = 0;
	int count = 0;
	while (str[i] != '\n') {
		if (isconsonant(str[i])) {
			count++;
		}
		i++;
	}
	return count;
}

int main() {

	char buff[] = "This is 1 string\n";
	printf("%4d, %4d, %4d, %s\n", cVowels(buff), cConsonants(buff), len(buff), buff);

	char buff2[] = "This is a second string\n";
	printf("%4d, %4d, %4d, %s\n", cVowels(buff2), cConsonants(buff2), len(buff2),  buff2);


	printf("a: %d\n", isvowel('a'));
	printf("b: %d\n", isvowel('b'));
	printf("Z: %d\n", isconsonant('Z'));
	printf("1: %d\n", isletter('1'));
}




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))
    }
}
Task: Draw a pixel

C: #include<graphics.h>

int main()
{
	initwindow(320,240,"Red Pixel");
	
	putpixel(100,100,RED);
	
	getch();
	
	return 0;
}




Go: package main

import (
    "fmt"
    "image"
    "image/color"
    "image/draw"
)

func main() {
    rect := image.Rect(0, 0, 320, 240)
    img := image.NewRGBA(rect)

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

    
    red := color.RGBA{255, 0, 0, 255}
    img.Set(100, 100, red)

    
    cmap := map[color.Color]string{green: "green", red: "red"}
    c1 := img.At(0, 0)
    c2 := img.At(100, 100)
    fmt.Println("The color of the pixel at (  0,   0) is", cmap[c1], "\b.")
    fmt.Println("The color of the pixel at (100, 100) is", cmap[c2], "\b.")
}
Task: Numbers whose binary and ternary digit sums are prime

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


uint8_t prime(uint8_t n) {
    uint8_t f;
    if (n < 2) return 0;
    for (f = 2; f < n; f++) {
        if (n % f == 0) return 0;
    }
    return 1;
}


uint8_t digit_sum(uint8_t n, uint8_t base) {
    uint8_t s = 0;
    do {s += n % base;} while (n /= base);
    return s;
}

int main() {
    uint8_t n, s = 0;
    for (n = 0; n < 200; n++) {
        if (prime(digit_sum(n,2)) && prime(digit_sum(n,3))) {
            printf("%4d",n);
            if (++s>=10) {
                printf("\n");
                s=0;
            }
        }
    }
    printf("\n");
    return 0;
}




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    var numbers []int
    for i := 2; i < 200; i++ {
        bds := rcu.DigitSum(i, 2)
        if rcu.IsPrime(bds) {
            tds := rcu.DigitSum(i, 3)
            if rcu.IsPrime(tds) {
                numbers = append(numbers, i)
            }
        }
    }
    fmt.Println("Numbers < 200 whose binary and ternary digit sums are prime:")
    for i, n := range numbers {
        fmt.Printf("%4d", n)
        if (i+1)%14 == 0 {
            fmt.Println()
        }
    }
    fmt.Printf("\n\n%d such numbers found\n", len(numbers))
}