Fork me on GitHub
#adventofcode
<
2022-12-25
>
norman05:12:00

Day 25 - Solutions

AC06:12:59

that was a nice finish to this year’s AoC. it took me longer than it should have to remember how to convert bases.

1
Miķelis Vindavs06:12:34

the carrying part when converting back to snafu took me a bit to get right

Miķelis Vindavs06:12:45

but it’s nice that the last one was a bit of a reprieve compared to some of the days in the last week like 19 or 22

1
Apple06:12:54

;; 202225
(let [m0 {\2 2, \1 1, \0 0, \- -1, \= -2}
      m1 {2 \2, 1 \1, 0 \0, -1 \-, -2 \=}
      s5->n10 (fn [s] (->> (map m0 s) (reduce (fn [r n] (+ (* 5 r) n)) 0)))
      n10->s5 (fn [n]
                (loop [n n, carry 0, r ()]
                  (if (= n 0)
                    (apply str r)
                    (let [n (+ n carry), x (mod n 5)]
                      (if (<= 0 x 2)
                        (recur (quot n 5) 0 (conj r (m1 x)))
                        (recur (quot n 5) 1 (conj r (m1 (- x 5)))))))))]
  (->> (slurp "resources/202225") (re-seq #"[^\n]+")
       (transduce (map s5->n10) + 0) n10->s5))
;; "2=000=22-0-102=-1001"

nice 1
bellissimo 1
Miķelis Vindavs12:12:43

Thanks all for sticking it to the end, seeing other folks' solutions and different approaches made it much more interesting. And happy holidays to everyone!

🎄 2
Miķelis Vindavs13:12:57

nice 😄 next level up from this is a cpu which has native snafu math instructions

misha13:12:10

oh, god, no

stephenmhopper14:12:21

I took a peak at my puzzle input ahead of time and figured that there was a chance of hitting some kind of integer overflow. So I avoided converting the Snafu numbers to longs and just wrote code to convert snafu numbers to maps, add them with merge-with + and then reduce down into something that could be directly translated back into a Snafu numeric string. I had a bug in there somewhere and didn’t feel like debugging it, so I wrote a property based test using test.check to ensure that the following 2 things were always equal for 2 arbitrary snafu numbers: 1. Convert snafu numbers to maps, merge those maps, reduce, convert to a long 2. Convert snafu numbers to longs and then add them I found the bug fairly quickly after that EDIT: The test looks like this:

(def snafu-digit-gen (gen/elements [\2 \1 \0 \- \=]))
(def snafu-num-gen (gen/vector snafu-digit-gen 1 15))

(defspec summation-summation-equivalency-check
  (prop/for-all [s1 snafu-num-gen
                 s2 snafu-num-gen]
    ;;Take 2 snafu numbers convert them to maps, add and reduce those maps, and then convert to longs
    ;;Take the same 2 snafu numbers, convert them to longs and add them
    ;;These values should always be equivalent unless we encounter sufficiently large snafu numbers that can't
    ;;be converted directly to longs
    (let [sum-by-map (->> [s1 s2]
                       (sut/sum-snafu-numbers)
                       (sut/fully-reduce-snafu-map)
                       (sut/snafu-map->long))
          sum-by-long (->> [s1 s2]
                        (map sut/convert-snafu)
                        (map sut/snafu-map->long)
                        (reduce +)
                        )]
      (is (= sum-by-map sum-by-long)))))

🤯 1
Callum Oakley11:12:46

what are people's total runtimes / linecounts for the year?

Callum Oakley11:12:51

runtime 28s:

aoc.2022.01/part-1   0.001s   72240                                        *
aoc.2022.01/part-2   0.001s   210957                                       *
aoc.2022.02/part-1   0.006s   11063                                        *
aoc.2022.02/part-2   0.007s   10349                                        *
aoc.2022.03/part-1   0.003s   7793                                         *
aoc.2022.03/part-2   0.003s   2499                                         *
aoc.2022.04/part-1   0.002s   456                                          *
aoc.2022.04/part-2   0.002s   808                                          *
aoc.2022.05/part-1   0.002s   FZCMJCRHZ                                    *
aoc.2022.05/part-2   0.002s   JSDHQMZGF                                    *
aoc.2022.06/part-1   0.001s   1702                                         *
aoc.2022.06/part-2   0.003s   3559                                         *
aoc.2022.07/part-1   0.000s   1611443                                      *
aoc.2022.07/part-2   0.001s   2086088                                      *
aoc.2022.08/part-1   0.059s   1814                                         *
aoc.2022.08/part-2   0.060s   330786                                       *
aoc.2022.09/part-1   0.023s   5695                                         *
aoc.2022.09/part-2   0.099s   2434                                         *
aoc.2022.10/part-1   0.000s   13680                                        *
aoc.2022.10/part-2   0.000s   PZGPKPEB                                     *
aoc.2022.11/part-1   0.001s   117640                                       *
aoc.2022.11/part-2   0.446s   30616425600                                  *
aoc.2022.12/part-1   0.013s   468                                          *
aoc.2022.12/part-2   0.013s   459                                          *
aoc.2022.13/part-1   0.001s   5208                                         *
aoc.2022.13/part-2   0.001s   25792                                        *
aoc.2022.14/part-1   0.005s   979                                          *
aoc.2022.14/part-2   0.190s   29044                                        *
aoc.2022.15/part-1   0.000s   5838453                                      *
aoc.2022.15/part-2   0.003s   12413999391794                               *
aoc.2022.16/part-1   0.020s   1792                                         *
aoc.2022.16/part-2   1.840s   2587                                         *
aoc.2022.17/part-1   0.057s   3175                                         *
aoc.2022.17/part-2   0.112s   1555113636385                                *
aoc.2022.18/part-1   0.008s   3550                                         *
aoc.2022.18/part-2   0.047s   2028                                         *
aoc.2022.19/part-1   4.451s   1262                                         *
aoc.2022.19/part-2   1.604s   37191                                        *
aoc.2022.20/part-1   0.501s   14888                                        *
aoc.2022.20/part-2   5.291s   3760092545849                                *
aoc.2022.21/part-1   0.168s   291425799367130                              *
aoc.2022.21/part-2   0.572s   3219579395609                                *
aoc.2022.22/part-1   0.070s   117054                                       *
aoc.2022.22/part-2   0.056s   162096                                       *
aoc.2022.23/part-1   0.175s   3684                                         *
aoc.2022.23/part-2  10.419s   862                                          *
aoc.2022.24/part-1   0.473s   308                                          *
aoc.2022.24/part-2   1.355s   908                                          *
aoc.2022.25/part-1   0.001s   20===-20-020=0001-02                         *
aoc.2022 (total)    28.305s
linecount: 1214
12    43   297 src/aoc/2022/01.clj
   43   165  1100 src/aoc/2022/02.clj
   31   100   876 src/aoc/2022/03.clj
   25    90   617 src/aoc/2022/04.clj
   39   171  1232 src/aoc/2022/05.clj
   27   104   913 src/aoc/2022/06.clj
   41   184  1295 src/aoc/2022/07.clj
   33   123  1095 src/aoc/2022/08.clj
   41   200  1252 src/aoc/2022/09.clj
   58   241  2595 src/aoc/2022/10.clj
   83   350  2821 src/aoc/2022/11.clj
   38   176  1241 src/aoc/2022/12.clj
   36   141  1064 src/aoc/2022/13.clj
   68   268  2278 src/aoc/2022/14.clj
   67   424  2816 src/aoc/2022/15.clj
   91   488  3626 src/aoc/2022/16.clj
   61   317  2184 src/aoc/2022/17.clj
   32   124  1143 src/aoc/2022/18.clj
   74   345  2930 src/aoc/2022/19.clj
   41   205  1522 src/aoc/2022/20.clj
   33   169  1121 src/aoc/2022/21.clj
   90   443  3710 src/aoc/2022/22.clj
   50   189  1632 src/aoc/2022/23.clj
   67   322  2338 src/aoc/2022/24.clj
   33   171  1145 src/aoc/2022/25.clj
 1214  5553 42843 total

Miķelis Vindavs13:12:18

Day 01 took     0.35ms
Day 02 took     0.45ms
Day 03 took     0.85ms
Day 04 took     2.62ms
Day 05 took     0.83ms
Day 06 took     3.60ms
Day 07 took     0.84ms
Day 08 took    53.90ms
Day 09 took    22.94ms
Day 10 took     0.24ms
Day 11 took   109.43ms
Day 12 took    15.69ms
Day 13 took    13.32ms
Day 14 took   490.48ms
Day 15 took     0.75ms
Day 16 took   479.41ms
Day 17 took    40.85ms
Day 18 took   113.56ms
Day 19 took  2055.75ms
Day 20 took  1649.73ms
Day 21 took     3.38ms
Day 22 took    10.67ms
Day 23 took  3899.99ms
Day 24 took   557.03ms
Day 25 took     1.25ms

real	0m9.676s
these are my python solutions

👌 1
Miķelis Vindavs13:12:09

I don’t have clj ones for every day this year

Miķelis Vindavs13:12:21

source line counts (via sloc)

day01.py    4
 day02.py   25
 day03.py   14
 day04.py   16
 day05.py   18
 day06.py   11
 day07.py   28
 day08.py   26
 day09.py   29
 day10.py   27
 day11.py   35
 day12.py   38
 day13.py   25
 day14.py   53
 day15.py  111
 day16.py   44
 day17.py   63
 day18.py   42
 day19.py   85
 day20.py   22
 day21.py   47
 day22.py   82
 day23.py   53
 day24.py   37
 day25.py   21
 total     956

👌 1
Miķelis Vindavs13:12:24

@U01HL2S0X71 could you share how you have your runner set up? I really like that summary view with all the outputs and times

1