Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Use your hands! solution in Uncategorized category for Funny Addition by Lucy
# migrated from python 2.7
import itertools as it
FINGERS = ['Thumb' , 'Index', 'Middle', 'Ring', 'Pinky']
def add_fingers(f1, f2):
return count_number_of_hands( FINGERS.index(f1) + FINGERS.index(f2) + 2)
def count_number_of_hands(x):
hands = 0
if x == 0:
return hands, None
for finger in it.cycle(FINGERS):
x -= 1
if x==0:
return hands, finger
if finger == 'Pinky':
hands += 1
finger = None
def checkio(data):
'The sum of two integer elements'
a, b = data
hands_a, finger_a = count_number_of_hands(a)
hands_b, finger_b = count_number_of_hands(b)
hands_res, finger_res = add_fingers(finger_a, finger_b)
if finger_res is not None:
res = FINGERS.index(finger_res) + 1
return 5*(hands_a + hands_b + hands_res) + res
if __name__ == '__main__':
assert checkio([5, 5]) == 10, 'First'
assert checkio([7,1]) == 8, 'Second'
print('All ok')
Dec. 19, 2012
Comments: