Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ability to get any numeric value into any slot

  • Loading branch information...
commit 215e2ab07085146d9cae7d4950e45e990307bcf5 1 parent d6cf8d1
@axelson axelson authored
Showing with 63 additions and 0 deletions.
  1. +63 −0 python/src/icfp.py
View
63 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
Please sign in to comment.
Something went wrong with that request. Please try again.