tzurshubi commited on
Commit
67f9ca2
·
verified ·
1 Parent(s): 7411d4c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -4
app.py CHANGED
@@ -126,6 +126,22 @@ def classify_path(path, d: int):
126
  return "snake", True
127
 
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  def hamming_dist(a: int, b: int) -> int:
130
  x, c = a ^ b, 0
131
  while x:
@@ -793,10 +809,11 @@ def path_info(d, path):
793
  if not path:
794
  return html.Span("Path: (empty)")
795
 
 
796
  path_str = ", ".join(str(v) for v in path)
797
 
 
798
  label, valid = classify_path(path, d)
799
-
800
  color = {
801
  "snake": "green",
802
  "coil": "green",
@@ -804,9 +821,27 @@ def path_info(d, path):
804
  "not snake": "red",
805
  }[label]
806
 
807
- return html.Span([
808
- html.Span(f"Path: {path_str} "),
809
- html.Span(f"[{label}]", style={"color": color, "fontWeight": "bold"}),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810
  ])
811
 
812
 
 
126
  return "snake", True
127
 
128
 
129
+ def edge_dimension(a: int, b: int) -> int | None:
130
+ """
131
+ Return the dimension index of the edge (a,b) if they are adjacent,
132
+ otherwise return None.
133
+ """
134
+ x = a ^ b
135
+ if x == 0 or (x & (x - 1)) != 0:
136
+ # either same vertex or differ in more than one bit
137
+ return None
138
+ dim = 0
139
+ while x > 1:
140
+ x >>= 1
141
+ dim += 1
142
+ return dim
143
+
144
+
145
  def hamming_dist(a: int, b: int) -> int:
146
  x, c = a ^ b, 0
147
  while x:
 
809
  if not path:
810
  return html.Span("Path: (empty)")
811
 
812
+ # Vertex list
813
  path_str = ", ".join(str(v) for v in path)
814
 
815
+ # Classification
816
  label, valid = classify_path(path, d)
 
817
  color = {
818
  "snake": "green",
819
  "coil": "green",
 
821
  "not snake": "red",
822
  }[label]
823
 
824
+ # Dimensions of consecutive edges
825
+ dims = []
826
+ for i in range(len(path) - 1):
827
+ dim = edge_dimension(path[i], path[i + 1])
828
+ if dim is not None:
829
+ dims.append(dim)
830
+ else:
831
+ # non adjacent step, keep something explicit
832
+ dims.append("?")
833
+
834
+ dims_str = ", ".join(str(x) for x in dims) if dims else "(none)"
835
+
836
+ return html.Div([
837
+ html.Div([
838
+ html.Span(f"Path: {path_str} "),
839
+ html.Span(f"[{label}]", style={"color": color, "fontWeight": "bold"}),
840
+ ]),
841
+ html.Div([
842
+ html.Span("Dimensions: "),
843
+ html.Span(dims_str, style={"fontFamily": "monospace"}),
844
+ ]),
845
  ])
846
 
847