Exemple simple:
...
20 + 02 = 22 NON
21 + 12 = 33 OUI
22 + 22 = 44 NON
...
Et comme d'habitude, j'ai sorti l'ami Python, celui qui nous veut du bien.
#! /usr/bin/python
# Codechef Twitter Daily 2009/06/24
# How many numbers below 1000 which when added with their respective mirror images result in a number with entirely odd digits?
# 2009/06/24 - Jean Karim Bockstael - jkb@jkbockstael.be
def reverse_number(num):
return int(str(num)[::-1])
def is_all_odds(num):
for digit in str(num):
if (int(digit) % 2 == 0):
return False
return True
def count_mirrors(max):
n_mirrors = 0
for num in range(1, max):
if is_all_odds(num + reverse_number(num)):
n_mirrors += 1
return n_mirrors
print count_mirrors(1000)
0 comments:
Enregistrer un commentaire