mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Rename Project Euler directories and other dependent changes (#3300)
* Rename all Project Euler directories: Reason: The change was done to maintain consistency throughout the directory and to keep all directories in sorted order. Due to the above change, some config files had to be modified: 'problem_22` -> `problem_022` * Update scripts to pad zeroes in PE directories
This commit is contained in:
0
project_euler/problem_080/__init__.py
Normal file
0
project_euler/problem_080/__init__.py
Normal file
37
project_euler/problem_080/sol1.py
Normal file
37
project_euler/problem_080/sol1.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Project Euler Problem 80: https://projecteuler.net/problem=80
|
||||
Author: Sandeep Gupta
|
||||
Problem statement: For the first one hundred natural numbers, find the total of
|
||||
the digital sums of the first one hundred decimal digits for all the irrational
|
||||
square roots.
|
||||
Time: 5 October 2020, 18:30
|
||||
"""
|
||||
import decimal
|
||||
|
||||
|
||||
def solution() -> int:
|
||||
"""
|
||||
To evaluate the sum, 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.
|
||||
|
||||
>>> solution()
|
||||
40886
|
||||
"""
|
||||
answer = 0
|
||||
decimal_context = decimal.Context(prec=105)
|
||||
for i in range(2, 100):
|
||||
number = decimal.Decimal(i)
|
||||
sqrt_number = number.sqrt(decimal_context)
|
||||
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()
|
||||
Reference in New Issue
Block a user