I don't think my prediction market code is right master
authorZack M. Davis <ultimatelyuntruethought@gmail.com>
Sun, 13 Oct 2024 06:32:37 +0000 (23:32 -0700)
committerZack M. Davis <ultimatelyuntruethought@gmail.com>
Sun, 13 Oct 2024 06:32:37 +0000 (23:32 -0700)
content/drafts/prediction-markets-are-not-a-drop-in-replacement-for-concepts.md

index e0f77bf..3e146cc 100644 (file)
@@ -34,37 +34,65 @@ Your teammate objects to the idea of moving elements based on whether they're gr
 
 ````
 from math import log2
-import prediction markets
+import prediction_markets
+
 
 def prediction_market_sort(my_list):
     n = len(my_list)
+    op_count = 0
     op_budget = n * log2(n)
-    is_sorted = prediction_markets.create("Is the list sorted?", data=my_list, options=[True, False])
+    is_sorted_market = prediction_markets.create(
+        "Is the list sorted?", dynamic_data=my_list
+    )
 
     markets_to_resolve = []
 
-    while not is_sorted:
-
-        if is_sorted
-
-
-        next_comparison = prediction_markets.create(
-            f"Will the list be sorted with no more than {op_budget} comparisons, if the"
-            "next comparision is between these indicies?",
-            data=my_list,
-            options=[(i, j) for i in range(n) for j in range(i, n) if i != j]
-        )
-        i, j = next_comparison.leading
-        should_swap = prediction_markets.create(
+    while is_sorted_market.probability < 0.95:
+        next_comparison_markets = {
+            (i, j): prediction_markets.create(
+                f"Will the list be sorted with no more than {op_budget} comparisons, if the"
+                f"next comparision is between indicies {i} and {j}?",
+                static_data=my_list,
+            )
+            for i in range(n)
+            for j in range(i, n)
+            if i != j
+        }
+
+        next_comparison = max(
+            next_comparison_markets.items(), key=lambda m: m[1].probability
+        )[0]
+
+        for comparison, market in next_comparison_markets.items():
+            if comparison != next_comparison:
+                market.cancel()
+            else:
+                markets_to_resolve.append(market)
+
+        i, j = next_comparison
+
+        should_swap_market = prediction_markets.create(
             f"Will the list be sorted with no more than {op_budget} comparisons, if we swap"
             f"the elements at indices {i} and {j}?",
-            data=my_list,
-            options=[True, False]
+            static_data=my_list,
         )
-        if should_swap.resolution:
+        if should_swap_market.probability > 0.5:
             temp = my_list[i]
             my_list[i] = my_list[j]
             my_list[j] = temp
+
+            markets_to_resolve.append(should_swap_market)
+        else:
+            should_swap_market.cancel()
+
+        op_count += 1
+
+    is_sorted_market.resolve(True)
+
+    for market in markets_to_resolve:
+        market.resolve(op_count <= op_budget)
+
+    return my_list
 ```
 
 "No," you say.