Skip to content

Commit

Permalink
Add ability to get any numeric value into any slot
Browse files Browse the repository at this point in the history
  • Loading branch information
axelson committed Jun 19, 2011
1 parent d6cf8d1 commit 215e2ab
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions python/src/icfp.py
Expand Up @@ -97,3 +97,66 @@ def k2(slot):
print "2" print "2"
print slot print slot
print "K" print "K"

# Get the value num into slot slot
def buildNum(slot, num):
if(num == 0):
zero2(slot)
return

if(num == 1):
zero2(slot)
succ1(slot)
return

if((num % 2) == 0):
buildNum(slot, num/2)
dbl1(slot)
else:
buildNum(slot, num/2)
dbl1(slot)
succ1(slot)


def build(num):
if(num == 0):
print "0"
return

if(num == 1):
print "0"
print "1"
return

if((num % 2) == 0):
build(num/2)
print num
else:
build(num/2)
print num - 1
print num


#def notes():
# 5 = 0 1 2 4 5
# 5 = zero succ dbl dbl succ
# 7 = 0 1 2 4 5 6 7
# 7 = 0 1 2 3 6 7
# 8 = 0 1 2 4 8
# 9 = 0 1 2 4 9
# 10 = 0 1 2 4 8 9 10
# 10 = 0 1 2 3 6 8 9 10
# 10 = 0 1 2 4 5 10
# 10 = build(5) build(2) build(1)
# 12 = 0 1 2 4 8 9 10 11 12
# 12 = 0 1 2 3 6 12
# # devide by 2, round down (build that num) count up
# 13 = 0 1 2 4 8 9 10 11 12 13
# 13 = 0 1 2 3 6 12 13
# 13 = build(6) build(3) build(1)
# 14 = 0 1 2 3 6 12 13 14
# 14 = 0 1 2 3 6 7 14
# 14 = build(7) build(3) build(1)
# 16 = 0 1 2 4 8 16
# 16 = build(8) build(4) build(2) build(1)
# 21 = 0 1 2 4 5 10 20 21

0 comments on commit 215e2ab

Please sign in to comment.