From 215e2ab07085146d9cae7d4950e45e990307bcf5 Mon Sep 17 00:00:00 2001 From: Jason Axelson Date: Sun, 19 Jun 2011 09:19:32 -1000 Subject: [PATCH] Add ability to get any numeric value into any slot --- python/src/icfp.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/python/src/icfp.py b/python/src/icfp.py index 7291eb5..a7adb18 100644 --- a/python/src/icfp.py +++ b/python/src/icfp.py @@ -97,3 +97,66 @@ def k2(slot): print "2" print slot 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