Data update

This commit is contained in:
Ingy döt Net 2024-11-04 20:28:54 -08:00
parent 52a6ef48dd
commit 157b70a810
604 changed files with 14253 additions and 2100 deletions

View file

@ -1,4 +1,6 @@
templates queens
data done <=1> local
def n: $;
templates getRowColumn
when <?($@queens.freeRows($.r::raw) <=0>)> do 0 !
@ -14,8 +16,6 @@ templates queens
@queens.freeMins($p.c::raw - $p.r::raw + $n): $p.val::raw;
end setRowColumn
data done <=1>
templates placeQueen
def c: $;
row´1 -> #

View file

@ -0,0 +1,52 @@
queens templates
done requires <|=1>
failed requires <|=0>
n is $;
getRowColumn templates
when <|?($@queens(freeRows:; $(r:)::raw) matches <|=0>)> do 0 !
when <|?($@queens(freeMaxs:; $(r:)::raw + $(c:)::raw) matches <|=0>)> do 0 !
when <|?($@queens(freeMins:; $(c:)::raw - $(r:)::raw + $n) matches <|=0>)> do 0 !
otherwise 1!
end getRowColumn
setRowColumn sink
p is $;
@queens(freeRows:; $p(r:)::raw) set $p(val:)::raw;
@queens(freeMaxs:; $p(c:)::raw + $p(r:)::raw) set $p(val:)::raw;
@queens(freeMins:; $p(c:)::raw - $p(r:)::raw + $n) set $p(val:)::raw;
end setRowColumn
placeQueen templates
{c: $, r: 1} -> # !
when <|done> do done´1!
when <|{c: <|$n + 1..>}> do done´1!
when <|{r: <|$n + 1..>}> do failed´0 !
when <|?($ -> getRowColumn matches <|=1>)> do
current is $;
@queens(queenRows:; $(r:)::raw) set $(c:);
{$, val: 0} -> !setRowColumn
{c: $(c:)::raw + 1, r: 1} -> # -> templates
when <|done> do done´1!
otherwise
{$current, val: 1} -> !setRowColumn
{c: $current(c:), r: $current(r:)::raw + 1} !
end -> # !
otherwise {c: $(c:), r: $(r:)::raw + 1} -> # !
end placeQueen
@ set { freeRows: [1..$n -> 1],
freeMaxs: [1..$n*2 -> 1],
freeMins: [1..$n*2 -> 1],
queenRows: [1..$n -> -1] };
1 -> placeQueen -> templates
when <|done> do $@queens(queenRows:) !
otherwise 'non-existent'!
end!
end queens
'A solution to the 8 queens problem is $:8 -> queens;
' !
'A solution to the 4 queens problem is $:4 -> queens;
' !
'A solution to the 3 queens problem is $:3 -> queens;
' !