WeixiangYan/CodeTransOcean huggingface dataset:
Task: Common list elements




Go: package main

import "fmt"

func indexOf(l []int, n int) int {
    for i := 0; i < len(l); i++ {
        if l[i] == n {
            return i
        }
    }
    return -1
}

func common2(l1, l2 []int) []int {
    
    c1, c2 := len(l1), len(l2)
    shortest, longest := l1, l2
    if c1 > c2 {
        shortest, longest = l2, l1
    }
    longest2 := make([]int, len(longest))
    copy(longest2, longest) 
    var res []int
    for _, e := range shortest {
        ix := indexOf(longest2, e)
        if ix >= 0 {
            res = append(res, e)
            longest2 = append(longest2[:ix], longest2[ix+1:]...)
        }
    }
    return res
}

func commonN(ll [][]int) []int {
    n := len(ll)
    if n == 0 {
        return []int{}
    }
    if n == 1 {
        return ll[0]
    }
    res := common2(ll[0], ll[1])
    if n == 2 {
        return res
    }
    for _, l := range ll[2:] {
        res = common2(res, l)
    }
    return res
}

func main() {
    lls := [][][]int{
        {{2, 5, 1, 3, 8, 9, 4, 6}, {3, 5, 6, 2, 9, 8, 4}, {1, 3, 7, 6, 9}},
        {{2, 2, 1, 3, 8, 9, 4, 6}, {3, 5, 6, 2, 2, 2, 4}, {2, 3, 7, 6, 2}},
    }
    for _, ll := range lls {
        fmt.Println("Intersection of", ll, "is:")
        fmt.Println(commonN(ll))
        fmt.Println()
    }
}
Task: Bioinformatics_Subsequence




Go: package main

import (
    "fmt"
    "math/rand"
    "regexp"
    "time"
)

const base = "ACGT"

func findDnaSubsequence(dnaSize, chunkSize int) {
    dnaSeq := make([]byte, dnaSize)
    for i := 0; i < dnaSize; i++ {
        dnaSeq[i] = base[rand.Intn(4)]
    }
    dnaStr := string(dnaSeq)
    dnaSubseq := make([]byte, 4)
    for i := 0; i < 4; i++ {
        dnaSubseq[i] = base[rand.Intn(4)]
    }
    dnaSubstr := string(dnaSubseq)
    fmt.Println("DNA sequnence:")
    for i := chunkSize; i <= len(dnaStr); i += chunkSize {
        start := i - chunkSize
        fmt.Printf("%3d..%3d: %s\n", start+1, i, dnaStr[start:i])
    }
    fmt.Println("\nSubsequence to locate:", dnaSubstr)
    var r = regexp.MustCompile(dnaSubstr)
    var matches = r.FindAllStringIndex(dnaStr, -1)
    if len(matches) == 0 {
        fmt.Println("No matches found.")
    } else {
        fmt.Println("Matches found at the following indices:")
        for _, m := range matches {
            fmt.Printf("%3d..%-3d\n", m[0]+1, m[1])
        }
    }
}

func main() {
    rand.Seed(time.Now().UnixNano())
    findDnaSubsequence(200, 20)
    fmt.Println()
    findDnaSubsequence(600, 40)
}
Task: Sattolo cycle




Go: package main

import (
	"math/rand"
	"fmt"
)

func main() {
	list := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
	for i := 1; i <= 10; i++ {
		sattoloCycle(list)
		fmt.Println(list)
	}
}

func sattoloCycle(list []int) {
	for x := len(list) -1; x > 0; x-- {
		j := rand.Intn(x)
		list[x], list[j] = list[j], list[x]
	}
}
Task: Pinstripe_Printer

C: 

#include <stdlib.h>
#include <string.h>
#include "dome.h"

static DOME_API_v0* core;
static WREN_API_v0* wren;

static const char* source =  ""
"class Printer {\n" 
  "foreign static printFile(name) \n"
"} \n";

void C_printFile(WrenVM* vm) {
    const char *arg = wren->getSlotString(vm, 1);
    char command[strlen(arg) + 4];
    strcpy(command, "lp ");
    strcat(command, arg);
    int res = system(command);
}

DOME_EXPORT DOME_Result PLUGIN_onInit(DOME_getAPIFunction DOME_getAPI, DOME_Context ctx) {
    core = DOME_getAPI(API_DOME, DOME_API_VERSION);
    wren = DOME_getAPI(API_WREN, WREN_API_VERSION);
    core->registerModule(ctx, "printer", source);
    core->registerClass(ctx, "printer", "Printer", NULL, NULL);
    core->registerFn(ctx, "printer", "static Printer.printFile(_)", C_printFile);
    return DOME_RESULT_SUCCESS;
}

DOME_EXPORT DOME_Result PLUGIN_preUpdate(DOME_Context ctx) {
    return DOME_RESULT_SUCCESS;
}

DOME_EXPORT DOME_Result PLUGIN_postUpdate(DOME_Context ctx) {
    return DOME_RESULT_SUCCESS;
}

DOME_EXPORT DOME_Result PLUGIN_preDraw(DOME_Context ctx) {
    return DOME_RESULT_SUCCESS;
}

DOME_EXPORT DOME_Result PLUGIN_postDraw(DOME_Context ctx) {
    return DOME_RESULT_SUCCESS;
}

DOME_EXPORT DOME_Result PLUGIN_onShutdown(DOME_Context ctx) {
    return DOME_RESULT_SUCCESS;
}
Task: File size distribution

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

#define MAXORDER 25

int main(int argC, char* argV[])
{
	char str[MAXORDER],commandString[1000],*startPath;
	long int* fileSizeLog = (long int*)calloc(sizeof(long int),MAXORDER),max;
	int i,j,len;
	double scale;
	FILE* fp;

	if(argC==1)
		printf("Usage : %s <followed by directory to start search from(. for current dir), followed by \n optional parameters (T or G) to show text or graph output>",argV[0]);
	else{
		if(strchr(argV[1],' ')!=NULL){
		len = strlen(argV[1]);
		startPath = (char*)malloc((len+2)*sizeof(char));
		startPath[0] = '\"';
		startPath[len+1]='\"';
		strncpy(startPath+1,argV[1],len);
		startPath[len+2] = argV[1][len];
		sprintf(commandString,"forfiles /p %s /s /c \"cmd /c echo @fsize\" 2>&1",startPath);
	}

	else if(strlen(argV[1])==1 && argV[1][0]=='.')
		strcpy(commandString,"forfiles /s /c \"cmd /c echo @fsize\" 2>&1");

	else
		sprintf(commandString,"forfiles /p %s /s /c \"cmd /c echo @fsize\" 2>&1",argV[1]);

	fp = popen(commandString,"r");

	while(fgets(str,100,fp)!=NULL){
			if(str[0]=='0')
				fileSizeLog[0]++;
			else
				fileSizeLog[strlen(str)]++;
	}

	if(argC==2 || (argC==3 && (argV[2][0]=='t'||argV[2][0]=='T'))){
		for(i=0;i<MAXORDER;i++){
			printf("\nSize Order < 10^%2d bytes : %Ld",i,fileSizeLog[i]);
		}
	}

	else if(argC==3 && (argV[2][0]=='g'||argV[2][0]=='G')){
		CONSOLE_SCREEN_BUFFER_INFO csbi;
		int val = GetConsoleScreenBufferInfo(GetStdHandle( STD_OUTPUT_HANDLE ),&csbi);
		if(val)
		{

				max = fileSizeLog[0];

				for(i=1;i<MAXORDER;i++)
					(fileSizeLog[i]>max)?max=fileSizeLog[i]:max;

				(max < csbi.dwSize.X)?(scale=1):(scale=(1.0*(csbi.dwSize.X-50))/max);

				for(i=0;i<MAXORDER;i++){
					printf("\nSize Order < 10^%2d bytes |",i);
					for(j=0;j<(int)(scale*fileSizeLog[i]);j++)
						printf("%c",219);
					printf("%Ld",fileSizeLog[i]);
				}
		}

	}
	return 0;
	}
}
Task: Aspect oriented programming

C: #define MY_NEW_FEATURE_ENABLED

...

#ifdef MY_NEW_FEATURE_ENABLED
  my_new_feature();
#endif

...

#ifdef MY_NEW_FEATURE_ENABLED
  close_my_new_feature();
#endif
Task: Speech synthesis

C: #include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void talk(const char *s)
{
	pid_t pid;
	int status;

	pid = fork();
	if (pid < 0) {
		perror("fork");
		exit(1);
	}

	if (pid == 0) {
		execlp("espeak", "espeak", s, (void*)0);
		perror("espeak");
		_exit(1);
	}

	waitpid(pid, &status, 0);
	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
		exit(1);
}

int main()
{
	talk("This is an example of speech synthesis.");
	return 0;
}
Task: Audio overlap loop

C: #include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include "wren.h"

void C_getInput(WrenVM* vm) {
    int maxSize = (int)wrenGetSlotDouble(vm, 1) + 2;
    char input[maxSize];
    fgets(input, maxSize, stdin);
    __fpurge(stdin);
    input[strcspn(input, "\n")] = 0;
    wrenSetSlotString(vm, 0, (const char*)input);
}

void C_play(WrenVM* vm) {
    const char *args = wrenGetSlotString(vm, 1);
    char command[strlen(args) + 5];
    strcpy(command, "play ");
    strcat(command, args);
    system(command);
}

WrenForeignMethodFn bindForeignMethod(
    WrenVM* vm,
    const char* module,
    const char* className,
    bool isStatic,
    const char* signature) {
    if (strcmp(module, "main") == 0) {
        if (strcmp(className, "C") == 0) {
            if (isStatic && strcmp(signature, "getInput(_)") == 0) return C_getInput;
            if (isStatic && strcmp(signature, "play(_)") == 0) return C_play;
        }
    }
    return NULL;
}

static void writeFn(WrenVM* vm, const char* text) {
    printf("%s", text);
}

void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
    switch (errorType) {
        case WREN_ERROR_COMPILE:
            printf("[%s line %d] [Error] %s\n", module, line, msg);
            break;
        case WREN_ERROR_STACK_TRACE:
            printf("[%s line %d] in %s\n", module, line, msg);
            break;
        case WREN_ERROR_RUNTIME:
            printf("[Runtime Error] %s\n", msg);
            break;
    }
}

char *readFile(const char *fileName) {
    FILE *f = fopen(fileName, "r");
    fseek(f, 0, SEEK_END);
    long fsize = ftell(f);
    rewind(f);
    char *script = malloc(fsize + 1);
    fread(script, 1, fsize, f);
    fclose(f);
    script[fsize] = 0;
    return script;
}

int main(int argc, char **argv) {
    WrenConfiguration config;
    wrenInitConfiguration(&config);
    config.writeFn = &writeFn;
    config.errorFn = &errorFn;
    config.bindForeignMethodFn = &bindForeignMethod;
    WrenVM* vm = wrenNewVM(&config);
    const char* module = "main";
    const char* fileName = "audio_overlap_loop.wren";
    char *script = readFile(fileName);
    WrenInterpretResult result = wrenInterpret(vm, module, script);
    switch (result) {
        case WREN_RESULT_COMPILE_ERROR:
            printf("Compile Error!\n");
            break;
        case WREN_RESULT_RUNTIME_ERROR:
            printf("Runtime Error!\n");
            break;
        case WREN_RESULT_SUCCESS:
            break;
    }
    wrenFreeVM(vm);
    free(script);
    return 0;
}
Task: Addition-chain exponentiation

C: #include <stdio.h>

#include "achain.c" 


typedef struct {double u, v;} cplx;

inline cplx c_mul(cplx a, cplx b)
{
	cplx c;
	c.u = a.u * b.u - a.v * b.v;
	c.v = a.u * b.v + a.v * b.u;
	return c;
}

cplx chain_expo(cplx x, int n)
{
	int i, j, k, l, e[32];
	cplx v[32];

	l = seq(n, 0, e);

	puts("Exponents:");
	for (i = 0; i <= l; i++)
		printf("%d%c", e[i], i == l ? '\n' : ' ');

	v[0] = x; v[1] = c_mul(x, x);
	for (i = 2; i <= l; i++) {
		for (j = i - 1; j; j--) {
			for (k = j; k >= 0; k--) {
				if (e[k] + e[j] < e[i]) break;
				if (e[k] + e[j] > e[i]) continue;
				v[i] = c_mul(v[j], v[k]);
				j = 1;
				break;
			}
		}
	}
	printf("(%f + i%f)^%d = %f + i%f\n",
		x.u, x.v, n, v[l].u, v[l].v);

	return x;
}

int bin_len(int n)
{
	int r, o;
	for (r = o = -1; n; n >>= 1, r++)
		if (n & 1) o++;
	return r + o;
}

int main()
{
	cplx	r1 = {1.0000254989, 0.0000577896},
		r2 = {1.0000220632, 0.0000500026};
	int n1 = 27182, n2 = 31415, i;

	init();
	puts("Precompute chain lengths");
	seq_len(n2);

	chain_expo(r1, n1);
	chain_expo(r2, n2);
	puts("\nchain lengths: shortest binary");
	printf("%14d %7d %7d\n", n1, seq_len(n1), bin_len(n1));
	printf("%14d %7d %7d\n", n2, seq_len(n2), bin_len(n2));
	for (i = 1; i < 100; i++)
		printf("%14d %7d %7d\n", i, seq_len(i), bin_len(i));
	return 0;
}
Task: Audio frequency generator

C: #include <stdio.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <string.h>
#include "wren.h"

void C_getInput(WrenVM* vm) {
    int maxSize = (int)wrenGetSlotDouble(vm, 1) + 2;
    char input[maxSize];
    fgets(input, maxSize, stdin);
    __fpurge(stdin);
    input[strcspn(input, "\n")] = 0;
    wrenSetSlotString(vm, 0, (const char*)input);
}

void C_play(WrenVM* vm) {
    const char *args = wrenGetSlotString(vm, 1);
    char command[strlen(args) + 5];
    strcpy(command, "play ");
    strcat(command, args);
    system(command);
}

WrenForeignMethodFn bindForeignMethod(
    WrenVM* vm,
    const char* module,
    const char* className,
    bool isStatic,
    const char* signature) {
    if (strcmp(module, "main") == 0) {
        if (strcmp(className, "C") == 0) {
            if (isStatic && strcmp(signature, "getInput(_)") == 0) return C_getInput;
            if (isStatic && strcmp(signature, "play(_)") == 0) return C_play;
        }
    }
    return NULL;
}

static void writeFn(WrenVM* vm, const char* text) {
    printf("%s", text);
}

void errorFn(WrenVM* vm, WrenErrorType errorType, const char* module, const int line, const char* msg) {
    switch (errorType) {
        case WREN_ERROR_COMPILE:
            printf("[%s line %d] [Error] %s\n", module, line, msg);
            break;
        case WREN_ERROR_STACK_TRACE:
            printf("[%s line %d] in %s\n", module, line, msg);
            break;
        case WREN_ERROR_RUNTIME:
            printf("[Runtime Error] %s\n", msg);
            break;
    }
}

char *readFile(const char *fileName) {
    FILE *f = fopen(fileName, "r");
    fseek(f, 0, SEEK_END);
    long fsize = ftell(f);
    rewind(f);
    char *script = malloc(fsize + 1);
    fread(script, 1, fsize, f);
    fclose(f);
    script[fsize] = 0;
    return script;
}

int main(int argc, char **argv) {
    WrenConfiguration config;
    wrenInitConfiguration(&config);
    config.writeFn = &writeFn;
    config.errorFn = &errorFn;
    config.bindForeignMethodFn = &bindForeignMethod;
    WrenVM* vm = wrenNewVM(&config);
    const char* module = "main";
    const char* fileName = "audio_frequency_generator.wren";
    char *script = readFile(fileName);
    WrenInterpretResult result = wrenInterpret(vm, module, script);
    switch (result) {
        case WREN_RESULT_COMPILE_ERROR:
            printf("Compile Error!\n");
            break;
        case WREN_RESULT_RUNTIME_ERROR:
            printf("Runtime Error!\n");
            break;
        case WREN_RESULT_SUCCESS:
            break;
    }
    wrenFreeVM(vm);
    free(script);
    return 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);	
	}
}
Task: IPC via named pipe

C: #include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <limits.h>
#include <pthread.h>



#define WILL_BLOCK_EVERYTHING	0

#if WILL_BLOCK_EVERYTHING
#include <poll.h>
#endif

size_t tally = 0;

void* write_loop(void *a)
{
	int fd;
	char buf[32];
	while (1) {
#if WILL_BLOCK_EVERYTHING
		
		fd = open("out", O_WRONLY|O_NONBLOCK);
		if (fd < 0) { 
			usleep(200000);
			continue;
		}
#else
		
		fd = open("out", O_WRONLY);
#endif
		write(fd, buf, snprintf(buf, 32, "%d\n", tally));
		close(fd);

		
		usleep(10000);
	}
}

void read_loop()
{
	int fd;
	size_t len;
	char buf[PIPE_BUF];
#if WILL_BLOCK_EVERYTHING
	struct pollfd pfd;
	pfd.events = POLLIN;
#endif
	while (1) {
#if WILL_BLOCK_EVERYTHING
		fd = pfd.fd = open("in", O_RDONLY|O_NONBLOCK);
		fcntl(fd, F_SETFL, 0);  
		poll(&pfd, 1, INFTIM);  
#else
		fd = open("in", O_RDONLY);
#endif
		while ((len = read(fd, buf, PIPE_BUF)) > 0) tally += len;
		close(fd);
	}
}

int main()
{
	pthread_t pid;

	
	mkfifo("in", 0666);
	mkfifo("out", 0666);

	
	pthread_create(&pid, 0, write_loop, 0);
	read_loop();

	return 0;
}
Task: OpenGL pixel shader

C: #include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glut.h>

GLuint ps, vs, prog, r_mod;
float angle = 0;
void render(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glUniform1f(r_mod, rand() / (float)RAND_MAX);

	glLoadIdentity();
	glRotatef(angle, angle * .1, 1, 0);
	glBegin(GL_TRIANGLES);
		glVertex3f(-1, -.5, 0);
		glVertex3f(0, 1, 0);
		glVertex3f(1, 0, 0);
	glEnd();
	angle += .02;
	glutSwapBuffers();
}

void set_shader()
{
	const char *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);"
		"}";
	const char *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;"
		"}";

	vs = glCreateShader(GL_VERTEX_SHADER);
	ps = glCreateShader(GL_FRAGMENT_SHADER);
	glShaderSource(ps, 1, &f, 0);
	glShaderSource(vs, 1, &v, 0);

	glCompileShader(vs);
	glCompileShader(ps);

	prog = glCreateProgram();
	glAttachShader(prog, ps);
	glAttachShader(prog, vs);

	glLinkProgram(prog);
	glUseProgram(prog);
	r_mod = glGetUniformLocation(prog, "r_mod");
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(200, 200);
	glutCreateWindow("Stuff");
	glutIdleFunc(render);

	glewInit();
	if (!glewIsSupported("GL_VERSION_2_0")) {
		fprintf(stderr, "GL 2.0 unsupported\n");
		return 1;
	}

	set_shader();
	glutMainLoop();

	return 0;
}
Task: Digit fifth powers

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

int sum5( int n ) {
    if(n<10) return pow(n,5);
    return pow(n%10,5) + sum5(n/10);
}

int main(void) {
    int i, sum = 0;
    for(i=2;i<=999999;i++) {
        if(i==sum5(i)) {
            printf( "%d\n", i );
            sum+=i;
        }
    }
    printf( "Total is %d\n", sum );
    return 0;
}
Task: Execute Brain____

C: #include <stdio.h>
int main(){
     int ptr=0, i=0, cell[7];
     for( i=0; i<7; ++i) cell[i]=0;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 8;
     while(cell[ptr])
     {
          ptr-= 1;
          if(ptr<0) perror("Program pointer underflow");
          cell[ptr]+= 9;
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
          cell[ptr]-= 1;
     }
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 2;
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     while(cell[ptr])
     {
          cell[ptr]-= 1;
     }
     cell[ptr]+= 1;
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     while(cell[ptr])
     {
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
          while(cell[ptr])
          {
               cell[ptr]-= 1;
               ptr+= 1;
               if(ptr>=7) perror("Program pointer overflow");
               cell[ptr]+= 1;
               ptr-= 2;
               if(ptr<0) perror("Program pointer underflow");
               cell[ptr]+= 4;
               ptr+= 1;
               if(ptr>=7) perror("Program pointer overflow");
          }
          ptr-= 2;
          if(ptr<0) perror("Program pointer underflow");
     }
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     putchar(cell[ptr]);
     cell[ptr]+= 7;
     putchar(cell[ptr]);
     putchar(cell[ptr]);
     cell[ptr]+= 3;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 7;
     putchar(cell[ptr]);
     ptr-= 3;
     if(ptr<0) perror("Program pointer underflow");
     while(cell[ptr])
     {
          while(cell[ptr])
          {
               cell[ptr]-= 1;
          }
          ptr-= 1;
          if(ptr<0) perror("Program pointer underflow");
          while(cell[ptr])
          {
               cell[ptr]-= 1;
          }
          ptr+= 1;
          if(ptr>=7) perror("Program pointer overflow");
     }
     ptr-= 1;
     if(ptr<0) perror("Program pointer underflow");
     cell[ptr]+= 15;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     putchar(cell[ptr]);
     cell[ptr]+= 3;
     putchar(cell[ptr]);
     cell[ptr]-= 6;
     putchar(cell[ptr]);
     cell[ptr]-= 8;
     putchar(cell[ptr]);
     ptr+= 2;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 1;
     putchar(cell[ptr]);
     ptr+= 1;
     if(ptr>=7) perror("Program pointer overflow");
     cell[ptr]+= 4;
     putchar(cell[ptr]);
     return 0;
}
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;
}
Task: Code Golf_ Code Golf

C: main(){printf("Code Golf");}
Task: Strange unique prime triplets

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

#define LIMIT 3000

void init_sieve(unsigned char sieve[], int limit) {
    int i, j;

    for (i = 0; i < limit; i++) {
        sieve[i] = 1;
    }
    sieve[0] = 0;
    sieve[1] = 0;

    for (i = 2; i < limit; i++) {
        if (sieve[i]) {
            for (j = i + i; j < limit; j += i) {
                sieve[j] = 0;
            }
        }
    }
}

void strange_unique_prime_triplets(unsigned char sieve[], int limit, bool verbose) {
    int count = 0, sum;
    int i, j, k, n, p;
    int pi, pj, pk;

    n = 0;
    for (i = 0; i < limit; i++) {
        if (sieve[i]) {
            n++;
        }
    }

    if (verbose) {
        printf("Strange unique prime triplets < %d:\n", limit);
    }

    for (i = 0; i + 2 < n; i++) {
        pi = 2;
        p = i;
        while (p > 0) {
            pi++;
            if (sieve[pi]) {
                p--;
            }
        }

        for (j = i + 1; j + 1 < n; j++) {
            pj = pi;
            p = j - i;
            while (p > 0) {
                pj++;
                if (sieve[pj]) {
                    p--;
                }
            }

            for (k = j + 1; k < n; k++) {
                pk = pj;
                p = k - j;
                while (p > 0) {
                    pk++;
                    if (sieve[pk]) {
                        p--;
                    }
                }

                sum = pi + pj + pk;
                if (sum < LIMIT && sieve[sum]) {
                    count++;
                    if (verbose) {
                        printf("%2d + %2d + %2d = %d\n", pi, pj, pk, sum);
                    }
                }
            }
        }
    }

    printf("Count of strange unique prime triplets < %d is %d.\n\n", limit, count);
}

int main() {
    unsigned char sieve[LIMIT];

    init_sieve(sieve, LIMIT);

    strange_unique_prime_triplets(sieve, 30, true);
    strange_unique_prime_triplets(sieve, 1000, false);

    return 0;
}