Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let triangle = "" // removed cause it's fuckin' big (paste in)
- let largest =
- let temp =
- triangle.Replace("\r", String.Empty).Split('\n')
- |> List.ofArray
- |> List.map(fun line ->
- line.Split(' ')
- |> List.ofArray
- |> List.map(fun str -> Int32.Parse(str))
- )
- |> List.rev
- let length = temp.[0].Length
- temp
- |> List.fold(fun acc line ->
- acc
- |> List.mapi(fun i e ->
- match (i < (line.Length)) with
- | true -> line.[i] + Math.Max(acc.[i], acc.[i+1])
- | _ -> acc.[i]
- )
- )
- (List.ofArray (Array.zeroCreate(length + 1))) // number of elements in bottom row + 1
- |> Seq.nth 0
- printfn "%d" largest
Add Comment
Please, Sign In to add comment