Zebra puzzle: Difference between revisions
Content deleted Content added
Thundergnat (talk | contribs) Rename Perl 6 -> Raku, alphabetize, minor clean-up |
→{{header|F_Sharp|F#}}: Use impoved Ring.Plainchanges |
||
Line 2,530:
=={{header|F_Sharp|F#}}==
This task uses [
<lang fsharp>
(*Here I solve the Zebra puzzle using Plain Changes, definitely a challenge to some campanoligist to solve it using Grandsire Doubles.
Nigel Galloway: January 27th., 2017 *)
type N = |English=0 |Swedish=1|Danish=2 |German=3|Norwegian=4
type I = |Tea=0 |Coffee=1 |Milk=2 |Beer=3 |Water=4
type G = |Dog=0 |Birds=1 |Cats=2 |Horse=3 |Zebra=4
type E = |Red=0 |Green=1 |White=2 |Blue=3 |Yellow=4
type L = |PallMall=0|Dunhill=1|BlueMaster=2|Prince=3|Blend=4
type NIGELz={Nz:N[];Iz:I[];Gz:G[];Ez:E[];Lz:L[]}
let fn (i:'n[]) g (e:'g[]) l = //coincident?
Line 2,553:
_fn 0
let fg (i:'n[]) g (e:'g[]) l = (fi i g e l || fi e l i g) //adjacent?
let n = Ring.PlainChanges [|
let i = Ring.PlainChanges [|
let g = Ring.PlainChanges [|
let e = Ring.PlainChanges [|
let l = Ring.PlainChanges [|
match n|>Seq.map(fun n->{Nz=
|>Seq.collect(fun n->i|>Seq.map(fun i->{n with Iz=
|>Seq.collect(fun n->g|>Seq.map(fun i->{n with Gz=
|>Seq.collect(fun n->e|>Seq.map(fun i->{n with Ez=
|>Seq.collect(fun n->l|>Seq.map(fun i->{n with Lz=
|Some(nn) -> nn.Gz |> Array.iteri(fun n g -> if (g = G.Zebra) then printfn "\nThe man who owns a zebra is %A\n" nn.Nz.[n]); printfn "%A" nn
|None -> printfn "No solution found"
|