Data update
This commit is contained in:
parent
0df55f9f24
commit
aec8ed51b6
1045 changed files with 18889 additions and 2777 deletions
|
|
@ -0,0 +1,53 @@
|
|||
import sat, util.
|
||||
|
||||
main([File]) =>
|
||||
Lines = read_file_lines(File),
|
||||
Dim = Lines.len(),
|
||||
Board = new_array(Dim, Dim),
|
||||
Max = Dim*Dim,
|
||||
Board :: 1..Max,
|
||||
Bvars = Board.vars(),
|
||||
all_different(Bvars),
|
||||
|
||||
foreach ( R in 1..Dim )
|
||||
Line = Lines[R].split(),
|
||||
if( Line.len() != Dim ) then
|
||||
printf("Line %d too short or too long, failing\n", R),
|
||||
abort
|
||||
end,
|
||||
foreach ( C in 1..Dim ) % empty cell: _ or 0
|
||||
if ( Line[C] != ['_'] ) then % data as 49 _ _ 32 _ _...
|
||||
Num = Line[C].to_int(),
|
||||
if ( Num != 0 ) then % data as 0 11 12 15 18...
|
||||
Board[R,C] #= Num
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
||||
% each cell but that with value 1 must be +1 larger then one of its neighbours
|
||||
% some numbrix puzzles do not have min and/or max values,
|
||||
% but this method works for all cases
|
||||
foreach ( R in 1..Dim, C in 1..Dim )
|
||||
Nei = [(R1,C1) : (R1, C1) in [(R-1,C), (R,C+1), (R+1,C), (R,C-1)],
|
||||
between(1, Dim, R1), between(1, Dim, C1)],
|
||||
Consnei = [ Board[R,C] #= Board[R1,C1] + 1 : (R1,C1) in Nei ],
|
||||
Board[R,C] #!= 1 #=> sum(Consnei) #= 1
|
||||
end,
|
||||
|
||||
time2(solve(Bvars)),
|
||||
printboard(Board).
|
||||
|
||||
printboard(A) =>
|
||||
N = A.len,
|
||||
nl,
|
||||
foreach ( I in 1..N )
|
||||
foreach ( J in 1..A[I].len )
|
||||
if ( A[I,J] == 0 ) then
|
||||
printf(" ")
|
||||
else
|
||||
printf("%4w", A[I,J])
|
||||
end
|
||||
end,
|
||||
nl
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue