Skip to content

Commit 9714aa3

Browse files
authored
Merge pull request #213 from Thejus-Paul/master
Problem 16 Added
2 parents 777d947 + 0337441 commit 9714aa3

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

Diff for: Project Euler/Problem 16/sol1.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
power = int(input("Enter the power of 2: "))
2+
num = 2**power
3+
4+
string_num = str(num)
5+
6+
list_num = list(string_num)
7+
8+
sum_of_num = 0
9+
10+
print("2 ^",power,"=",num)
11+
12+
for i in list_num:
13+
sum_of_num += int(i)
14+
15+
print("Sum of the digits are:",sum_of_num)

Diff for: Project Euler/Problem 20/sol1.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Finding the factorial.
2+
def factorial(n):
3+
fact = 1
4+
for i in range(1,n+1):
5+
fact *= i
6+
return fact
7+
8+
# Spliting the digits and adding it.
9+
def split_and_add(number):
10+
sum_of_digits = 0
11+
while(number>0):
12+
last_digit = number % 10
13+
sum_of_digits += last_digit
14+
number = int(number/10) # Removing the last_digit from the given number.
15+
return sum_of_digits
16+
17+
# Taking the user input.
18+
number = int(input("Enter the Number: "))
19+
20+
# Assigning the factorial from the factorial function.
21+
factorial = factorial(number)
22+
23+
# Spliting and adding the factorial into answer.
24+
answer = split_and_add(factorial)
25+
26+
# Printing the answer.
27+
print(answer)

Diff for: Project Euler/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ PROBLEMS:
4949
Using the rule above and starting with 13, we generate the following sequence:
5050
13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
5151
Which starting number, under one million, produces the longest chain?
52+
53+
16. 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
54+
What is the sum of the digits of the number 2^1000?
55+
20. n! means n × (n − 1) × ... × 3 × 2 × 1
56+
For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
57+
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
58+
Find the sum of the digits in the number 100!

0 commit comments

Comments
 (0)