Skip to content

Instantly share code, notes, and snippets.

@dahlbyk
Created October 9, 2009 02:21
Show Gist options
  • Save dahlbyk/205639 to your computer and use it in GitHub Desktop.
Save dahlbyk/205639 to your computer and use it in GitHub Desktop.
let GetChainLength value =
let next x = match x % 2L with
| 0L -> x / 2L
| _ -> x * 3L + 1L
let rec chain n acc = match n with
| x when x <= 1L -> acc
| x -> chain (next x) (acc+1)
value, (chain value 1)
seq { 1L..999999L }
|> Seq.map GetChainLength
|> Seq.maxBy snd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment