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
mport numpy as np | |
data = """ | |
75 | |
95 64 | |
17 47 82 | |
18 35 87 10 | |
20 04 82 47 65 | |
19 01 23 75 03 34 | |
88 02 77 73 07 63 67 | |
99 65 04 28 06 16 70 92 |
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
info_less_than20 = { 0:"", 1:"one", 2:"two", 3:"three", 4:"four", 5:"five", | |
6:"six", 7:"seven", 8:"eight", 9:"nine", 10:"ten", | |
11:"eleven", 12:"twelve", 13:"thirteen", 14:"forteen", 15:"fifteen", | |
16:"sixteen", 17:"seventeen", 18:"eighteen", 19:"nineteen", | |
} | |
info_biger_than_twenty = { 20:"twenty", 30:"thirty", 40:"forty", 50:"fifty", | |
60:"sixty", 70:"seventy", 80:"eighty", 90:"ninety", | |
} | |
arr = [list(str(x)) for x in range(1000)] | |
arr = [x[:-2]+["".join(x[-2:])] for x in arr] |
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 multiply2(arr): | |
arr = [x*2 for x in arr] | |
arr.append(0) | |
for i in range(len(arr)-1): | |
arr[i+1] += arr[i] / 10 | |
arr[i] = arr[i] % 10 | |
if arr[-1] == 0: | |
arr = arr[:-1] | |
return arr |
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 f(n): | |
arr = [1] | |
for i in range(n): | |
a = [1] * (len(arr) + 1) | |
for j in range(1, len(arr)): | |
a[j] = arr[j] + arr[j-1] | |
arr = a | |
return sum([x*x for x in arr]) | |
print f(20) |
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
under = 1000000 + 1 | |
info = [0] * (3 * under) | |
def func(n): | |
if n == 1: | |
return 1 | |
if n < len(info): | |
if info[n]: | |
return info[n] | |
t = n/2 if n%2 == 0 else n*3 +1 | |
info[n] = 1 + func(t) |
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 numpy as np | |
data = """ | |
37107287533902102798797998220837590246510135740250 | |
46376937677490009712648124896970078050417018260538 | |
74324986199524741059474233309513058123726617309629 | |
91942213363574161572522430563301811072406154908250 | |
23067588207539346171171980310421047513778063246676 | |
89261670696623633820136378418383684178734361726757 | |
28112879812849979408065481931592621691275889832738 | |
44274228917432520321923589422876796487670272189318 |
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 math | |
def func(target=500): | |
n = 1 | |
while True: | |
n = n+1 | |
total = n * (n+1)/2 | |
count = 2 | |
for i in range(2, int(math.sqrt(total))): | |
if total%i == 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 numpy as np | |
from itertools import chain | |
data = """ | |
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 | |
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 | |
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65 | |
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91 | |
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80 | |
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50 | |
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70 |
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 find_prime_under(n=100): | |
arr = range(n) | |
nn = n - 1 | |
for num in arr: | |
if num > 1: | |
i = 2 | |
while True: | |
mul = i*num | |
i += 1 | |
if mul > nn: |
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
t = 1000. | |
def calc_a(b): | |
a = (t*t - 2*t*b)/2/(t-b) | |
return a | |
ab = [(calc_a(b), b) for b in range(1, int(t))] | |
ab = filter(lambda x: float(int(x[0])) == x[0] and x[0] > 0, ab) | |
abc = [list(x) + [t-x[0]-x[1]] for x in ab] | |
productor = [int(x[0] * x[1] * x[2]) for x in abc] |
NewerOlder