This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-12-05
Channels
- # adventofcode (50)
- # announcements (1)
- # asami (29)
- # babashka (56)
- # beginners (19)
- # calva (62)
- # cider (12)
- # cljs-dev (1)
- # clojure (42)
- # clojure-europe (214)
- # clojure-france (4)
- # clojure-italy (1)
- # clojurescript (58)
- # community-development (4)
- # cryogen (6)
- # cursive (7)
- # data-science (1)
- # events (3)
- # figwheel-main (1)
- # fulcro (21)
- # lambdaisland (3)
- # malli (17)
- # mid-cities-meetup (1)
- # off-topic (38)
- # pathom (3)
- # reagent (7)
- # reclojure (1)
- # reveal (15)
- # rewrite-clj (11)
- # shadow-cljs (30)
- # sql (21)
- # test-check (14)
- # tools-deps (1)
- # vim (21)
- # xtdb (5)
Day 5 probably would have been a lot easier if I had carefully read the problem.. Not too bad though..
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.
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.
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.
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.
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
https://github.com/nbardiuk/adventofcode/blob/master/2020/src/day05.clj spoiler 👇
@U8MJBRSR5 cannot find anything suitable, I am very intrigued 😮
@U076FM90B https://github.com/green-coder/advent-of-code-2020/blob/master/src/aoc/day_5.clj#L20-L21
edn/read-string is a good parser
@U07FP7QJ0 I like your approach for part2
i prefer (Integer/parseInt s 2)
to read-string
tricks, but that might be personality.
Me too, but the better way to do that is to use Long/parseLong
. Ultimately, all the numbers in Clojure represented as Longs.
@U076FM90B Just realized from your solution, that splitting at row and col and then some math are not needed at all.
I should carefully look at the input data.
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 :)
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))
and then just bit-or
it’s binary addition, so you get the same result just by decoding a whole string.
That’s it yes
Missed it 🙂
Jonathan did same: https://www.youtube.com/watch?v=wa0VcQugEsI
how brilliant!
row and col are just a single number?
because of adding?
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
I feel dumb. I created a range from 0 to 127 and recursively either drop / take half of it.
Me too 45 minutes of fighting with off-by-one errors and nullpointerexceptions 🙂
I didn't know about step argument in partition-all
. Literally yesterday had to implement the pairs
function manually
Nice! @U07FP7QJ0 any info about your env setup? Is that vim plus what?
(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))
full solution https://github.com/zelark/AoC-2020/blob/3cc64ff25278f82d262c4c32c2eec4268c0997a5/src/zelark/aoc_2020/day_05.clj
refactored one https://github.com/zelark/AoC-2020/blob/master/src/zelark/aoc_2020/day_05.clj
And my final decode
(defn decode [code]
(-> (str/escape code {\F 0 \L 0 \B 1 \R 1})
(Long/parseLong 2)))