I'm planning to use maps (sometimes called dictionaries) for part 2.utop[15]> (time (fun () -> day_1b "input.txt"));;Code:
(* Advent of Code - 2024; day1 - part2 on BPI-F3 RISC-V *)(* OCaml much faster code using BST instead of filter *)#load "utils.cmo"open Utilslet rec unleave = function [] -> [],[] | [a; b] :: t -> match unleave t with l, r -> (int_of_string a :: l, int_of_string b :: r)let day_1b file = let ll,rl = file |> read_lol_words |> unleave in let bst = bst_of_list rl in List.(fold_left (+) 0 (map (fun l -> l * (get l bst)) ll))
Execution time: 0.014070s
- : int = 26593248
Order of magnitude faster that version using filter.
Right now Chapel is building on the Pi 4:
Statistics: Posted by ejolson — Sun Dec 01, 2024 4:35 pm