Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5462

Teaching and learning resources • Re: Advent of Code 2024

$
0
0

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))
utop[15]> (time (fun () -> day_1b "input.txt"));;
Execution time: 0.014070s
- : int = 26593248

Order of magnitude faster that version using filter.
I'm planning to use maps (sometimes called dictionaries) for part 2.

Right now Chapel is building on the Pi 4:
    chapel_build.png
      Since that Pi has only 2 GB RAM, I hope it doesn't start thrashing.

      Statistics: Posted by ejolson — Sun Dec 01, 2024 4:35 pm



      Viewing all articles
      Browse latest Browse all 5462

      Trending Articles