Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,28 @@
templates permutations
when <=1> do [1] !
otherwise
def n: $;
templates expand
def p: $;
1..$n -> \(def k: $;
[$p(1..$k-1)..., $n, $p($k..last)...] !\) !
end expand
$n - 1 -> permutations -> expand !
end permutations
templates index&{of:}
$ -> \[i](<=$of> $i! \) ...!
end index
def names: ['Baker', 'Cooper', 'Fletcher', 'Miller', 'Smith'];
5 -> permutations -> $names($)
-> \(<?($ -> index&{of: 'Baker'} <~=5>)> $! \)
-> \(<?($ -> index&{of: 'Cooper'} <~=1>)> $! \)
-> \(<?($ -> index&{of: 'Fletcher'} <~=1|=5>)> $! \)
-> \(<?($ -> index&{of: 'Cooper'} <..($ -> index&{of:'Miller'})>)> $! \)
-> \(<?(($ -> index&{of: 'Smith'}) - ($ -> index&{of:'Fletcher'}) <~=1|=-1>)> $! \)
-> \(<?(($ -> index&{of: 'Cooper'}) - ($ -> index&{of:'Fletcher'}) <~=1|=-1>)> $! \)
-> \[i]('$i;:$;$#10;' ! \)
-> $(last..first:-1)
-> '$...;$#10;' -> !OUT::write

View file

@ -0,0 +1,24 @@
// We add a zero to be able to express e.g. "not top floor"
def floors: [0..5 -> (floor:$)];
def names: [['Ground', 'Baker', 'Cooper', 'Fletcher', 'Miller', 'Smith']... -> (name:$)];
def dwellings: [$floors, $names] -> \(
def solver: $ -> EinsteinSolver;
{name: 'Ground', floor: 0} -> !solver::isFact
({name: 'Ground'} solver::nextTo&{byField: :(floor:), bMinusA: [1..4]} {name: 'Baker'}) -> !VOID
({name: 'Ground'} solver::nextTo&{byField: :(floor:), bMinusA: [2..5]} {name: 'Cooper'}) -> !VOID
({name: 'Ground'} solver::nextTo&{byField: :(floor:), bMinusA: [2..4]} {name: 'Fletcher'}) -> !VOID
({name: 'Cooper'} solver::nextTo&{byField: :(floor:), bMinusA: [1..4]} {name: 'Miller'}) -> !VOID
({name: 'Fletcher'} solver::nextTo&{byField: :(floor:), bMinusA: [-4..-2, 2..4]} {name: 'Smith'}) -> !VOID
({name: 'Fletcher'} solver::nextTo&{byField: :(floor:), bMinusA: [-4..-2, 2..4]} {name: 'Cooper'}) -> !VOID
[$solver::solutions&{required: 6} ... -> ($ notMatching {| {name: 'Ground'} |})]!
\);
$dwellings -> \[i]('Solution $i;:
$... -> '$;
';
'! \)... -> !OUT::write
'No more solutions
' -> !OUT::write