-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Add Project Euler Problem 078 solution 01 #5565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
356bc6c
Create sol1.py
FirePing32 63b5438
updating DIRECTORY.md
23a6802
Create __init__.py
FirePing32 ece0d19
Add docstring
FirePing32 1774694
Reformat with black
FirePing32 6ad008f
Fix flake8 issues
FirePing32 e193bfb
Add EOL
FirePing32 5dc43f5
Fix formatting issues
FirePing32 cb0c01e
Merge branch 'TheAlgorithms:master' into Euler-P78
FirePing32 19373b3
Add docstring
FirePing32 b78fb54
Add func return type
FirePing32 e5a77b1
Change return type
FirePing32 87b6f67
Remove test print statement
FirePing32 b25d844
Reformat code
FirePing32 f8b3136
Fix return types
FirePing32 d2bf43d
Break loop
FirePing32 cea6f3b
Update doctest sol
FirePing32 f540cc6
Update project_euler/problem_078/sol1.py
FirePing32 7287753
Merge branch 'TheAlgorithms:master' into Euler-P78
FirePing32 cc00359
Added doctest and changed return type
FirePing32 3ff95ac
Add int()
FirePing32 95ba530
Fix flake8 issues
FirePing32 4760d47
Use argument instead of fixed constant
FirePing32 e4001b4
Update sol1.py
poyea a227be9
fix sol1.py
poyea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Problem 78 | ||
Url: https://projecteuler.net/problem=78 | ||
Statement: | ||
Let p(n) represent the number of different ways in which n coins | ||
can be separated into piles. For example, five coins can be separated | ||
into piles in exactly seven different ways, so p(5)=7. | ||
|
||
OOOOO | ||
OOOO O | ||
OOO OO | ||
OOO O O | ||
OO OO O | ||
OO O O O | ||
O O O O O | ||
Find the least value of n for which p(n) is divisible by one million. | ||
""" | ||
|
||
import itertools | ||
|
||
|
||
def solution() -> str: | ||
""" | ||
>>> solution() | ||
'55374' | ||
FirePing32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
MODULUS = 10 ** 6 | ||
partitions = [1] | ||
result = "" | ||
|
||
for i in itertools.count(len(partitions)): | ||
|
||
FirePing32 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
item = 0 | ||
for j in itertools.count(1): | ||
sign = -1 if j % 2 == 0 else +1 | ||
index = (j * j * 3 - j) // 2 | ||
if index > i: | ||
break | ||
item += partitions[i - index] * sign | ||
index += j | ||
if index > i: | ||
break | ||
item += partitions[i - index] * sign | ||
item %= MODULUS | ||
|
||
partitions.append(item) | ||
|
||
if item == 0: | ||
result = str(i) | ||
break | ||
|
||
return result | ||
FirePing32 marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.