author | Puneeth Chaganti <punchagan@fossee.in> |
Thu, 21 Jan 2010 15:26:11 +0530 | |
changeset 358 | 162e3e453920 |
parent 355 | 6af6441034f9 |
permissions | -rw-r--r-- |
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 |