Commit 62a56d96 authored by Taddeus Kroes's avatar Taddeus Kroes

Added solutions to problems 24, 26, 29, 41, 42, 81 and 92.

parents
This diff is collapsed.
from itertools import permutations
for i, p in enumerate(permutations(range(10))):
if i == 999999:
print ''.join(map(str, p))
break
from decimal import Decimal as D
import re
for i in range(2, 11):
r = str(round(1. / i, 1000))[2:-1]
for l in range(len(r) / 2, 0, -1):
pass
print i, r
def combos(A, B):
c = set()
for a in A:
for b in B:
c.add(a ** b)
return sorted(c)
print len(combos(range(2, 101), range(2, 101)))
from math import sqrt, ceil
from itertools import permutations
def is_prime(n):
if n == 2:
return True
if not n % 2:
return False
for i in xrange(3, int(ceil(sqrt(n))) + 1 + 1, 2):
if not divmod(n, i)[1]:
return False
return True
m = 0
for i in xrange(2, 10):
for digits in permutations(map(str, range(i, 0, -1))):
n = int(''.join(digits))
if n > m and is_prime(n):
m = n
print m
words = open('words.txt', 'r').read()[1:-1].split('","')
def word_value(word):
return sum([ord(c) - 96 for c in word.lower()])
values = [word_value(w) for w in words]
m = max(values)
triangle = [1]
v = n = 1
while v < m:
n += 1
v = n * (n + 1) / 2
triangle.append(v)
count = 0
for v in values:
if v in triangle:
count += 1
print count
from numpy import array, zeros
#m = array([[131, 673, 234, 103, 18 ],
# [201, 96 , 342, 965, 150],
# [630, 803, 746, 422, 111],
# [537, 699, 497, 121, 956],
# [805, 732, 524, 37 , 331]])
f = open('matrix.txt', 'r')
m = array([map(int, l.split(',')) for l in f.readlines()])
f.close()
def add(x, y):
global m
h, w = m.shape
if x == w or y == h: return
p = []
if x: p.append(m[y, x - 1])
if y: p.append(m[y - 1, x])
m[y, x] += min(p)
h, w = m.shape
for i in range(w+h):
for x in range(i + 1):
y = i - x
if (x or y) and x < w and y < h:
add(x, y)
print m[h - 1, w - 1]
def digits(n):
return [n] if n < 10 else digits(n / 10) + [n % 10]
def quad(n):
return n * n
def end(s):
return s if s == 1 or s == 89 else end(sum(map(quad, digits(s))))
count = 0
for n in xrange(1, 10000000):
if end(n) == 89:
count += 1
print count
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment