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 islice | |
def comb(l): | |
if len(l) == 0: | |
yield [] | |
else: | |
for i in range(len(l)): | |
for c in comb(l[:i] + l[i + 1:]): | |
yield [l[i]] + c |
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 sqrt | |
def divisors(n): | |
for x in xrange(1, int(sqrt(n)) + 1): | |
if n % x == 0: | |
yield x | |
if x != 1 and x * x != n: | |
yield n / x | |
abundants = set() |
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
names = sorted(open('names.txt').readline().replace('"', '').split(',')) | |
print sum(((i + 1) * sum(ord(c) - ord('A') + 1 for c in n) | |
for (i, n) in enumerate(names))) |
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 sqrt | |
def divisors(n): | |
for x in xrange(1, int(sqrt(n)) + 1): | |
if n % x == 0: | |
yield x | |
if x != 1 and x * x != n: | |
yield n / x | |
def amicable(n): |
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
def fact(n): | |
s = 1 | |
while n > 0: | |
s = s * n | |
n -= 1 | |
return s | |
print sum(int(c) for c in str(fact(100))) |
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
#!/bin/ksh | |
count=0 | |
for year in {1901..2000}; do | |
for month in {1..12}; do | |
if cal $month $year | cut -b1,2 | grep ' 1' > /dev/null; then | |
((count = $count + 1)) | |
fi | |
done | |
done | |
echo $count |
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
tn = [ | |
[75], | |
[95,64], | |
[17,47,82], | |
[18,35,87,10], | |
[20, 4,82,47,65], | |
[19, 1,23,75, 3,34], | |
[88, 2,77,73, 7,63,67], | |
[99,65, 4,28, 6,16,70,92], | |
[41,41,26,56,83,40,80,70,33], |
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
def say_digit(n): | |
number = '' | |
if n == 1: | |
number = 'one' | |
elif n == 2: | |
number = 'two' | |
elif n == 3: | |
number = 'three' | |
elif n == 4: | |
number = 'four' |
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
print sum(int(c) for c in str(2**1000)) |
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
def fact(n): | |
s = 1 | |
while n > 0: | |
s = s * n | |
n -= 1 | |
return s | |
print fact(20 * 2) / (fact(20) * fact(20)) |