Hey folks, scarce Internet access here, can someone send the part 2 instructions for day 18 as a thread comment?
Wow, thatโs neat.. I also made three mistake of using a vec with peek/pop and getting stuck for ages until I realized the queues were fifo and not like a stack ๐
@bhauman uploaded a file: https://clojurians.slack.com/files/U064J0EFR/F8GHFRM4J/-.clj
Thanks!
interesting looking at how everyone detected "deadlock"
ahhhhh whitespace-cleanup killed me for this challenge be careful
yeah, I tend to go slowly and test things in the REPL, and I fortunately noticed this pretty early... but if you miss it, I'd imagine that you'd get weird results
especially since I was using the length of the first line to get the "shape" of the field
https://github.com/minikomi/advent-of-code/blob/master/src/advent/2017/day19.clj If you're interested ๐
I've been using for
, :let
and :when
lots more since starting advent
ah, I see
I just kept the data as a jagged vector, and used get-in
everywhere
yeah, totally valid! I just like working with directions/positions as [x y]
heh, yeah, I know what you mean
I get mixed up too easily so I like to normalize first
wow, did you come from another lisp to clojure?
heh, no, though I do FP in other languages
I actually think my Clojure is pretty messy
the letfn
threw me ๐
heh
I feel like I use lazy-seq
way too often
I mean, it's really useful
but I suspect there are higher-level ways to do it
yeah, I tend to rely on for
and loop
/`recur` a lot
and I tend to combine lazy-seq
with letfn
I did a bunch or racket last year, so structuring things as a recursive loop often makes more sense to me
yeah
for
is pretty great
I really miss for/fold
& other racket-isms https://docs.racket-lang.org/reference/for.html
got to eat something! have a good day
take care!
racket sounds like a really cool language. just a bit more verbose than clojure
i learned the basics reading Little Schemer (big recommendation)
and it actually has CTO ๐
yep, and it was surprising for me how useful in-scope defines are, compared to let
i haven't used them, what's the difference?
Just saves you saying (let [a.. b.. c..]
and indenting / nesting .. you can do (define a (something))
ah, ok
so many languages, so little time
i wanted to check out elixir too
My day 19: https://github.com/orestis/adventofcode/blob/master/clojure/aoc/src/aoc/2017_day19.clj
Today was merciful ๐
My day 19: https://github.com/borkdude/aoc2017/blob/master/src/day19.clj (it also searches the begin position as a bonus)
day 19
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day19.clj
Nice @bhauman, concise ๐
Performance of the day, both parts: 9ms (on my machine)
well thats pretty darn fast
Day 19: https://github.com/mfikes/advent-of-code/blob/master/src/advent_2017/day_19.cljc
excellent @mfikes ๐
whoa, @mfikes gonna need some time to take that in ๐
good stuff
@mfikes How fast?
eduction
is a new one for me
@mfikes Why transpose the grid in the beginning?
I mean, it seems arbitrary how you look at the grid, as rows or columns?
because you have to move through it in all directions
It seems day 18 was the most difficult: https://www.reddit.com/r/adventofcode/comments/7kuaaj/2017_day_19_leaderboard_chart/
I think the reason (for me at least) was a lack of confirmation data and lots of places where it could go wrong
Timed @mfikes's solutions, both come in around 40ms on my machine
Now I see why he applies mapv vec, it creates a vector of vector of chars
HINT I didnโt get a nice word like MERRYCHRISTMAS
I whittled my day 19 down a bunch more
https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2017/day19.clj
HINT
it seems to add a bunch of extra work keeping a direction in the state
That's really obvious now that you say it. I'll have to shave this yak a bit more.
noob question: what is #_
?
hm, seems to be a reader macro for commenting things out, why do you use it?
You can eval it in the repl, and also saves you commenting line by line, you just comment the next form, however big.
ah, how do you eval a commented block of code in the repl? ๐
Also wanted to share mine https://github.com/axelarge/advent-of-code/blob/master/src/advent_of_code/2017/day18.clj โ could be optimized by running interpreters in alternating sequence instead of in parallel, but I still think it turned out pretty nice and debuggable https://github.com/axelarge/advent-of-code/blob/master/src/advent_of_code/2017/day19.clj โ looks quite similar to the other ones shared I suppose
Btw get
and by extension get-in
also work on strings, so thereโs no need to turn them into char vectors
I wonder if thereโs a nicer way of writing the somewhat common pattern
(when (not= x bad-value) x)
For the opposite case (whitelist), thereโs (some-> x #{good-values..})
Maybe something like
(defn is [pred x] (when (pred x) x))
(defn is-not [pred x] (when-not (pred x) x))
@ihabunek C-x C-e if youโre in Emacs
Planck:
(get-in "foo" [0 0 0 0 0]) ;;=> "f"
JVM: nil
@mikelis.vindavs Clean looking solution, great job.
commenting a the next form is really helpful in a lot of situations
also you may not know that #_ #_
comments out the next two forms and etc.
@borkdude If I had to guess, the get-in
behavior is a consequence of characters being represented by single-character strings in ClojureScript.