This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
from collections import Counter | |
print Counter(Image.open('Santa.png').getdata()).most_common(10)[-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import pow, sqrt | |
MAX = 10000 | |
MAX_PRIME = int(sqrt(sqrt(MAX))) | |
primes = [prime for prime | |
in [2] + range(3, MAX_PRIME, 2) | |
if all(prime%i != 0 for i in range(2, prime))] | |
for n in range(MAX_PRIME): | |
if n in primes: | |
perfectNumber = pow(2, n-1) * (pow(2, n)-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
print min([min(a, b) for (a, b) in combinations(xrange(99, 999), 2) | |
if a+b>999 | |
if len(set("%s%s%s" % (a,b,a+b)))==10]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c, people = 1, range(1, 1501) | |
while len(people)>1: | |
people.pop(c) | |
c += 1 | |
if c == len(people): c = 0 | |
elif c > len(people): c = 1 | |
print people[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date, timedelta | |
start = date(1337,1,1) | |
delta = date.today() - start | |
print len([date for date in | |
[start + timedelta(days=n) for n in range(delta.days)] | |
if date.day == 13 | |
if date.weekday() == 4]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MOVES = [[-2,-1],[-2,1],[-1,-2],[-1,2],[1,-2],[1,2],[2,-1],[2,1]] | |
KEYPAD = [[1, 2, 3],[4, 5, 6],[7, 8, 9],[None, 0, None]] | |
VALID = {(x, y) : key | |
for x,row in enumerate(KEYPAD) | |
for y,key in enumerate(row) | |
if not key == None} | |
GRAPH = {key : [VALID[(x+x2, y+y2)] for x2, y2 in MOVES if (x+x2, y+y2) in VALID] | |
for x, row in enumerate(KEYPAD) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
G = {0:[4, 6], 1:[6, 8], 2:[7, 9], 3:[4, 8], 4:[3, 9, 0], 5:[], 6:[1, 7, 0], 7:[2, 6], 8:[1, 3], 9:[2, 4]} | |
def walk(graph, node, d=1, m=10): | |
return 1 if d == m else sum([walk(graph, n, d+1, m) for n in graph[node]]) | |
print walk(G, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import Counter | |
with open('words.txt', 'r') as f: | |
print Counter(["".join(sorted(w.strip().lower())) for w in f]).most_common(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = data.replace("\n","").lower() | |
palin = [data[i:j] | |
for i in xrange(len(data)) | |
for j in xrange(i, len(data)+1) | |
if data[i:j] == data[i:j][::-1]] | |
longest = max(map(len, palin)) | |
print filter(lambda x: len(x) == longest, palin)[0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import five from 'johnny-five'; | |
const board = new five.Board(); | |
const SAMPLE_SIZE = 50; | |
const SAMPLE_FREQ = 1; | |
const SAMPLE_TIMES = 10; | |
board.on("ready", function() { | |
const mic = new five.Sensor({ | |
pin:"A0", |