-
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.
Solve p85 in python (86th solved!); minor docs changes
- Loading branch information
1 parent
0e4e2be
commit fdf358b
Showing
9 changed files
with
79 additions
and
7 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
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
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
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,23 @@ | ||
Python Implementation of Problem 85 | ||
=================================== | ||
|
||
View source code :source:`python/src/p0085.py` | ||
|
||
Includes | ||
-------- | ||
|
||
- :external:py:func:`math.ceil` | ||
- :external:py:func:`math.sqrt` | ||
|
||
Problem Solution | ||
---------------- | ||
|
||
.. automodule:: python.src.p0085 | ||
:members: | ||
:undoc-members: | ||
|
||
.. literalinclude:: ../../../python/src/p0085.py | ||
:language: python | ||
:linenos: | ||
|
||
.. tags:: geometry, packing, combinatorics |
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
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
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
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 @@ | ||
""" | ||
Project Euler Problem 85 | ||
Problem: | ||
By counting carefully it can be seen that a rectangular grid measuring 3 by 2 contains eighteen rectangles: | ||
.. image:: https://projecteuler.net/resources/images/0085.png | ||
Although there exists no rectangular grid that contains exactly two million rectangles, find the area of the grid with the nearest solution. | ||
""" | ||
from math import ceil, sqrt | ||
|
||
|
||
def num_rectangles(x: int, y: int) -> int: | ||
answer = 0 | ||
for a in range(1, x + 1): | ||
for b in range(1, y + 1): | ||
answer += (x - a + 1) * (y - b + 1) | ||
return answer | ||
|
||
|
||
def main(tolerance: int = 2) -> int: | ||
for x in range(1, ceil(sqrt(2000000))): | ||
for y in range(1, x): | ||
if abs(num_rectangles(x, y) - 2000000) <= tolerance: | ||
return x * y | ||
return -1 |
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
*range(76, 78), | ||
79, | ||
81, | ||
85, | ||
87, | ||
89, | ||
92, | ||
|