Fork me on GitHub
#adventofcode
<
2020-12-18
>
markw02:12:53

I thought day 17 looked reasonably easy at first… Now my back of the envelope guess for part 2 completion is 2.5 hours

markw02:12:42

guess that leaves me some time to consider my botched approach … or just be lazy and let it finish before day 18 😛

markw02:12:02

only an hour it turns out…. yay?

curlyfry04:12:06

While I have no clue what your solution looks like, maybe you can bring that down without rewriting your logic at all by using memoize (if you have any functions that will often have the same inputs throughout execution)

markw04:12:11

yeah i was considering going in that direction, but i just scrapped version one and did a big refactor.. now it’s < 1 second for part 1 and about 10 for part 2, good enough for me

Average-user06:12:02

That was boring :c

Vincent Cantin06:12:41

Maybe it means that we improved.

Average-user06:12:35

Don't think so. My solution is still pretty ugly, but that is because the problem is not very motivating. At least for me of course, it is a matter of taste.

Vincent Cantin06:12:42

Small note about how to test the type of something that looks like a “list”:

;; Only use list? when you are sure what you want to test is a list.
  (list? (map identity (list :a :b))) ; false
  (list? (cons :a (list :b))) ; false
  (list? `(:a :b)) ; false
  
  ;; sequential? is more generic.
  (sequential? (map identity (list :a :b))) ; true
  (sequential? (cons :a (list :b))) ; true
  (sequential? `(:a :b)) ; true
  
  ;; Note: Strings are seqable, but not sequential?
  (sequential? "foo")) ; false

thanks2 2
🙏 2
Daw-Ran Liou11:12:58

TIL clojure.lang.Symbols are also functions! I guess the purpose of it is to look up things inside a map or a set but I’m not sure how to use this effectively. Here is the source code: https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Symbol.java#L127-L133

;; surprise!
('+ 1 2)
;; => 2

('+ {'+ 1})
;; => 1
('+ {'+ +})
;; => #function[clojure.core/+]
('+ {'* *})
;; => nil
('+ {'* *} :not-found)
;; => :not-found

👍 3
Daw-Ran Liou12:12:41

Had to learn this the hard way because my day 18 part 1 kept evaluating to the very last number in any given equation. picard-facepalm

('+ ('+ 1 ('* 2 3)) ('* 4 ('+ 5 6)))
;; => 6

😅 2
Vincent Cantin13:12:24

I did not know that. Thank you for sharing.