Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created December 20, 2016 12:38
Show Gist options
  • Select an option

  • Save theburningmonk/a27da7a956afd97d64dba242fe3e4ea2 to your computer and use it in GitHub Desktop.

Select an option

Save theburningmonk/a27da7a956afd97d64dba242fe3e4ea2 to your computer and use it in GitHub Desktop.
type Elf = { N: int; mutable Gifts: int }
let rec loop (elves: ResizeArray< Elf>)=
let this = elves.[0]
let opposite = elves.[elves.Count / 2]
this.Gifts <- this.Gifts + opposite.Gifts
opposite.Gifts <- 0
elves.RemoveAt(elves.Count/2)
elves.RemoveAt(0)
elves.Add(this)
if elves.Count = 1 then elves.[0].N else loop elves
for i = 3 to 81 do
let elves = [| 1..i |] |> Array.map (fun i -> { N=i; Gifts=1 })
let ans = loop <| new ResizeArray<Elf>(elves)
printfn "%d : %d" i ans
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment