Update app.py
Browse files
app.py
CHANGED
|
@@ -228,6 +228,34 @@ def longest_cib(d: int):
|
|
| 228 |
return seq
|
| 229 |
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
def parse_path(text: str, d: int) -> List[int]:
|
| 233 |
if not text:
|
|
@@ -484,7 +512,7 @@ app.layout = html.Div(
|
|
| 484 |
html.Button("Longest CIB", id="btn_longest_cib", n_clicks=0,
|
| 485 |
style={"background": "#059669", "color": "white"}),
|
| 486 |
html.Button("Shorter CIB", id="btn_shorter_cib", n_clicks=0,
|
| 487 |
-
style={"background": "#FFFF00"
|
| 488 |
html.Button("Clear", id="btn_clear", n_clicks=0),
|
| 489 |
]
|
| 490 |
),
|
|
@@ -573,6 +601,7 @@ def stats(d, path):
|
|
| 573 |
Input("fig", "clickData"),
|
| 574 |
Input("btn_clear", "n_clicks"),
|
| 575 |
Input("btn_longest_cib", "n_clicks"),
|
|
|
|
| 576 |
Input("btn_set", "n_clicks"),
|
| 577 |
Input("btn_swap", "n_clicks"),
|
| 578 |
Input("btn_flip", "n_clicks"),
|
|
@@ -605,10 +634,14 @@ def update_path(clickData,
|
|
| 605 |
if trigger == "btn_clear":
|
| 606 |
return []
|
| 607 |
|
| 608 |
-
#
|
| 609 |
if trigger == "btn_longest_cib":
|
| 610 |
return longest_cib(d)
|
| 611 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 612 |
# 3) Manual set path
|
| 613 |
if trigger == "btn_set":
|
| 614 |
newp = parse_path(manual_text or "", d)
|
|
|
|
| 228 |
return seq
|
| 229 |
|
| 230 |
|
| 231 |
+
def shorter_cib(d: int):
|
| 232 |
+
"""
|
| 233 |
+
Return a predefined coil/snake for certain dimensions,
|
| 234 |
+
otherwise fall back to a standard Gray-code path.
|
| 235 |
+
"""
|
| 236 |
+
presets = {
|
| 237 |
+
2: [0, 1, 3, 2, 0],
|
| 238 |
+
3: [0, 1, 3, 7, 6, 4, 0],
|
| 239 |
+
4: [0, 1, 3, 7, 6, 4, 0],
|
| 240 |
+
5: [0, 1, 3, 7, 6, 14, 12, 13, 29, 21, 20, 16, 0],
|
| 241 |
+
6: [0, 1, 3, 7, 15, 31, 29, 25, 24, 26, 10, 42, 43, 59, 51, 49, 53, 37, 45, 44, 60, 62, 54, 22, 20, 4, 0],
|
| 242 |
+
7: [0, 1, 3, 7, 15, 13, 12, 28, 30, 26, 27, 25, 57, 56, 40, 104, 72, 73, 75, 107, 111, 110, 46, 38, 36, 52,116, 124, 125, 93, 95, 87, 119, 55, 51, 50, 114, 98, 66, 70, 68, 69, 101, 97, 113, 81, 80, 16, 0],
|
| 243 |
+
8: [0, 1, 3, 7, 6, 14, 12, 13, 29, 31, 27, 26, 18, 50, 54, 62, 60, 56, 57, 49, 53, 37, 101, 69, 68, 196, 132, 133, 149, 151, 150, 158, 156, 220, 92, 94, 86, 87, 119, 115, 123, 122, 250, 254, 255, 191, 187, 179, 163, 167, 231, 230, 226, 98, 66, 74, 202, 200, 136, 137, 139, 143, 207, 205, 237, 173, 172, 174, 170, 42, 43, 47, 111, 110, 108, 104, 105, 73, 89, 217, 219, 211, 195, 193, 225, 241, 245, 244, 116, 112, 80, 208, 144, 176, 160, 32, 0],
|
| 244 |
+
}
|
| 245 |
+
|
| 246 |
+
if d in presets:
|
| 247 |
+
return presets[d][:] # copy, so we don't mutate the original
|
| 248 |
+
|
| 249 |
+
return [0]
|
| 250 |
+
# Fallback: Gray-code Hamiltonian path for other dimensions
|
| 251 |
+
n = 1 << d
|
| 252 |
+
seq = []
|
| 253 |
+
for i in range(n):
|
| 254 |
+
g = i ^ (i >> 1)
|
| 255 |
+
seq.append(g)
|
| 256 |
+
return seq
|
| 257 |
+
|
| 258 |
+
|
| 259 |
|
| 260 |
def parse_path(text: str, d: int) -> List[int]:
|
| 261 |
if not text:
|
|
|
|
| 512 |
html.Button("Longest CIB", id="btn_longest_cib", n_clicks=0,
|
| 513 |
style={"background": "#059669", "color": "white"}),
|
| 514 |
html.Button("Shorter CIB", id="btn_shorter_cib", n_clicks=0,
|
| 515 |
+
style={"background": "#FFFF00"}),
|
| 516 |
html.Button("Clear", id="btn_clear", n_clicks=0),
|
| 517 |
]
|
| 518 |
),
|
|
|
|
| 601 |
Input("fig", "clickData"),
|
| 602 |
Input("btn_clear", "n_clicks"),
|
| 603 |
Input("btn_longest_cib", "n_clicks"),
|
| 604 |
+
Input("btn_shorter_cib", "n_clicks"),
|
| 605 |
Input("btn_set", "n_clicks"),
|
| 606 |
Input("btn_swap", "n_clicks"),
|
| 607 |
Input("btn_flip", "n_clicks"),
|
|
|
|
| 634 |
if trigger == "btn_clear":
|
| 635 |
return []
|
| 636 |
|
| 637 |
+
# 2a) Longest CIB
|
| 638 |
if trigger == "btn_longest_cib":
|
| 639 |
return longest_cib(d)
|
| 640 |
|
| 641 |
+
# 2b) Shorter CIB
|
| 642 |
+
if trigger == "btn_longest_cib":
|
| 643 |
+
return shorter_cib(d)
|
| 644 |
+
|
| 645 |
# 3) Manual set path
|
| 646 |
if trigger == "btn_set":
|
| 647 |
newp = parse_path(manual_text or "", d)
|