Skip to content

Commit

Permalink
Solved #17, #85, #116, #125, #206
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmoyev committed May 7, 2021
1 parent 584b34c commit b19f450
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
28 changes: 28 additions & 0 deletions problem_116.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from functools import lru_cache


@lru_cache
def count(size, tiles, tile_size):
if tile_size * tiles > size:
return 0
if tile_size * tiles == size:
return 1
if tiles == 1:
return size - tile_size + 1

total = 0
for i in range(tile_size, size - (tiles - 1) * tile_size + 1):
total += count(size - i, tiles - 1, tile_size)

return total


def count_for_tile(size, tile_size):
total = 0
for i in range(1, (size // tile_size) + 1):
total += count(size, i, tile_size)
return total


print(count_for_tile(50, 2), count_for_tile(50, 3), count_for_tile(50, 4))
print(count_for_tile(50, 2) + count_for_tile(50, 3) + count_for_tile(50, 4))
16 changes: 16 additions & 0 deletions problem_125.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
def is_poly(n):
return str(n) == str(n)[::-1]


palindromes = set()
for i in range(1, 10000):
j = i + 1
total_tmp = j * j + i * i
j += 1
while total_tmp < 10 ** 8:
if is_poly(total_tmp):
palindromes.add(total_tmp)
total_tmp += j * j
j += 1

print(sum(palindromes))
3 changes: 3 additions & 0 deletions problem_17.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from num2words import num2words

print(sum(len(num2words(i).replace(' ', '').replace('-', '')) for i in range(1, 1001)))
9 changes: 9 additions & 0 deletions problem_206.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from math import sqrt
import re

for i in range(int(sqrt(1020304050607080900)), int(sqrt(1929394959697989990)), 10):
if re.match('1.2.3.4.5.6.7.8.9.0', str(i * i)):
print('Done', i)

if i % 1000000 == 0:
print(i)
14 changes: 14 additions & 0 deletions problem_85.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def count_rects(a, b):
if a == b == 1:
return 1
res = 1
if a > 1:
res += count_rects(a - 1, b) * 2
if b > 1:
res += count_rects(a, b - 1) * 2
if a >= 1 and b >= 1:
res -= count_rects(a - 1, b - 1)
return res


print(count_rects(2, 2))

0 comments on commit b19f450

Please sign in to comment.