Skip to content

Commit

Permalink
problem 30, safeguard in new-problem.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Datamine committed Feb 1, 2017
1 parent 1294302 commit a4c1164
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
3 changes: 0 additions & 3 deletions Problems/028/solution.py
@@ -1,8 +1,5 @@
#!/usr/bin/python3

import os, sys
sys.path.append(os.getcwd())

def main():
# think of the spiral as a set of nested squares, where the side length grows
# o-n every level by two (one integer on each side). then we try to capture all
Expand Down
8 changes: 5 additions & 3 deletions Problems/029/solution.py
@@ -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())
24 changes: 24 additions & 0 deletions Problems/030/solution.py
@@ -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())
9 changes: 9 additions & 0 deletions Problems/031/solution.py
@@ -0,0 +1,9 @@
#!/usr/bin/python3

import os, sys
sys.path.append(os.getcwd())

def main():

if __name__=='__main__':
print(main())
6 changes: 5 additions & 1 deletion confirm-solutions.py
Expand Up @@ -36,7 +36,11 @@
"023": 4179871,
"024": "2783915460",
"025": 4782,
"026": 983
"026": 983,
"027": -59231,
"028": 669171001,
"029": 9183,
"030": 443839,

}

Expand Down
2 changes: 2 additions & 0 deletions new-problem.py
Expand Up @@ -6,6 +6,8 @@

if not os.path.exists(new_problem):
os.mkdir(new_problem)
else:
raise IOError("Error! Path `{}` already exists. Exiting.".format(new_problem))

filetext = ["#!/usr/bin/python3\n", "\n", "import os, sys\n", "sys.path.append(os.getcwd())\n",
"\n", "def main():\n", "\n", "if __name__=='__main__':\n", " print(main())\n"]
Expand Down

0 comments on commit a4c1164

Please sign in to comment.