Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created December 21, 2008 16:56
Show Gist options
  • Save cbilson/38716 to your computer and use it in GitHub Desktop.
Save cbilson/38716 to your computer and use it in GitHub Desktop.
#light
open System
open System.Collections.Generic
open Microsoft.FSharp.Math
let N =
Seq.unfold (fun x -> Some(x, x + 1I)) 1I
let isEven = function
| x when x % 2I = 0I -> true
| x -> false
let f = function
| x when isEven x -> x / 2I
| x -> (3I * x) + 1I
let rec makeSequence = function
| x when x = 1I -> [x]
| x -> let next = f x
x :: makeSequence next
let sequenceLengths m n =
[m .. n]
|> Seq.map (fun x -> if x % 10000I = 0I then do printfn "at %A" x
(x, makeSequence x |> Seq.length))
let longestSequence m n =
sequenceLengths m n |> Seq.max_by (snd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment