Fork me on GitHub
<
2020-12-05
>
Vincent Cantin05:12:46

Good morning

👋 15
fingertoe05:12:50

Day 5 probably would have been a lot easier if I had carefully read the problem.. Not too bad though..

rjray05:12:00

Day 5 done. I found the wording of part 2 to be very confusing. Lost time trying to figure out WTF was being asked for. Once I understood, the solution was pretty simple.

Vincent Cantin06:12:40

My cat started screaming right at that time, making it very difficult to focus on the problem. 📝 memo: take the cat away for tomorrow’s puzzle.

mchampine06:12:48

Agreed, the wording of part 2 took a while to interpret. I thought the description in part one was also a very long winded way to describe binary that could easily lead someone down a very long unproductive path. I suspect that was intentional and that you’re supposed to be rewarded (with time savings) for insights that lead to dramatically simpler solutions. I’m pretty happy with my 6 line solution to part 1. Part 2 took another 2 lines but is slightly hacky. Looking forward to seeing other approaches.

Vincent Cantin06:12:41

I solved part2 before I had a correct expression to solve it, just by doing some data exploration … the solution appeared clearly in the middle of false positives.

erwinrooijakkers06:12:01

Good morning. Probably can be done nicer using an index instead of a vector representation but it’s Saturday. I hope to see an example with index later today 🙂 https://github.com/transducer/adventofcode/blob/master/src/adventofcode/2020/day5.clj

nbardiuk06:12:54

seat number is just a binary with 0 and 1 replaced with L|F and R|B

Vincent Cantin06:12:07

another trick is how to parse it … there is a clojure function for that

3
dpkp07:12:47

Very nice

nbardiuk07:12:35

@U8MJBRSR5 cannot find anything suitable, I am very intrigued 😮

nbardiuk07:12:59

oh cool! learn something new with every puzzle 😆

plexus07:12:37

I guess I'm the only one who actually bothered to use bit-shift/bit-or 🙂

🙂 3
Vincent Cantin07:12:28

edn/read-string is a good parser

Vincent Cantin07:12:24

@U07FP7QJ0 I like your approach for part2

plexus07:12:16

the `(partition coll n 1)` trick has saved me more than once

i prefer `(Integer/parseInt s 2)` to `read-string` tricks, but that might be personality.

3
alekszelark10:12:07

Me too, but the better way to do that is to use `Long/parseLong` . Ultimately, all the numbers in Clojure represented as Longs.

alekszelark10:12:39

@U076FM90B Just realized from your solution, that splitting at row and col and then some math are not needed at all.

👍 3
alekszelark10:12:19

I should carefully look at the input data.

plexus12:12:01

Yeah I thought I was pretty smart by spotting it was just binary, but now I feel silly for not realizing that row+col are just a single number, no need to split them up :)

😲 3
3

`* 8` was the clue. Why 8?

alekszelark12:12:41

It’s a power of 2. 2 2 2 = 8. Multiplying by 2 means the same thing you do with shift-left. For example

``````(= (bit-shift-left 1 3)
(* 1 8))``````

alekszelark12:12:32

and then just `bit-or` it’s binary addition, so you get the same result just by decoding a whole string.

woonki.moon13:12:02

how brilliant!

erwinrooijakkers14:12:55

row and col are just a single number?

erwinrooijakkers14:12:15

erwinrooijakkers14:12:25

So 🙂 For example “BFFFBBFRRR” is in binary 1000110 111, so:

``````(+ (* 8 (Integer/parseInt "1000110" 2))
(Integer/parseInt "111" 2))
;; => 567``````
which is equal to:
``(Integer/parseInt "1000110111" 2) ;; => 567 ``

🤯 3
Stuart19:12:28

I feel dumb. I created a range from 0 to 127 and recursively either drop / take half of it.

erwinrooijakkers11:12:15

Me too 45 minutes of fighting with off-by-one errors and nullpointerexceptions 🙂

nbardiuk09:12:34

I didn't know about step argument in `partition-all` . Literally yesterday had to implement the `pairs` function manually

andrea20:12:30

Nice! @U07FP7QJ0 any info about your env setup? Is that vim plus what?

plexus05:12:51

Planning to get that to a shippable state during the christmas/new years holidays

👍 3
alekszelark09:12:50

I solved it literally how it says (spoiler) 😞

☝️ 3
alekszelark09:12:15

``````(defn decode [lo hi s]
(if-let [c (first s)]
(case c
(\F \L) (recur lo (+ lo (quot (- hi lo) 2)) (next s))
(\B \R) (recur (+ lo (inc (quot (- hi lo) 2))) hi (next s)))
lo))``````

👍 3
alekszelark11:12:51

And my final decode

``````(defn decode [code]
(-> (str/escape code {\F 0 \L 0 \B 1 \R 1})
(Long/parseLong 2)))``````

💯 9
nbardiuk12:12:16

Cool! `escape` another function I've learned today

👍 6
plexus12:12:56

Ooh that's a good one! Sequestering it for my toolbox :) 🧰

😁 3
☝️ 3
pez14:12:34

I did it even more literally. 😃 I figured while doing it that there must be another way, but the thing with gold stars is that they give me fever and make me indifferent to what happens to gnomes and kittens.

☝️ 6
3
3