Skip to content

Added solution for Project Euler problem 119#2931

Merged
dhruvmanila merged 1 commit intoTheAlgorithms:masterfrom
ksr1122:problem_119
Oct 10, 2020
Merged

Added solution for Project Euler problem 119#2931
dhruvmanila merged 1 commit intoTheAlgorithms:masterfrom
ksr1122:problem_119

Conversation

@ksr1122
Copy link
Copy Markdown
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 thread project_euler/problem_119/sol1.py Outdated
Comment thread project_euler/problem_119/sol1.py Outdated
Comment on lines +12 to +13


Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread project_euler/problem_119/sol1.py Outdated
Comment thread project_euler/problem_119/sol1.py Outdated
Comment thread project_euler/problem_119/sol1.py Outdated

def solution() -> int:
"""
Returns the value of a30
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread project_euler/problem_119/sol1.py Outdated
powers = []
for i in range(2, 100):
for j in range(2, 100):
n = int(math.pow(i, j))
Copy link
Copy Markdown
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?

Comment thread project_euler/problem_119/sol1.py Outdated
@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 thread project_euler/problem_119/sol1.py Outdated
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
Copy Markdown
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
Copy Markdown
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 <rkandasamysundaram@luxoft.com>
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 <rkandasamysundaram@luxoft.com>
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