File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11open Core_kernel
22open Stdio
33
4- let load_names =
5- let replace ~pattern ~with_str =
6- Str. global_replace (Str. regexp_string pattern) with_str in
4+ let replace ~pattern ~with_str =
5+ Str. global_replace (Str. regexp_string pattern) with_str
76
7+ let load_names =
88 In_channel. read_all " p022_names.txt"
99 |> replace ~pattern: " \" " ~with_str: " "
1010 |> String. split ~on: ','
1111 |> List. sort ~compare: (Stdlib. compare)
1212
13+ let sum = List. fold ~f: (+ ) ~init: (0 )
14+
1315let name_score index name =
1416 let char_val c = Char. to_int c - 64 in
1517 name
1618 |> Bytes. of_string
1719 |> Bytes. to_list
1820 |> List. map ~f: (fun c -> (index + 1 ) * char_val c)
19- |> List. fold ~f: ( + ) ~init: ( 0 )
21+ |> sum
2022
2123let solve =
2224 load_names
23- |> List. mapi ~f: (fun i s -> name_score i s )
24- |> List. fold ~f: ( + ) ~init: ( 0 )
25+ |> List. mapi ~f: (name_score)
26+ |> sum
2527
2628let () =
2729 printf " %i\n " solve;;
You can’t perform that action at this time.
0 commit comments