Skip to content

Instantly share code, notes, and snippets.

View sjatkins's full-sized avatar

Samantha Atkins sjatkins

View GitHub Profile
from itertools import permutations, product
def pairs(it):
return [(a,b) for a in it[:-1] for b in it[a+1:]]
class Board(object):
offset_pairs = ((1, -2), (1, 2), (2, -1), (2, 1), (-1, -2), (-1, 2), (-2, 1), (-2, -1))
unrestricted = (-2, -1, 1, -2)
dim_specials = {
0: (1,2), 1:(-1, 1, 2), -1: (-1, -2), -2: (1, -1, -2)
@sjatkins
sjatkins / foo.py
Last active November 3, 2016 00:57
from itertools import chain, cycle, izip, imap, islice
def fizzbuzz(count):
cycler = lambda mod_n, mod_label: cycle((mod_n - 1) * [''] + [mod_label])
str_value = lambda (index, (fizz, buzz)): (fizz + buzz) or str(index + 1)
take = lambda n, iterable: islice(iterable, n)
data = take(count, enumerate(izip(cycler(3, 'fizz'), cycler(5, 'buzz'))))
return imap(str_value, data)
test_fb = lambda n: list(fizzbuzz(n))