#acsl 1
#Gray
Stanton Phillips Exeter Academy Senior Div
for x
in range(0,5):
ratio = raw_input("Enter the two
integers with one space in between ")
evenWhorlStr=""
oddWhorlStr=""
ev=True
for c in ratio:
if c==" ":
ev=False
elif ev:
evenWhorlStr += c
else:
oddWhorlStr+= c
evenWhorl=int(evenWhorlStr)
oddWhorl=int(oddWhorlStr)
oddWhorlTable={1:9,2:7,4:5,8:3,16:1,}
ScorePoss=[16,8,4,2,1]
evenWhorlTable={1:10,2:8,4:6,8:4,16:2,}#<score:finger>
evenWhorl-=1
oddWhorl-=1 #eliminating the added one to
get the sum
#5! different possible combinations of
finger whorls
usedevenVals=[]
curscore=0
curval=0
whorl=evenWhorl
while curscore<whorl:
#tries adding from largest to smallest
until it can fit
if curscore==whorl: #done, exact number
of fingers
break
elif curval>4:
usedevenVals=[-1] # no solution
break
elif
curscore+ScorePoss[curval]<=whorl:
curscore+=ScorePoss[curval]
usedevenVals.append(ScorePoss[curval])
curval+=1
elif
curscore+ScorePoss[curval]>whorl:
curval+=1
whorl=oddWhorl
usedoddVals=[]
curscore=0
curval=0
while curscore<whorl:
#tries adding from largest to smallest
until it can fit
if curscore==whorl: #done, exact number
of fingers
break
if curval>4:
usedoddVals=[-1] # no solution
break
elif
curscore+ScorePoss[curval]<=whorl:
curscore+=ScorePoss[curval]
usedoddVals.append(ScorePoss[curval])
curval+=1
elif
curscore+ScorePoss[curval]>whorl:
curval+=1
print "Whorled Fingers:"
if usedoddVals != [-1]:
for x in usedoddVals:
print oddWhorlTable[x]
if usedevenVals != [-1]:
for x in usedevenVals:
print evenWhorlTable[x]
if usedevenVals == [-1] and usedoddVals ==
[-1] or evenWhorl<=0 and oddWhorl<=0:
print "None"