Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
problem 30, safeguard in new-problem.py
- Loading branch information
Showing
6 changed files
with
45 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os, sys | ||
sys.path.append(os.getcwd()) | ||
|
||
def main(): | ||
sequence = set([]) | ||
for a in range(2,101): | ||
for b in range(2,101): | ||
sequence.add(a**b) | ||
return len(sequence) | ||
|
||
if __name__=='__main__': | ||
print(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os, sys | ||
sys.path.append(os.getcwd()) | ||
|
||
def main(): | ||
# note that 9^5 = 59,049. So the maximum sum of digits to the fifth power, | ||
# for a four-digit number, for example, is 4 * 9^5 = 236,196. For a seven-digit | ||
# number, however, 7 * 9^5 = 413,343, which is smaller than the smallest seven-digit number. | ||
# so this suggests we only need to check through the six-digit-numbers, where | ||
# the largest possible such number is 6 * 9^5 = 354,294. | ||
|
||
accumulator = 0 | ||
# start the range at 10. according to the problem, single-digit numbers do not create sums, | ||
# which i disagree with, but so be it. | ||
for i in range(10, 354295): | ||
fifth_digit_sum = sum(int(c)**5 for c in str(i)) | ||
if fifth_digit_sum == i: | ||
accumulator += i | ||
|
||
return accumulator | ||
|
||
if __name__=='__main__': | ||
print(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/python3 | ||
|
||
import os, sys | ||
sys.path.append(os.getcwd()) | ||
|
||
def main(): | ||
|
||
if __name__=='__main__': | ||
print(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters