-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kuzmoyev
committed
May 7, 2021
1 parent
584b34c
commit b19f450
Showing
5 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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)) |
This file contains 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
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)) |
This file contains 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
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))) |
This file contains 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
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) |
This file contains 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
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)) |