Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.lisp
Project Euler 67.
William James
3/18/2016 7:39:00 PM
There are only two differences from problem 18.:
1. The triangle has to be obtained from a text file.
2. There are 100 rows in the triangle.
The website says that if you could check 10^12 routes every second,
it would take you over 20 billion years to check them all.
OCaml:
#load "str.cma";;
let slurp file =
let chan = open_in file in
let text = really_input_string chan (in_channel_length chan) in
close_in chan ;
text ;;
let triangle =
slurp "p067_triangle.txt"
|> Str.split (Str.regexp "\n")
|> List.map (fun line ->
line |> Str.split (Str.regexp " +") |> List.map int_of_string
|> Array.of_list)
|> List.rev ;;
let rec loop = function
[[|n|]] -> n
| row2::row1::rows ->
loop
((Array.mapi
(fun i n -> n + (max row2.(i) row2.(i+1)))
row1)
:: rows)
in loop triangle ;;
===>
7273
--
Europe is not going to be the monolithic societies that they once were in the
last century.... They are now going into a multicultural mode. Jews will be
resented because of our leading role. --- Barbara Spectre
http://archive.org/download/DavidDuke_videos/HowZionistsDivideAndConquer-fjjsz...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Project Euler 67.
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password