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
fellshard 2016-12-05T06:15:06.000004Z

Having a devil of a time with today's. I think it comes down to not being familiar / being able to find documentation on how to use arrays / byte arrays in Clojure.

spfeiffer 2016-12-05T07:20:52.000005Z

http://clojure.org/reference/java_interop

spfeiffer 2016-12-05T07:21:36.000006Z

Scroll down to β€žArraysβ€œ. Keep in mind they are mutable. That bite me in on of last years challenges.

fellshard 2016-12-05T07:29:25.000007Z

In the end, it was mostly the array operations that were aggravating.

fellshard 2016-12-05T07:30:24.000008Z

Er, byte operations, that is

fellshard 2016-12-05T07:30:37.000009Z

This problem works at the byte level, not the nibble level. So gotta do a little tinkering to get it working efficiently enough to search such a wide space.

abarylko 2016-12-05T07:55:46.000010Z

Just finished day 5

abarylko 2016-12-05T07:55:56.000011Z

Though didn't use byte arrays....

fellshard 2016-12-05T07:58:01.000012Z

Have the resulting code posted anywhere for comparison?

fellshard 2016-12-05T07:58:50.000013Z

I've been pushing the raw 'just get an answer' code, then going back and refactoring to see what could be done better, etc.

fellshard 2016-12-05T07:59:22.000014Z

Given how painful it is to calculate these hashes, good time to learn this: is there a 'best method' to cache the resolved portions of an infinite sequence?

abarylko 2016-12-05T08:14:49.000015Z

good idea on the cache .....

abarylko 2016-12-05T08:15:18.000016Z

my code is here https://github.com/amirci/aoc_clj

abarylko 2016-12-05T08:16:02.000018Z

any reviews and comments are welcome

fellshard 2016-12-05T08:24:42.000019Z

Ahh, there's a digest lib?

fellshard 2016-12-05T08:26:16.000020Z

Okay, the source I found for MD5 digest did the same thing as the library. Internally, it's using the same thing

abarylko 2016-12-05T08:26:25.000021Z

cool

fellshard 2016-12-05T08:27:14.000022Z

I found that by short-circuiting that library's use of byte hash -> BigInteger -> string every time, there was at least a bit of time savings. Might have to profile and measure it later, but I was reaching for straws trying to get a feedback loop going even with the sample data.

fellshard 2016-12-05T08:27:51.000023Z

But may have been more pain than it's worth. πŸ™‚ I mostly used it to filter the initial results so I only generated string reps when I knew those first five nybbles were 0'd out.

fellshard 2016-12-05T09:28:08.000024Z

In the end, it was by far not the MD5 that was the time constraint, it was me being really really bad about mixing eager and lazy πŸ™‚

fellshard 2016-12-05T09:29:20.000025Z

It does take some time to find all the matches - a couple minutes for my second round, since it has to find over 20 valid hashes until it found its position 3 entry, but that's just compounding the problem

fellshard 2016-12-05T10:02:16.000026Z

Lots of learning tonight πŸ˜„

fellshard 2016-12-05T10:03:53.000029Z

In the end, I did a refactor 'for the fun of it'. Using the swiss arrows library allowed me to A. reuse the initial part of the calculation, and B. run part A and part B pipelines in parallel

fellshard 2016-12-05T10:04:11.000030Z

The parallel furcula is magic

abarylko 2016-12-05T17:11:55.000032Z

@fellshard pretty cool!

fellshard 2016-12-05T17:23:07.000033Z

Glad I finally found an excuse to try that lib πŸ˜›

andrew.sinclair 2016-12-05T17:59:06.000035Z

Hello, @abarylko told me this is the best place to improve my Clojure! I'm looking forward to solve some AoC with some fellow Clojurians. I have lots to learn πŸ˜‰

fellshard 2016-12-05T18:20:29.000036Z

4clojure may be a bit better for basic learning, but last year's AoC challenges are probably great, too πŸ™‚

fellshard 2016-12-05T18:20:59.000037Z

This year's AoC challenges are starting a bit higher level if I recall last year's problems correctly.

andrew.sinclair 2016-12-05T18:31:40.000038Z

Yep, I did last years AoC with Clojure. 4clojure was where I cut my teeth.

andrew.sinclair 2016-12-05T18:32:07.000039Z

I'd consider myself competent, but I want to go from "hobby language" to "professional understanding" in Clojure.

fellshard 2016-12-05T18:39:09.000040Z

πŸ˜„

fellshard 2016-12-05T18:39:48.000041Z

Then this is a fantastic place for it. All the problems have two parts, and usually the second part requires you to change your model or refactor your first solution in some way. Very cleverly written.

fellshard 2016-12-05T18:40:15.000042Z

And if you aim for the leaderboards, it's an extra bit of challenge πŸ˜„

spfeiffer 2016-12-05T19:37:57.000043Z

I am still stuck around problem 20 of last years AoC because i am a hobbyist and i am lacking free time. I expect to finish this years AoC around 2021 ☺️

spfeiffer 2016-12-05T19:38:23.000044Z

These are the most fun programming exercises i stumbled upon ever…

spfeiffer 2016-12-05T19:38:51.000045Z

Hearing this years challenges are much harder frightens me ☺️

mnespor 2016-12-05T19:39:18.000046Z

I hope he doesn't throw anything harder than last year's problem 19 at us

fellshard 2016-12-05T21:11:17.000047Z

πŸ˜„

fellshard 2016-12-05T21:11:31.000048Z

I'm at 14 from last year, 'cuz of free time too...