Skip to content

Commit afda29f

Browse files
Fix sudoku exercise answer checking issues
Co-authored-by: andrewrosemberg <[email protected]>
1 parent 982c702 commit afda29f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Manifest.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
julia_version = "1.11.6"
4+
manifest_format = "2.0"
5+
project_hash = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
6+
7+
[deps]

class01/background_materials/optimization_basics.jl

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ begin
436436
[7 1 3 9 2 4 8 5 6];
437437
[9 6 1 5 3 7 2 8 4];
438438
[2 8 7 4 1 9 6 3 5];
439-
[3 4 5 2 8 6 1 7 9]])
439+
[3 4 5 2 8 6 1 7 9]],)
440440

441441
anss = missing
442442
try
@@ -447,8 +447,24 @@ begin
447447
anss = missing
448448
end
449449

450-
goods = !ismissing(anss) &&
451-
all(isapprox.(anss.x_ss, ground_truth_s.x_ss; atol=1e-3))
450+
# Convert 3D binary matrix to 2D solution matrix
451+
function convert_3d_to_solution(x_3d)
452+
if ismissing(x_3d)
453+
return missing
454+
end
455+
solution = zeros(Int, 9, 9)
456+
for i in 1:9, j in 1:9, k in 1:9
457+
if x_3d[i, j, k] 1.0
458+
solution[i, j] = k
459+
end
460+
end
461+
return solution
462+
end
463+
464+
solution_matrix = ismissing(anss) ? missing : convert_3d_to_solution(anss.x_ss)
465+
466+
goods = !ismissing(anss) && !ismissing(solution_matrix) &&
467+
all(isapprox.(solution_matrix, ground_truth_s.x_ss; atol=1e-3))
452468

453469
if ismissing(anss)
454470
still_missing()

0 commit comments

Comments
 (0)