WeixiangYan/CodeTransOcean huggingface dataset:
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;
}







Python: 












def Gcd(v1, v2):
    a, b = v1, v2
    if (a < b):
        a, b = v2, v1
    r = 1
    while (r != 0):
        r = a % b
        if (r != 0):
            a = b
            b = r
    return b


a = [1, 2]

n = 3

while (n < 50):
    gcd1 = Gcd(n, a[-1])
    gcd2 = Gcd(n, a[-2])
    
    
    if (gcd1 == 1 and gcd2 == 1 and not(n in a)):
        
        a.append(n)
        n = 3
    else:
        
        n += 1


for i in range(0, len(a)):
    if (i % 10 == 0):
        print('')
    print("%4d" % a[i], end = '');
    

print("\n\nNumber of elements in coprime triplets = " + str(len(a)), end = "\n")
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;
}







Python: s = [1, 2, 2, 3, 4, 4, 5]
 
for i in range(len(s)):
    curr = s[i]
    if i > 0 and curr == prev:
        print(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;
}







Python: from SOAPpy import WSDL 
proxy = WSDL.Proxy("http://example.com/soap/wsdl")
result = proxy.soapFunc("hello")
result = proxy.anotherSoapFunc(34234)
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









Python: Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import __future__
>>> __future__.all_feature_names
['nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement', 'print_function', 'unicode_literals', 'barry_as_FLUFL']
>>>
Task: Find first and last set bit of a long integer

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

uint32_t msb32(uint32_t n)
{
	uint32_t b = 1;
	if (!n) return 0;

#define step(x) if (n >= ((uint32_t)1) << x) b <<= x, n >>= x
	step(16); step(8); step(4); step(2); step(1);
#undef step
	return b;
}

int msb32_idx(uint32_t n)
{
	int b = 0;
	if (!n) return -1;

#define step(x) if (n >= ((uint32_t)1) << x) b += x, n >>= x
	step(16); step(8); step(4); step(2); step(1);
#undef step
	return b;
}

#define lsb32(n) ( (uint32_t)(n) & -(int32_t)(n) )


inline int lsb32_idx(uint32_t n) { return msb32_idx(lsb32(n)); }

int main()
{
	int32_t n;
	int i;

	for (i = 0, n = 1; ; i++, n *= 42) {
		printf("42**%d = %10d(x%08x): M x%08x(%2d) L x%03x(%2d)\n",
			i, n, n,
			msb32(n), msb32_idx(n),
			lsb32(n), lsb32_idx(n));

		if (n >= INT32_MAX / 42) break;
	}

	return 0;
}







Python: def msb(x):
    return x.bit_length() - 1

def lsb(x):
    return msb(x & -x)

for i in range(6):
    x = 42 ** i
    print("%10d MSB: %2d LSB: %2d" % (x, msb(x), lsb(x)))

for i in range(6):
    x = 1302 ** i
    print("%20d MSB: %2d LSB: %2d" % (x, msb(x), lsb(x)))
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;
}







Python: import itertools

def riseEqFall(num):
    
    height = 0
    d1 = num % 10
    num //= 10
    while num:
        d2 = num % 10
        height += (d1<d2) - (d1>d2)
        d1 = d2
        num //= 10
    return height == 0
    
def sequence(start, fn):
    
    num=start-1
    while True:
        num += 1
        while not fn(num): num += 1
        yield num

a296712 = sequence(1, riseEqFall)


print("The first 200 numbers are:")
print(*itertools.islice(a296712, 200))


print("The 10,000,000th number is:")
print(*itertools.islice(a296712, 10000000-200-1, 10000000-200))
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;
}







Python: import curses

scr = curses.initscr()

def move_left():
	y,x = curses.getyx()
	curses.move(y,x-1)
	

def move_right():
	y,x = curses.getyx()
	curses.move(y,x+1)
	

def move_up():
	y,x = curses.getyx()
	curses.move(y-1,x)
	

def move_down():
	y,x = curses.getyx()
	curses.move(y+1,x)


def move_line_home()	
	y,x = curses.getyx()
	curses.move(y,0)


def move_line_end()	
	y,x = curses.getyx()
	maxy,maxx = scr.getmaxyx()
	curses.move(y,maxx)


def move_page_home():
	curses.move(0,0)
	

def move_page_end():
	y,x = scr.getmaxyx()
	curses.move(y,x)
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;
}







Python: 

def isPrime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False        
    return True

if __name__ == '__main__':
    suma = 2
    n = 1
    for i in range(3, 2000000, 2):
        if isPrime(i):
            suma += i
            n+=1 
    print(suma)
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;
}







Python: l = 300

def setup():
    size(400, 400)
    background(0, 0, 255)
    stroke(255)
    
    translate(width / 2.0, height / 2.0)
    
    translate(-l / 2.0, l * sqrt(3) / 6.0)
    for i in range(4):
        kcurve(0, l)
        rotate(radians(120))
        translate(-l, 0)


def kcurve(x1, x2):
    s = (x2 - x1) / 3.0
    if s < 5:
        pushMatrix()
        translate(x1, 0)
        line(0, 0, s, 0)
        line(2 * s, 0, 3 * s, 0)
        translate(s, 0)
        rotate(radians(60))
        line(0, 0, s, 0)
        translate(s, 0)
        rotate(radians(-120))
        line(0, 0, s, 0)
        popMatrix()
        return

    pushMatrix()
    translate(x1, 0)
    kcurve(0, s)
    kcurve(2 * s, 3 * s)
    translate(s, 0)
    rotate(radians(60))
    kcurve(0, s)
    translate(s, 0)
    rotate(radians(-120))
    kcurve(0, s)
    popMatrix()
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;
}







Python: import Tkinter,random
def draw_pixel_2 ( sizex=640,sizey=480 ):
    pos  = random.randint( 0,sizex-1 ),random.randint( 0,sizey-1 )
    root = Tkinter.Tk()
    can  = Tkinter.Canvas( root,width=sizex,height=sizey,bg='black' )
    can.create_rectangle( pos*2,outline='yellow' )
    can.pack()
    root.title('press ESCAPE to quit')
    root.bind('<Escape>',lambda e : root.quit())
    root.mainloop()

draw_pixel_2()
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'));
}







Python: def isvowel(c):
    
    return c in ['a', 'e', 'i', 'o', 'u', 'A', 'E', "I", 'O', 'U']

def isletter(c):
    
    return 'a' <= c <= 'z' or 'A' <= c <= 'Z'

def isconsonant(c):
    
    return  not isvowel(c) and isletter(c)

def vccounts(s):
    
    a = list(s.lower())
    au = set(a)
    return sum([isvowel(c) for c in a]), sum([isconsonant(c) for c in a]), \
        sum([isvowel(c) for c in au]), sum([isconsonant(c) for c in au])

def testvccount():
    teststrings = [
        "Forever Python programming language",
        "Now is the time for all good men to come to the aid of their country."]
    for s in teststrings:
        vcnt, ccnt, vu, cu = vccounts(s)
        print(f"String: {s}\n    Vowels: {vcnt} (distinct {vu})\n    Consonants: {ccnt} (distinct {cu})\n")

testvccount()
Task: Compiler_syntax analyzer

C: count = 1;
 while (count < 10) {
     print("count is: ", count, "\n");
     count = count + 1;
 }







Python: def expr(p)
    if tok is "("
        x = paren_expr()
    elif tok in ["-", "+", "!"]
        gettok()
        y = expr(precedence of operator)
        if operator was "+"
            x = y
        else
            x = make_node(operator, y)
    elif tok is an Identifier
        x = make_leaf(Identifier, variable name)
        gettok()
    elif tok is an Integer constant
        x = make_leaf(Integer, integer value)
        gettok()
    else
        error()

    while tok is a binary operator and precedence of tok >= p
        save_tok = tok
        gettok()
        q = precedence of save_tok
        if save_tok is not right associative
            q += 1
        x = make_node(Operator save_tok represents, x, expr(q))

    return x

def paren_expr()
    expect("(")
    x = expr(0)
    expect(")")
    return x

def stmt()
    t = NULL
    if accept("if")
        e = paren_expr()
        s = stmt()
        t = make_node(If, e, make_node(If, s, accept("else") ? stmt() : NULL))
    elif accept("putc")
        t = make_node(Prtc, paren_expr())
        expect(";")
    elif accept("print")
        expect("(")
        repeat
            if tok is a string
                e = make_node(Prts, make_leaf(String, the string))
                gettok()
            else
                e = make_node(Prti, expr(0))

            t = make_node(Sequence, t, e)
        until not accept(",")
        expect(")")
        expect(";")
    elif tok is ";"
        gettok()
    elif tok is an Identifier
        v = make_leaf(Identifier, variable name)
        gettok()
        expect("=")
        t = make_node(Assign, v, expr(0))
        expect(";")
    elif accept("while")
        e = paren_expr()
        t = make_node(While, e, stmt()
    elif accept("{")
        while tok not equal "}" and tok not equal end-of-file
            t = make_node(Sequence, t, stmt())
        expect("}")
    elif tok is end-of-file
        pass
    else
        error()
    return t

def parse()
    t = NULL
    gettok()
    repeat
        t = make_node(Sequence, t, stmt())
    until tok is end-of-file
    return t
Task: Draw a pixel

C: #include<graphics.h>

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







Python: from PIL import Image

img = Image.new('RGB', (320, 240))
pixels = img.load()
pixels[100,100] = (255,0,0)
img.show()
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;
}







Python: 



def digitSumsPrime(n):
    
    def go(bases):
        return all(
            isPrime(digitSum(b)(n))
            for b in bases
        )
    return go



def digitSum(base):
    
    def go(n):
        q, r = divmod(n, base)
        return go(q) + r if n else 0
    return go




def main():
    
    xs = [
        str(n) for n in range(1, 200)
        if digitSumsPrime(n)([2, 3])
    ]
    print(f'{len(xs)} matches in [1..199]\n')
    print(table(10)(xs))





def chunksOf(n):
    
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go



def isPrime(n):
    
    if n in (2, 3):
        return True
    if 2 > n or 0 == n % 2:
        return False
    if 9 > n:
        return True
    if 0 == n % 3:
        return False

    def p(x):
        return 0 == n % x or 0 == n % (2 + x)

    return not any(map(p, range(5, 1 + int(n ** 0.5), 6)))



def table(n):
    
    def go(xs):
        w = len(xs[-1])
        return '\n'.join(
            ' '.join(row) for row in chunksOf(n)([
                s.rjust(w, ' ') for s in xs
            ])
        )
    return go



if __name__ == '__main__':
    main()
Task: Words from neighbour ones

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

#define MAX_WORD_SIZE 80
#define MIN_LENGTH 9
#define WORD_SIZE (MIN_LENGTH + 1)

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 word_compare(const void* p1, const void* p2) {
    return memcmp(p1, p2, WORD_SIZE);
}

int main(int argc, char** argv) {
    const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
    FILE* in = fopen(filename, "r");
    if (!in) {
        perror(filename);
        return EXIT_FAILURE;
    }
    char line[MAX_WORD_SIZE];
    size_t size = 0, capacity = 1024;
    char* words = xmalloc(WORD_SIZE * capacity);
    while (fgets(line, sizeof(line), in)) {
        size_t len = strlen(line) - 1; 
        if (len < MIN_LENGTH)
            continue;
        line[len] = '\0';
        if (size == capacity) {
            capacity *= 2;
            words = xrealloc(words, WORD_SIZE * capacity);
        }
        memcpy(&words[size * WORD_SIZE], line, WORD_SIZE);
        ++size;
    }
    fclose(in);
    qsort(words, size, WORD_SIZE, word_compare);
    int count = 0;
    char prev_word[WORD_SIZE] = { 0 };
    for (size_t i = 0; i + MIN_LENGTH <= size; ++i) {
        char word[WORD_SIZE] = { 0 };
        for (size_t j = 0; j < MIN_LENGTH; ++j)
            word[j] = words[(i + j) * WORD_SIZE + j];
        if (word_compare(word, prev_word) == 0)
            continue;
        if (bsearch(word, words, size, WORD_SIZE, word_compare))
            printf("%2d. %s\n", ++count, word);
        memcpy(prev_word, word, WORD_SIZE);
    }
    free(words);
    return EXIT_SUCCESS;
}







Python: 

import urllib.request
from collections import Counter
 
urllib.request.urlretrieve("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt", "unixdict.txt")
 
dictionary = open("unixdict.txt","r")
 
wordList = dictionary.read().split('\n')
 
dictionary.close()
 
filteredWords = [chosenWord for chosenWord in wordList if len(chosenWord)>=9]

for word in filteredWords[:-9]:
  position = filteredWords.index(word)
  newWord = "".join([filteredWords[position+i][i] for i in range(0,9)])
  if newWord in filteredWords:
   print(newWord)
Task: Numbers divisible by their individual digits, but not by the product of their digits.

C: #include <stdio.h>

int divisible(int n) {
    int p = 1;
    int c, d;
    
    for (c=n; c; c /= 10) {
        d = c % 10;
        if (!d || n % d) return 0;
        p *= d;
    }
    
    return n % p;
}

int main() {
    int n, c=0;
    
    for (n=1; n<1000; n++) {
        if (divisible(n)) {
            printf("%5d", n);
            if (!(++c % 10)) printf("\n");
        }
    }
    printf("\n");
    
    return 0;
}







Python: 

from functools import reduce
from operator import mul



def p(n):
    
    digits = [int(c) for c in str(n)]
    return not 0 in digits and (
        0 != (n % reduce(mul, digits, 1))
    ) and all(0 == n % d for d in digits)




def main():
    
    xs = [
        str(n) for n in range(1, 1000)
        if p(n)
    ]
    w = len(xs[-1])
    print(f'{len(xs)} matching numbers:\n')
    print('\n'.join(
        ' '.join(cell.rjust(w, ' ') for cell in row)
        for row in chunksOf(10)(xs)
    ))





def chunksOf(n):
    
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go



if __name__ == '__main__':
    main()