Skip to content

Added solution for Project Euler problem 119 #2931

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 1 commit into from
Oct 10, 2020

Conversation

ksr1122
Copy link
Contributor

@ksr1122 ksr1122 commented Oct 6, 2020

Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: #2695

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ksr1122 ksr1122 force-pushed the problem_119 branch 4 times, most recently from 33eb596 to e03214f Compare October 9, 2020 08:41
@ksr1122 ksr1122 changed the title problem_119: project euler solution 119 Hacktoberfest: project euler solution 119 Oct 9, 2020
@ksr1122 ksr1122 force-pushed the problem_119 branch 2 times, most recently from c8f232f to 77d2401 Compare October 10, 2020 09:36
@ksr1122 ksr1122 changed the title Hacktoberfest: project euler solution 119 Added solution for Project Euler problem 119 Oct 10, 2020
Comment on lines 12 to 13


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the empty line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove both the newlines before the imports :)
You could've directly applied the suggestion but it's up to you.


def solution() -> int:
"""
Returns the value of a30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please improve on docstring and add doctest

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated docstring and added doctests

powers = []
for i in range(2, 100):
for j in range(2, 100):
n = int(math.pow(i, j))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a more descriptive variable name than n?

@dhruvmanila dhruvmanila added awaiting changes A maintainer has requested changes to this PR require tests Tests [doctest/unittest/pytest] are required labels Oct 10, 2020
Comment on lines 39 to 42
digi_to_powers = []
for digit in range(2, 100):
for power in range(2, 100):
digit_to_power = int(math.pow(digit, power))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe number instead of digit_to_power and digit_to_powers instead of digi_to_powers ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, sorry for the typo. Fixed it.

Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695
@dhruvmanila dhruvmanila merged commit 2b5b2c6 into TheAlgorithms:master Oct 10, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695

Co-authored-by: Ravi Kandasamy Sundaram <[email protected]>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request May 13, 2021
Name: Digit power sum

Problem Statement: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284.
We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum.
You are given that a2 = 512 and a10 = 614656.
Find a30

Reference: https://projecteuler.net/problem=119

reference: TheAlgorithms#2695

Co-authored-by: Ravi Kandasamy Sundaram <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes A maintainer has requested changes to this PR require tests Tests [doctest/unittest/pytest] are required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants