day1/exercise/arms.py
author Christopher Burns <chris.d.burns@gmail.com>
Tue, 29 Jun 2010 00:30:21 -0500
branchscipy2010
changeset 431 9126059d6b37
parent 355 6af6441034f9
permissions -rw-r--r--
DOC: Add slide about __module__ attribute.
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