Return the number of different square laminae that can be formed using up to one million tiles. >>> solution(100) 41
(limit: int = 1000000)
| 15 | |
| 16 | |
| 17 | def solution(limit: int = 1000000) -> int: |
| 18 | """ |
| 19 | Return the number of different square laminae that can be formed using up to |
| 20 | one million tiles. |
| 21 | >>> solution(100) |
| 22 | 41 |
| 23 | """ |
| 24 | answer = 0 |
| 25 | |
| 26 | for outer_width in range(3, (limit // 4) + 2): |
| 27 | if outer_width**2 > limit: |
| 28 | hole_width_lower_bound = max(ceil(sqrt(outer_width**2 - limit)), 1) |
| 29 | else: |
| 30 | hole_width_lower_bound = 1 |
| 31 | if (outer_width - hole_width_lower_bound) % 2: |
| 32 | hole_width_lower_bound += 1 |
| 33 | |
| 34 | answer += (outer_width - hole_width_lower_bound - 2) // 2 + 1 |
| 35 | |
| 36 | return answer |
| 37 | |
| 38 | |
| 39 | if __name__ == "__main__": |