Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
95
Task/Zebra-puzzle/Tailspin/zebra-puzzle-1.tailspin
Normal file
95
Task/Zebra-puzzle/Tailspin/zebra-puzzle-1.tailspin
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
processor EinsteinSolver
|
||||
@: [{|{}|}]; // A list of possible relations, start with one relation with an empty tuple
|
||||
$ -> \(
|
||||
when <[](1..)> do
|
||||
def variableRange: $(1);
|
||||
@EinsteinSolver: [($@EinsteinSolver(1) join {|{by $variableRange...}|})];
|
||||
$(2..last) -> #
|
||||
\) -> !VOID
|
||||
|
||||
sink isFact
|
||||
def fact: $;
|
||||
def parts: [$... -> {$}];
|
||||
@EinsteinSolver: [$@EinsteinSolver... -> \(
|
||||
def new: ($ matching {|$fact|});
|
||||
@: $;
|
||||
$parts... -> @: ($@ notMatching {| $ |});
|
||||
($new union $@) !
|
||||
\)];
|
||||
end isFact
|
||||
|
||||
operator (a nextTo&{byField:, bMinusA:} b)
|
||||
data ES_temp__ <"1"> local
|
||||
@EinsteinSolver: [$@EinsteinSolver... -> \(
|
||||
def in: $;
|
||||
def temp: {| $... -> {$, ES_temp__: ($(byField)::raw)"1"} |};
|
||||
def numbers: [$temp({ES_temp__:})... -> $.ES_temp__];
|
||||
$numbers... -> \(
|
||||
def aNumber: $;
|
||||
def bNumbers: [$bMinusA... -> ($ + $aNumber)"1"];
|
||||
def new: ($temp matching {| {$a, ES_temp__: $aNumber} |});
|
||||
@: ($new union (($temp notMatching {| $a |}) notMatching {| {ES_temp__: $aNumber} |}));
|
||||
$numbers... -> \(<~ ?($bNumbers <[<=$>]>)> $! \) -> @: ($@ notMatching {| {$b, ES_temp__: $} |});
|
||||
($in matching $@) !
|
||||
\) !
|
||||
\)];
|
||||
end nextTo
|
||||
|
||||
source solutions&{required:}
|
||||
templates resolve&{rows:}
|
||||
when <?($rows <=1>)?($::count <=1>)> do $ !
|
||||
when <?($::count <$rows..>)> do
|
||||
def in: $;
|
||||
def selected: [$...] -> $(1);
|
||||
($in minus {|$selected|}) -> resolve&{rows: $rows} ! // Alternative solutions
|
||||
@: $;
|
||||
$selected... -> {$} -> @: ($@ notMatching {| $ |});
|
||||
[$@ -> resolve&{rows: $rows-1}] -> \(
|
||||
when <~=[]> do
|
||||
$... -> {| $..., $selected |} !
|
||||
\) !
|
||||
end resolve
|
||||
[$@EinsteinSolver... -> resolve&{rows: $required}] !
|
||||
end solutions
|
||||
end EinsteinSolver
|
||||
|
||||
def numbers: [1..5 -> (no: $)];
|
||||
def nationalities: [['Englishman', 'Swede', 'Dane', 'Norwegian', 'German']... -> (nationality:$)];
|
||||
def colours: [['red', 'green', 'white', 'yellow', 'blue']... -> (colour:$)];
|
||||
def pets: [['dog', 'birds', 'cats', 'horse', 'zebra']... -> (pet:$)];
|
||||
def drinks: [['tea', 'coffee', 'milk', 'beer', 'water']... -> (drink:$)];
|
||||
def smokes: [['Pall Mall', 'Dunhill', 'Blend', 'Blue Master', 'Prince']... -> (smoke: $)];
|
||||
|
||||
|
||||
def solutions: [$numbers, $nationalities, $colours, $pets, $drinks, $smokes] -> \(
|
||||
def solver: $ -> EinsteinSolver;
|
||||
|
||||
{nationality: 'Englishman', colour: 'red'} -> !solver::isFact
|
||||
{nationality: 'Swede', pet: 'dog'} -> !solver::isFact
|
||||
{nationality: 'Dane', drink: 'tea'} -> !solver::isFact
|
||||
({colour: 'green'} solver::nextTo&{byField: :(no:), bMinusA: [1]} {colour: 'white'}) -> !VOID
|
||||
{drink: 'coffee', colour: 'green'} -> !solver::isFact
|
||||
{smoke: 'Pall Mall', pet: 'birds'} -> !solver::isFact
|
||||
{colour: 'yellow', smoke: 'Dunhill'} -> !solver::isFact
|
||||
{no: 3, drink: 'milk'} -> !solver::isFact
|
||||
{nationality: 'Norwegian', no: 1} -> !solver::isFact
|
||||
({smoke: 'Blend'} solver::nextTo&{byField: :(no:), bMinusA: [-1, 1]} {pet: 'cats'}) -> !VOID
|
||||
({smoke: 'Dunhill'} solver::nextTo&{byField: :(no:), bMinusA: [-1, 1]} {pet: 'horse'}) -> !VOID
|
||||
{smoke: 'Blue Master', drink: 'beer'} -> !solver::isFact
|
||||
{nationality: 'German', smoke: 'Prince'} -> !solver::isFact
|
||||
({nationality: 'Norwegian'} solver::nextTo&{byField: :(no:), bMinusA: [-1, 1]} {colour: 'blue'}) -> !VOID
|
||||
({drink: 'water'} solver::nextTo&{byField: :(no:), bMinusA: [-1, 1]} {smoke: 'Blend'}) -> !VOID
|
||||
|
||||
$solver::solutions&{required: 5}!
|
||||
\);
|
||||
|
||||
$solutions... -> ($ matching {| {pet: 'zebra'} |}) ... -> 'The $.nationality; owns the zebra.
|
||||
|
||||
' -> !OUT::write
|
||||
|
||||
$solutions -> \[i]('Solution $i;:
|
||||
$... -> '$;
|
||||
';
|
||||
'! \)... -> !OUT::write
|
||||
'No more solutions
|
||||
' -> !OUT::write
|
||||
52
Task/Zebra-puzzle/Tailspin/zebra-puzzle-2.tailspin
Normal file
52
Task/Zebra-puzzle/Tailspin/zebra-puzzle-2.tailspin
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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
|
||||
|
||||
def permutationsOf5: [5 -> permutations];
|
||||
|
||||
def nationalities: ['Englishman', 'Swede', 'Dane', 'Norwegian', 'German'];
|
||||
def colours: ['red', 'green', 'white', 'yellow', 'blue'];
|
||||
def pets: ['dog', 'birds', 'cats', 'horse', 'zebra'];
|
||||
def drinks: ['tea', 'coffee', 'milk', 'beer', 'water'];
|
||||
def smokes: ['Pall Mall', 'Dunhill', 'Blend', 'Blue Master', 'Prince'];
|
||||
|
||||
$permutationsOf5... -> $colours($) -> [$... -> {colour: $}]
|
||||
-> \(<[(<{colour: <='green'>}>:<{colour: <='white'>}>)]> $! \)
|
||||
-> \(def current: $;
|
||||
$permutationsOf5... -> $nationalities($) -> \[i]({$current($i), nationality: $}! \) !
|
||||
\)
|
||||
-> \(<?($(1) <{nationality: <='Norwegian'>}>)> $! \)
|
||||
-> \(<[<{nationality: <='Englishman'>, colour: <='red'>}>]> $! \)
|
||||
-> \(<[(<{nationality: <='Norwegian'>}>:<{colour: <='blue'>}>)] | [(<{colour: <='blue'>}>:<{nationality: <='Norwegian'>}>)]> $! \)
|
||||
-> \(def current: $;
|
||||
$permutationsOf5... -> $drinks($) -> \[i]({$current($i), drink: $}! \) !
|
||||
\)
|
||||
-> \(<?($(3) <{drink: <='milk'>}>)> $! \)
|
||||
-> \(<[<{drink: <='coffee'>, colour: <='green'>}>]> $! \)
|
||||
-> \(<[<{drink: <='tea'>, nationality: <='Dane'>}>]> $! \)
|
||||
-> \(def current: $;
|
||||
$permutationsOf5... -> $pets($) -> \[i]({$current($i), pet: $}! \)!
|
||||
\)
|
||||
-> \(<[<{nationality: <='Swede'>, pet: <='dog'>}>]> $! \)
|
||||
-> \(def current: $;
|
||||
$permutationsOf5... -> $smokes($) -> \[i]({$current($i), smoke: $}! \)!
|
||||
\)
|
||||
-> \(<[<{smoke: <='Pall Mall'>, pet: <='birds'>}>]> $! \)
|
||||
-> \(<[<{smoke: <='Dunhill'>, colour: <='yellow'>}>]> $! \)
|
||||
-> \(<[(<{smoke: <='Blend'>}>:<{pet: <='cats'>}>)] | [(<{pet: <='cats'>}>:<{smoke: <='Blend'>}>)]> $! \)
|
||||
-> \(<[(<{smoke: <='Dunhill'>}>:<{pet: <='horse'>}>)] | [(<{pet: <='horse'>}>:<{smoke: <='Dunhill'>}>)]> $! \)
|
||||
-> \(<[<{smoke: <='Blue Master'>, drink: <='beer'>}>]> $! \)
|
||||
-> \(<[<{smoke: <='Prince'>, nationality: <='German'>}>]> $! \)
|
||||
-> \(<[(<{smoke: <='Blend'>}>:<{drink: <='water'>}>)] | [(<{drink: <='water'>}>:<{smoke: <='Blend'>}>)]> $! \)
|
||||
-> \[i](when <{pet: <='zebra'>}> do 'The $.nationality; owns the zebra.$#10;' -> !OUT::write $!
|
||||
otherwise $! \)
|
||||
-> \[i]('$i;: $;'! \) -> '$... -> '$;$#10;';$#10;'
|
||||
-> !OUT::write
|
||||
Loading…
Add table
Add a link
Reference in a new issue