Created
December 21, 2008 16:56
-
-
Save cbilson/38716 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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