Skip to content

Project Euler Problem 80 #2885

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 7 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_67/sol1.py)
* Problem 76
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_76/sol1.py)
* Problem 80
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_80/sol1.py)
* Problem 97
* [Sol1](https://github.com/TheAlgorithms/Python/blob/master/project_euler/problem_97/sol1.py)
* Problem 99
Expand Down
Empty file.
31 changes: 31 additions & 0 deletions project_euler/problem_80/sol1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Euler Problem : 80
@author : Sandeep Gupta
@time : 5 October 2020, 18:30
@Solution: Used decimal python module to calculate the decimal
places up to 100, the most important thing would be take calculate
a few extra places for decimal otherwise there will be rounding
error.
@answer : 40886
"""
import decimal


def solution() -> int:
answer = 0
dot100 = decimal.Context(prec=105)
for i in range(2, 100):
number = decimal.Decimal(i)
sqrt_number = number.sqrt(dot100)
if len(str(sqrt_number)) > 1:
answer += int(str(sqrt_number)[0])
sqrt_number = str(sqrt_number)[2:101]
answer += sum([int(x) for x in sqrt_number])
return answer


if __name__ == "__main__":
import doctest

doctest.testmod()
print(solution())