Without associative arrays I'd try a list of pairs. The first element in each pair the stone type and the second a count of that type of stone in the current generation.Fast enough was not my first, and most important problem. The more pressing problem was the data structures. You guys are using ephemeral data structures, and I'm using persistent data structures. Simply put the list of all stones is only growing, and not going away. That's why I shifted to Opi5 (with 16GB) but it did not help. Testing with only one stone, it crashed on approx generation 47. Still a long way to go.I suspected a direct simulation would not be fast enough. Is part two just more blinks?> > > (time (lambda () (day11 "input.txt")))Code:
;;; Advent of code 2024 - day11, part1, on Opi5;;; Chez code (load "utils.so")(define (rule1 n) (cond ((zero? n) '(1))(else (rule2/3 n))))(define (rule2/3 n) (let* ((ns (number->string n)) (sl (string-length ns))) (if (even? sl)(let ((d (quotient sl 2))) (list (string->number (substring ns 0 d))(string->number (substring ns d sl))))(list (* n 2024)))))(define (split lst n) (do ([blink 0 (add1 blink)] [ln lst (apply append (map rule1 ln))])((= blink n) ln)))(define (day11 file) (let* ((line (read-file file)) (part1 (map (lambda (l) (length (split (list l) 25))) line))) (values (apply + part1) 'not-done)))
#<procedure >>
> 186424
not-done
#<time-duration 0.309748967>
This is only Part1 and it was done in 15 minutes in Chez. However, for Part2, I really have no idea how to proceed.
I calculated roughly, that starting from 186424 (at 25 blinks) to get to 75,
the line should be around 230T stones. I'll sleep on it, but ...???
I've fixed that, and the list is not growing, well, not nearly as fast, because, I'm going left, and left and left... until first of first stones is done with.
Doing this I have discovered one interesting fact about OCaml. Global variables do not exist (or at least I have no idea how to create them). So i resorted to using an array of length one, to hold the count of completed stones (those with generation 75).
Statistics: Posted by ejolson — Thu Dec 12, 2024 2:47 pm