day1/exercise/arms.py
author Prabhu Ramachandran <prabhu@aero.iitb.ac.in>
Sat, 19 Jun 2010 01:27:20 -0400
branchscipy2010
changeset 409 4442da6bf693
parent 355 6af6441034f9
permissions -rw-r--r--
ENH: Minor cleanup. Also added slide to introduce IPython's %timeit and %time.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
355
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
# Armstrong Numbers
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
for n in range(100, 1000):
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     4
#    s = str(n)
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     5
#    a, b, c = int(s[0]), int(s[1]), int(s[2])
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     6
#    if a * a * a + b * b * b + c * c * c == n:
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     7
#       print n
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     8
#   sum, copy = 0, n    
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     9
#   while copy > 0:
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    10
#       sum += (copy % 10) ** 3
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    11
#       copy /= 10
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
#   if sum == n:
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
#      print n
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
    u = n % 10
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
    h = n / 100
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    16
    t = (n/10) % 10
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
    if h ** 3 + t ** 3 + u ** 3 == N:
6af6441034f9 Added some solutions to exercises written during REC Chennai workshop.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
        print n