summaryrefslogtreecommitdiff
path: root/day1
diff options
context:
space:
mode:
Diffstat (limited to 'day1')
-rw-r--r--day1/exercise/arms.py18
-rwxr-xr-xday1/exercise/lister.py13
-rw-r--r--day1/exercise/x.py19
3 files changed, 50 insertions, 0 deletions
diff --git a/day1/exercise/arms.py b/day1/exercise/arms.py
new file mode 100644
index 0000000..33196fd
--- /dev/null
+++ b/day1/exercise/arms.py
@@ -0,0 +1,18 @@
+# Armstrong Numbers
+
+for n in range(100, 1000):
+# s = str(n)
+# a, b, c = int(s[0]), int(s[1]), int(s[2])
+# if a * a * a + b * b * b + c * c * c == n:
+# print n
+# sum, copy = 0, n
+# while copy > 0:
+# sum += (copy % 10) ** 3
+# copy /= 10
+# if sum == n:
+# print n
+ u = n % 10
+ h = n / 100
+ t = (n/10) % 10
+ if h ** 3 + t ** 3 + u ** 3 == N:
+ print n
diff --git a/day1/exercise/lister.py b/day1/exercise/lister.py
new file mode 100755
index 0000000..9124bf7
--- /dev/null
+++ b/day1/exercise/lister.py
@@ -0,0 +1,13 @@
+s = "1, 3-7, 12, 15, 18-21"
+answer = []
+single = "answer.append( %s )"
+many = "answer.extend(range(%s))"
+COMMA = ','
+MINUS = '-'
+for p in s.split(COMMA):
+ if MINUS not in p:
+ eval( single % (p) )
+ else:
+ p = p.replace( MINUS, COMMA) + '+ 1 '
+ eval( many % (p) )
+print answer
diff --git a/day1/exercise/x.py b/day1/exercise/x.py
new file mode 100644
index 0000000..0b073db
--- /dev/null
+++ b/day1/exercise/x.py
@@ -0,0 +1,19 @@
+d1 = [2,4,6,8]
+d0 = [0,2,4,6,8]
+dq = [0, 4, 6]
+
+for a in d1:
+ th = a * 1000
+ for b in d0:
+ hu = b * 100
+ for c in d0:
+ te = c * 10
+ for u in dq:
+ n = th + hu + te + u
+ if is_square(n): print n
+
+
+for i in range(46, 94, 2):
+ n = i * i
+ if all_even( n ): print n
+