Skip to content

Instantly share code, notes, and snippets.

@jeek
jeek / exp.py
Last active May 9, 2016 09:07
exp.py
from itertools import permutations
for digits in xrange(1, 10):
thestring = "".join([str(i) for i in range(1, digits + 1)])
for a in permutations(thestring):
for b in permutations(thestring):
answer = " + ".join([a[i] + "**" + b[i] for i in xrange(digits)])
if thestring == "".join(sorted(str(eval(answer)))):
print "[" + str(eval(answer)) + " = " + answer + "]"
@jeek
jeek / palintree.py
Last active May 9, 2016 09:06
palintree.py
from gmpy import is_prime
START = 16661
BADDIGITS = "23457890"
while True:
print START
i = 1
while not is_prime(int(str(i)[::-1] + str(START) + str(i))) or sum([str(i).count(j) for j in BADDIGITS]) > 0:
i += 1
START = int(str(i)[::-1] + str(START) + str(i))
@jeek
jeek / nerfty2.py
Created January 18, 2016 11:08
nerfty2.py
#!/bin/env python
i = 1
while i <= 10000000:
j = 1
answers = dict()
while j * j <= i:
if i % j == 0:
rep = "".join(sorted(([k for k in str(j)]) + ([k for k in str(i/j)])))
if rep not in answers:
@jeek
jeek / nerfty.py
Last active January 18, 2016 06:14
nerfty.py
i = 1
while i <= 1000000:
j = 1
answers = dict()
while j * j <= i:
if i % j == 0:
rep = "".join(sorted(([k for k in str(j)]) + ([k for k in str(i/j)])))
if rep not in answers:
answers[rep] = []
answers[rep].append(str(j) + " * " + str(i/j))
@jeek
jeek / nifty.py
Last active January 17, 2016 22:30
nifty.py
i = 2
def recur(i, j, k):
if len(k) > 0 and k[1] == "+":
k = k[3:]
if len(k) > 0:
current = str(eval(k))
if len(current) == 10:
if "1" in current:
if "2" in current:
@jeek
jeek / shufflemult.py
Last active January 17, 2016 21:10 — forked from anonymous/shufflemult.py
shufflemult.py
from itertools import permutations
seen = dict()
seenline = set()
i = 0
while True:
current = sorted(set([int("".join(j)) for j in list(permutations(str(i)))]))
if current[-1] not in seen:
from itertools import permutations
for ii in xrange(2, 10):
for i in permutations("1234567890", ii):
for k in xrange(1, len(i)):
if i[:k][0] != '0':
if i[k:][0] != '0':
left = int("".join(i[:k]))
right = int("".join(i[k:]))
if right != 0:
@jeek
jeek / fib.py
Created January 7, 2016 19:00
nonsequential Fibonacci sums
from copy import deepcopy as copy
import heapq
UPPERLIMIT = 1000000
fib = [1,1]
while fib[-1] < UPPERLIMIT:
fib.append(fib[-1] + fib[-2])
fib.pop(0)
fib.pop()
from copy import deepcopy as copy
target = 2016
fib = [1,1]
while fib[-1] < target:
fib.append(fib[-1] + fib[-2])
fib.pop()
fib = tuple(fib)
fibs = set()
@jeek
jeek / skills.py
Created November 13, 2015 18:13
Fallout Skills
from copy import deepcopy as copy
from itertools import permutations
def recur(levels, skills, skilltree):
if len(skills) == 0:
yield levels
else:
current = skills.pop(0)
good = True
for i in xrange(len(skilltree[current])):