Table of Contents
Interesting code snippets
(C) Fibonacci One-liner
#include <stdio.h> int main(void) { long x = 1, y = 1; do { printf("%d\\n%d\\n", x, y); } while ( (x += y) && (y += x) ); }
#include <stdio.h> int main(void) { for ( unsigned int x = 1, y = 1 ; (x += y) && (y < x) && (y += x) && (x < y) ; printf("%d\\n%d\\n", x, y) ) continue; }
(Python) String Generator
def string_generator(chars, length): positions = [0] * (length + 1) while positions[0] == 0: yield ''.join(chars[x] for x in positions[1:]) pos = length positions[pos] = (positions[pos] + 1) % len(chars) while positions[pos] == 0 and pos > 0: pos -= 1 positions[pos] = (positions[pos] + 1) % len(chars)