Skip to content

Commit cf6ef9f

Browse files
authored
Fix deserializer for Lohkous (#280)
1 parent a469cab commit cf6ef9f

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

cspuz_rs_puzzles/src/puzzles/lohkous.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub fn deserialize_problem(url: &str) -> Option<Problem> {
117117
let mut ret = vec![vec![None; w]; h];
118118

119119
let mut i = 0;
120+
let mut cont = false;
120121
while i < body.len() {
121122
if idx >= w * h {
122123
return None;
@@ -137,13 +138,15 @@ pub fn deserialize_problem(url: &str) -> Option<Problem> {
137138
}
138139
ret[idx / w][idx % w] = Some(clues);
139140
idx += 1;
141+
cont = false;
140142
} else {
141143
let mut s = (body[i] - b'a') as usize;
142-
if i == 0 || i + 1 == body.len() {
144+
if i == 0 || i + 1 == body.len() || cont {
143145
s += 1;
144146
}
145147
idx += s;
146148
i += 1;
149+
cont = true;
147150
}
148151
}
149152

@@ -154,7 +157,7 @@ pub fn deserialize_problem(url: &str) -> Option<Problem> {
154157
mod tests {
155158
use super::*;
156159

157-
fn problem_for_tests() -> Problem {
160+
fn problem_for_tests1() -> Problem {
158161
// https://puzz.link/p?lohkous/6/6/12k2a23b2k13d13a10b14d
159162
let mut problem: Vec<Vec<Option<Vec<i32>>>> = vec![vec![None; 6]; 6];
160163
problem[0][0] = Some(vec![1, 2]);
@@ -168,10 +171,18 @@ mod tests {
168171
problem
169172
}
170173

174+
fn problem_for_tests2() -> Problem {
175+
// https://pzprxs.vercel.app/p?lohkous/8/8/a48zzf48e
176+
let mut problem: Vec<Vec<Option<Vec<i32>>>> = vec![vec![None; 8]; 8];
177+
problem[0][1] = Some(vec![4, 8]);
178+
problem[7][3] = Some(vec![4, 8]);
179+
problem
180+
}
181+
171182
#[test]
172183
#[rustfmt::skip]
173184
fn test_lohkous_problem() {
174-
let problem = problem_for_tests();
185+
let problem = problem_for_tests1();
175186

176187
let ans = solve_lohkous(&problem);
177188
assert!(ans.is_some());
@@ -199,8 +210,16 @@ mod tests {
199210

200211
#[test]
201212
fn test_lohkous_serializer() {
202-
let problem = problem_for_tests();
203-
let url = "https://puzz.link/p?lohkous/6/6/12k2a23b2k13d13a10b14d";
204-
assert_eq!(deserialize_problem(url).unwrap(), problem);
213+
{
214+
let problem = problem_for_tests1();
215+
let url = "https://puzz.link/p?lohkous/6/6/12k2a23b2k13d13a10b14d";
216+
assert_eq!(deserialize_problem(url).unwrap(), problem);
217+
}
218+
219+
{
220+
let problem = problem_for_tests2();
221+
let url = "https://pzprxs.vercel.app/p?lohkous/8/8/a48zzf48e";
222+
assert_eq!(deserialize_problem(url).unwrap(), problem);
223+
}
205224
}
206225
}

0 commit comments

Comments
 (0)