3 people like it.
Like the snippet!
Two Logicians
Solves the "Two Logicians" puzzle.
1:
2:
3:
4:
5:
6:
7:
|
let inOp op f = Seq.groupBy (fun (x, y) -> op x y) >> Seq.filter f >> Seq.collect snd
let singleCase op = inOp op (snd >> Seq.length >> (=) 1)
let all = [for x = 2 to 49 do for y = x + 1 to 99 - x do yield x, y]
let spoilP = all |> singleCase (*) |> Set.ofSeq
all |> inOp (+) (snd >> Set.ofSeq >> Set.intersect spoilP >> Set.isEmpty)
|> singleCase (*) |> singleCase (+) |> Seq.exactlyOne
|
val inOp : op:('a -> 'b -> 'c) -> f:('c * seq<'a * 'b> -> bool) -> (seq<'a * 'b> -> seq<'a * 'b>) (requires equality)
Full name: Script.inOp
val op : ('a -> 'b -> 'c) (requires equality)
val f : ('c * seq<'a * 'b> -> bool) (requires equality)
module Seq
from Microsoft.FSharp.Collections
val groupBy : projection:('T -> 'Key) -> source:seq<'T> -> seq<'Key * seq<'T>> (requires equality)
Full name: Microsoft.FSharp.Collections.Seq.groupBy
val x : 'a
val y : 'b
val filter : predicate:('T -> bool) -> source:seq<'T> -> seq<'T>
Full name: Microsoft.FSharp.Collections.Seq.filter
val collect : mapping:('T -> #seq<'U>) -> source:seq<'T> -> seq<'U>
Full name: Microsoft.FSharp.Collections.Seq.collect
val snd : tuple:('T1 * 'T2) -> 'T2
Full name: Microsoft.FSharp.Core.Operators.snd
val singleCase : op:('a -> 'b -> 'c) -> (seq<'a * 'b> -> seq<'a * 'b>) (requires equality)
Full name: Script.singleCase
val length : source:seq<'T> -> int
Full name: Microsoft.FSharp.Collections.Seq.length
val all : (int * int) list
Full name: Script.all
val x : int
val y : int
val spoilP : Set<int * int>
Full name: Script.spoilP
Multiple items
module Set
from Microsoft.FSharp.Collections
--------------------
type Set<'T (requires comparison)> =
interface IComparable
interface IEnumerable
interface IEnumerable<'T>
interface ICollection<'T>
new : elements:seq<'T> -> Set<'T>
member Add : value:'T -> Set<'T>
member Contains : value:'T -> bool
override Equals : obj -> bool
member IsProperSubsetOf : otherSet:Set<'T> -> bool
member IsProperSupersetOf : otherSet:Set<'T> -> bool
...
Full name: Microsoft.FSharp.Collections.Set<_>
--------------------
new : elements:seq<'T> -> Set<'T>
val ofSeq : elements:seq<'T> -> Set<'T> (requires comparison)
Full name: Microsoft.FSharp.Collections.Set.ofSeq
val intersect : set1:Set<'T> -> set2:Set<'T> -> Set<'T> (requires comparison)
Full name: Microsoft.FSharp.Collections.Set.intersect
val isEmpty : set:Set<'T> -> bool (requires comparison)
Full name: Microsoft.FSharp.Collections.Set.isEmpty
val exactlyOne : source:seq<'T> -> 'T
Full name: Microsoft.FSharp.Collections.Seq.exactlyOne
More information