changeset 218:35a38b49b5cd

example: heavily updated while-loop Getting close to PySMCL code!
author Sigurd Meldgaard <stm@daimi.au.dk>
date Wed, 23 Dec 2009 14:33:31 +0100
parents 121f28df6811
children 1683fdd52828
files examples/while-loop.py
diffstat 1 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/examples/while-loop.py	Wed Dec 23 14:32:20 2009 +0100
+++ b/examples/while-loop.py	Wed Dec 23 14:33:31 2009 +0100
@@ -1,8 +1,9 @@
+from pysmcl.functions import get
 from pysmcl.ideal_functionality import ideal_functionality
-
+from pysmcl.functions import precondition
 
-@ideal_functionality(range={'bids': (0,4)})
-def auction(bids):
+@ideal_functionality(range={'bids': (-4,4)})
+def search(bids):
     precondition("a >= b <=> bids[a] >= bids[b]")
     precondition("0 >= bids[0]")
     precondition("bids[len(bids)-1] >= 0")
@@ -10,10 +11,20 @@
     high = len(bids)
     while(low < high):
         mid = (low + high) // 2
-        r = open(bids[mid] >= 0)
+        r = output(bids[mid] >= 0)
         if r:
             high = mid
         else:
             low = mid+1
     result(mid)
     return mid
+
+@ideal_functionality()
+def main():
+    bids = [0] * 100
+    for i in range(100):
+        bids1 = get("Buy at price: " + str(i), 1, (0,2))
+        bids2 = get("Sell at price: " + str(i), 2, (0,2))
+        bids[i] = bids1[i] - bids2[i]
+    a = search(bids)
+    print "Market clearing price: " + str(a)