Skip to content

Commit

Permalink
fix: new data processing in nonogram
Browse files Browse the repository at this point in the history
  • Loading branch information
T0nyX1ang committed Mar 22, 2024
1 parent 5027fb3 commit 36d85fb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
4 changes: 2 additions & 2 deletions solvers/nonogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def solve(E: Encoding) -> List:

top_clues = {}
for c in E.top:
top_clues[c] = tuple(int(clue) if clue != "?" else "?" for clue in E.top[c].split())
top_clues[c] = tuple(int(clue) if clue != "?" else "?" for clue in E.top[c])

left_clues = {}
for r in E.left:
left_clues[r] = tuple(int(clue) if clue != "?" else "?" for clue in E.left[r].split())
left_clues[r] = tuple(int(clue) if clue != "?" else "?" for clue in E.left[r])

solver.reset()
solver.add_program_line(f"grid(-1..{E.R}, -1..{E.C}).")
Expand Down
54 changes: 27 additions & 27 deletions static/noq/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3420,40 +3420,40 @@ const examples = {
data: {
param_values: { r: "4", c: "4" },
grid: {
"-1,1": "? ?",
"-1,3": "? ?",
"-1,5": "? 1",
"-1,7": "1 2",
"1,-1": "? ?",
"3,-1": "?",
"5,-1": "1 1",
"7,-1": "? ?",
"-1,1": ["?", "?"],
"-1,3": ["?", "?"],
"-1,5": ["?", "1"],
"-1,7": ["1", "2"],
"1,-1": ["?", "?"],
"3,-1": ["?"],
"5,-1": ["1", "1"],
"7,-1": ["?", "?"],
},
},
},
2: {
data: {
param_values: { r: "11", c: "8" },
grid: {
"-1,1": "0",
"-1,3": "9",
"-1,5": "9",
"-1,7": "2 2",
"-1,9": "2 2",
"-1,11": "4",
"-1,13": "4",
"-1,15": "0",
"1,-1": "0",
"3,-1": "4",
"5,-1": "6",
"7,-1": "2 2",
"9,-1": "2 2",
"11,-1": "6",
"13,-1": "4",
"15,-1": "2",
"17,-1": "2",
"19,-1": "2",
"21,-1": "0",
"-1,1": ["0"],
"-1,3": ["9"],
"-1,5": ["9"],
"-1,7": ["2", "2"],
"-1,9": ["2", "2"],
"-1,11": ["4"],
"-1,13": ["4"],
"-1,15": ["0"],
"1,-1": ["0"],
"3,-1": ["4"],
"5,-1": ["6"],
"7,-1": ["2", "2"],
"9,-1": ["2", "2"],
"11,-1": ["6"],
"13,-1": ["4"],
"15,-1": ["2"],
"17,-1": ["2"],
"19,-1": ["2"],
"21,-1": ["0"],
},
},
link: "https://en.wikipedia.org/wiki/Nonogram",
Expand Down
13 changes: 10 additions & 3 deletions static/noq/elves.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,14 @@ class NonogramElf extends DirectSum(
this.curr_clue = "";
}

if ("1234567890?".includes(key)) this.curr_clue += key;
if ("1234567890?".includes(key))
if (
this.curr_clue.includes("?") ||
key === "?" ||
this.curr_clue.length > 1
)
this.curr_clue = key;
else this.curr_clue += key;

// resize extender dimension for all siblings, as needed
let max_size = Math.max(1, this.true_num_clues());
Expand All @@ -1107,7 +1114,7 @@ class NonogramElf extends DirectSum(
if (this.curr_clue != "") this.clues.pop();
}
load_example(str) {
this.clues = str.split(" ");
this.clues = str;
this.curr_clue = "";

let max_size = Math.max(1, this.true_num_clues());
Expand All @@ -1129,7 +1136,7 @@ class NonogramElf extends DirectSum(
this.clues.push(this.curr_clue);
this.curr_clue = "";
}
return this.clues.length == 0 ? null : this.clues.join(" ");
return this.clues.length == 0 ? null : this.clues;
}
}

Expand Down

0 comments on commit 36d85fb

Please sign in to comment.