adventofcode

Happy Advent 2020! Please put answers in the pinned threads or create one if it does not exist yet. | https://github.com/adventofcode-clojurians/adventofcode-clojurians | Join the private leaderboard with code 217019-4a55b8eb
val_waeselynck 2017-12-19T00:42:24.000124Z

Hey folks, scarce Internet access here, can someone send the part 2 instructions for day 18 as a thread comment?

2017-12-19T01:13:13.000246Z

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 2017-12-19T01:14:35.000105Z

@bhauman uploaded a file: https://clojurians.slack.com/files/U064J0EFR/F8GHFRM4J/-.clj

bhauman 2017-12-19T01:14:44.000123Z

@val_waeselynck ^

val_waeselynck 2017-12-19T23:13:40.000116Z

Thanks!

2017-12-19T02:55:31.000114Z

interesting looking at how everyone detected "deadlock"

2017-12-19T05:43:35.000010Z

ahhhhh whitespace-cleanup killed me for this challenge be careful

dyankowsky 2017-12-19T05:48:42.000129Z

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

2017-12-19T05:52:29.000186Z

especially since I was using the length of the first line to get the "shape" of the field

2017-12-19T05:55:52.000159Z

https://github.com/minikomi/advent-of-code/blob/master/src/advent/2017/day19.clj If you're interested ๐Ÿ™‚

2017-12-19T05:57:25.000020Z

I've been using for, :let and :when lots more since starting advent

dyankowsky 2017-12-19T05:59:44.000107Z

ah, I see

dyankowsky 2017-12-19T06:00:37.000104Z

I just kept the data as a jagged vector, and used get-in everywhere

2017-12-19T06:01:06.000164Z

yeah, totally valid! I just like working with directions/positions as [x y]

dyankowsky 2017-12-19T06:01:18.000176Z

heh, yeah, I know what you mean

2017-12-19T06:01:30.000150Z

I get mixed up too easily so I like to normalize first

2017-12-19T06:02:24.000017Z

wow, did you come from another lisp to clojure?

dyankowsky 2017-12-19T06:02:45.000098Z

heh, no, though I do FP in other languages

dyankowsky 2017-12-19T06:03:07.000096Z

I actually think my Clojure is pretty messy

2017-12-19T06:03:21.000043Z

the letfn threw me ๐Ÿ˜›

dyankowsky 2017-12-19T06:03:28.000226Z

heh

dyankowsky 2017-12-19T06:03:34.000198Z

I feel like I use lazy-seq way too often

dyankowsky 2017-12-19T06:03:38.000059Z

I mean, it's really useful

dyankowsky 2017-12-19T06:03:48.000090Z

but I suspect there are higher-level ways to do it

2017-12-19T06:03:53.000069Z

yeah, I tend to rely on for and loop/`recur` a lot

dyankowsky 2017-12-19T06:04:01.000123Z

and I tend to combine lazy-seq with letfn

2017-12-19T06:04:21.000145Z

I did a bunch or racket last year, so structuring things as a recursive loop often makes more sense to me

dyankowsky 2017-12-19T06:04:54.000089Z

yeah

dyankowsky 2017-12-19T06:04:57.000149Z

for is pretty great

2017-12-19T06:05:06.000168Z

I really miss for/fold & other racket-isms https://docs.racket-lang.org/reference/for.html

2017-12-19T06:06:25.000035Z

got to eat something! have a good day

dyankowsky 2017-12-19T06:06:35.000009Z

take care!

ihabunek 2017-12-19T09:12:45.000160Z

racket sounds like a really cool language. just a bit more verbose than clojure

ihabunek 2017-12-19T09:13:06.000431Z

i learned the basics reading Little Schemer (big recommendation)

ihabunek 2017-12-19T09:13:36.000176Z

and it actually has CTO ๐Ÿ™‚

2017-12-19T09:14:12.000046Z

yep, and it was surprising for me how useful in-scope defines are, compared to let

ihabunek 2017-12-19T09:14:53.000466Z

i haven't used them, what's the difference?

2017-12-19T09:15:32.000343Z

Just saves you saying (let [a.. b.. c..] and indenting / nesting .. you can do (define a (something))

ihabunek 2017-12-19T09:16:09.000074Z

ah, ok

ihabunek 2017-12-19T09:16:25.000512Z

so many languages, so little time

ihabunek 2017-12-19T09:16:31.000323Z

i wanted to check out elixir too

orestis 2017-12-19T13:36:55.000327Z

Today was merciful ๐Ÿ™‚

borkdude 2017-12-19T16:23:24.000090Z

My day 19: https://github.com/borkdude/aoc2017/blob/master/src/day19.clj (it also searches the begin position as a bonus)

bhauman 2017-12-19T16:25:11.000182Z

day 19

borkdude 2017-12-19T16:27:21.000053Z

Nice @bhauman, concise ๐Ÿ™‚

๐Ÿ‘ 1
borkdude 2017-12-19T16:30:56.000381Z

Performance of the day, both parts: 9ms (on my machine)

bhauman 2017-12-19T16:31:49.000854Z

well thats pretty darn fast

borkdude 2017-12-19T16:35:39.000509Z

excellent @mfikes ๐Ÿ™‚

bhauman 2017-12-19T16:36:32.000093Z

whoa, @mfikes gonna need some time to take that in ๐Ÿ™‚

bhauman 2017-12-19T16:36:41.000511Z

good stuff

borkdude 2017-12-19T16:38:02.000205Z

@mfikes How fast?

ihabunek 2017-12-19T16:39:09.000254Z

eduction is a new one for me

borkdude 2017-12-19T16:58:29.000081Z

@mfikes Why transpose the grid in the beginning?

borkdude 2017-12-19T17:00:01.000765Z

I mean, it seems arbitrary how you look at the grid, as rows or columns?

borkdude 2017-12-19T17:00:17.000291Z

because you have to move through it in all directions

borkdude 2017-12-19T17:21:22.000140Z

It seems day 18 was the most difficult: https://www.reddit.com/r/adventofcode/comments/7kuaaj/2017_day_19_leaderboard_chart/

borkdude 2017-12-19T17:21:45.000413Z

I think the reason (for me at least) was a lack of confirmation data and lots of places where it could go wrong

borkdude 2017-12-19T17:26:18.000086Z

Timed @mfikes's solutions, both come in around 40ms on my machine

borkdude 2017-12-19T17:28:30.000456Z

Now I see why he applies mapv vec, it creates a vector of vector of chars

๐Ÿ‘ 1
borkdude 2017-12-19T17:30:45.000051Z

HINT I didnโ€™t get a nice word like MERRYCHRISTMAS

๐Ÿ˜ข 2
bhauman 2017-12-19T20:31:10.000629Z

I whittled my day 19 down a bunch more

bhauman 2017-12-19T20:33:57.000727Z

HINT

bhauman 2017-12-19T20:34:27.000368Z

it seems to add a bunch of extra work keeping a direction in the state

fellshard 2017-12-19T21:33:46.000036Z

That's really obvious now that you say it. I'll have to shave this yak a bit more.

ihabunek 2017-12-19T21:40:02.000252Z

noob question: what is #_?

ihabunek 2017-12-19T21:42:02.000480Z

hm, seems to be a reader macro for commenting things out, why do you use it?

orestis 2017-12-19T22:18:10.000018Z

You can eval it in the repl, and also saves you commenting line by line, you just comment the next form, however big.

ihabunek 2017-12-19T22:25:45.000078Z

ah, how do you eval a commented block of code in the repl? ๐Ÿ™‚

mikelis 2017-12-19T22:37:36.000365Z

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

mikelis 2017-12-19T22:38:09.000460Z

Btw get and by extension get-in also work on strings, so thereโ€™s no need to turn them into char vectors

mikelis 2017-12-19T22:39:57.000192Z

I wonder if thereโ€™s a nicer way of writing the somewhat common pattern (when (not= x bad-value) x)

mikelis 2017-12-19T22:41:11.000298Z

For the opposite case (whitelist), thereโ€™s (some-> x #{good-values..})

mikelis 2017-12-19T22:42:48.000325Z

Maybe something like

(defn is [pred x] (when (pred x) x))
(defn is-not [pred x] (when-not (pred x) x))

borkdude 2017-12-19T23:06:20.000453Z

@ihabunek C-x C-e if youโ€™re in Emacs

borkdude 2017-12-19T23:08:07.000310Z

Planck:

(get-in "foo" [0 0 0 0 0]) ;;=> "f"
JVM: nil

borkdude 2017-12-19T23:10:02.000113Z

@mikelis.vindavs Clean looking solution, great job.

bhauman 2017-12-19T23:16:55.000406Z

commenting a the next form is really helpful in a lot of situations

bhauman 2017-12-19T23:18:08.000022Z

also you may not know that #_ #_ comments out the next two forms and etc.

mfikes 2017-12-19T23:30:30.000207Z

@borkdude If I had to guess, the get-in behavior is a consequence of characters being represented by single-character strings in ClojureScript.