adventofcode

thomas 2023-12-06T08:00:14.091149Z

still stuck on day 2.... but getting there.

8
bop 2023-12-06T15:30:41.922059Z

[SPOILER WARNING] Hey guys! Does anyone can give a direction on why my day 3 /part 1 solution is wrong? https://github.com/brunoti/advent-of-code/blob/main/years/y2023/day3.clj

bop 2023-12-06T15:31:39.467789Z

It works with the default data. Even after spotting some possible edge cases that would cause my code to fail, I’m still very stuck!

pez 2023-12-06T15:39:51.723509Z

You should post under the Day 3 solutions thread, me thinks. Or at least post your code in a thread. Anyway. I had troubles with part 1 too and that was because I failed to find the numbers when they were last on the line. Haven’t read your code super carefully, but just maybe you have the same issue?

bop 2023-12-06T15:45:56.398769Z

It’s not that. Just checked. But, what you said is that should ask for help on the solutions thread?

pez 2023-12-06T15:55:18.721619Z

What I mean is that we try to avoid spoilers in the main channel.

πŸ’― 1
rjray 2023-12-06T05:25:31.347309Z

Holy crap. For once, I was the first-to-finish on our leaderboard!

πŸ‘ 6
2023-12-06T05:50:30.417419Z

Day 6 - Solutions

oyakushev 2023-12-06T09:16:18.706749Z

Very easy today, just a simple quadratic equation https://gist.github.com/alexander-yakushev/6ad2ec7bfc16fd9d68c3d133636c59bc "Elapsed time: 0.126625 msecs"

πŸ™Œ 1
πŸ™ŒπŸ» 1
Casey 2023-12-06T09:21:48.037129Z

Maybe i had a lucky input? but the brute force worked well for me https://github.com/Ramblurr/advent-of-code/blob/main/src/aoc/2023/day06.clj#L10-L15

genmeblog 2023-12-06T09:44:17.876599Z

Quadratic solver works. I was afraid of floating point accuracy for such big numbers but looks like it's not a case here (my zeros are at: [7711542.749144189, 3.827683025085581E7])

oyakushev 2023-12-06T09:53:52.435169Z

@tsulej IEEE754 has 52 bits for the fraction, input numbers are not that big:)

genmeblog 2023-12-06T10:39:35.045239Z

True, but in reality fractional part in floating point number depends on the exponent. Here we have E7 but for 5.0E15 the next possible number is one larger, ie: (m/ulp 5.0E15) ;; => 1.0

genmeblog 2023-12-06T10:40:27.274969Z

So, above 1.0e16 you have no fractional part at all.

genmeblog 2023-12-06T10:41:23.634119Z

Sometimes AoC tasks go beyond this value.

Sam Ferrell 2023-12-06T10:47:13.583309Z

https://github.com/samcf/advent-of-code/blob/main/2023-06-wait.clj Not as brute force as (range 1 n) but not as fast as binary search or math

oyakushev 2023-12-06T10:49:57.271639Z

@tsulej What's m/ulp? I'm not sure what are you saying with your example.

user=> (long 5.0E15)
5000000000000000
user=> (long 5.0E16)
50000000000000000
user=> (long 5.1E17)
510000000000000000

oyakushev 2023-12-06T10:52:57.793149Z

I think I got it.

(long (double (inc (long 5.0e16)))) => 50000000000000000

πŸ‘ 1
genmeblog 2023-12-06T10:53:51.873259Z

https://en.wikipedia.org/wiki/Unit_in_the_last_place is Unit in the last place. It's a measure of a precision of the floating point number. Meaning: what is the difference between next possible double and given double.

(== 1.0e16 (+ 1.0e16 0.5))
;; => true
(== 1.0e16 (+ 1.0e16 1.0))
;; => true
(== 1.0e16 (+ 1.0e16 1.5))
;; => false

πŸ‘ 1
πŸ‘πŸ» 1
oyakushev 2023-12-06T10:54:11.527049Z

I think it is consistent with my point.

user=> (count (Long/toBinaryString 50000000000000000))
56

oyakushev 2023-12-06T10:54:50.586889Z

So as long as the non-fractional part fits into 52 bits, you should be safe.

genmeblog 2023-12-06T10:56:37.319369Z

Yes. But as I mentioned, sometimes you deal with numbers around 1.0e15 and higher in AoC and operations can lead to losing the precision. Race task is not a case fortunately.

oyakushev 2023-12-06T10:57:35.681019Z

Fair enough. Can always switch to BigDecimal if needed.

user=> (inc 5.0e16M)
50000000000000001M

πŸ‘ 1
genmeblog 2023-12-06T10:58:05.706429Z

Exactly.

genmeblog 2023-12-06T11:00:02.085349Z

One more example and I shut up πŸ™‚ . There is no representation in doubles for 100000000000000006 which is valid as long.

(long 1.0e17)
;; => 100000000000000000
(long (m/next-double 1.0e17))
;; => 100000000000000016
(long (double 100000000000000006))
;; => 100000000000000000

βž• 1
Arno Jacobs 2023-12-06T11:09:11.598579Z

I coded brute force solutions for day 6 and I was amazed by the speed. About 2 seconds for both parts. πŸ’ͺ

Marcel Krcah 2023-12-06T11:53:16.031639Z

https://github.com/mkrcah/advent-of-code/blob/main/src/day_06.clj with rusty quadratic formula

genmeblog 2023-12-06T12:53:26.861799Z

My solution (based on quadratic formula): https://github.com/genmeblog/advent-of-code/blob/master/src/advent_of_code_2023/day06.clj

πŸ‘πŸ» 1
Felipe 2023-12-06T13:10:19.037689Z

quadratic what? πŸ™‚ https://github.com/FelipeCortez/advent-of-code/blob/master/2023/06.clj

tschady 2023-12-06T13:22:29.232929Z

I re-used quadratic helper. https://github.com/tschady/advent-of-code/blob/main/src/aoc/2023/d06.clj

Jakob Durstberger 2023-12-06T13:41:20.620329Z

Today's puzzle was so much more enjoyable, and I am quite happy that my very simple implementation just worked. Definitely dropped my frustration level with AoC 2023 back down. https://youtu.be/8SMrDhRFr6E

πŸ‘ 1
Arno Jacobs 2023-12-06T15:15:02.020269Z

Great. Was able to some more on the challenge. Quadratic indeed. Now it's "Elapsed time: 0.628375 msecs"

Ivana 2023-12-06T15:26:59.281819Z

Got it by simple binary-search of monotonic function root, in integers, without any quadratic equations, discriminants, square roots etc. Actually easy task, both parts can be solved with a pen & paper without computer at all.

(let [t 44707080N
        d 283113411341491N
        root (fn [t1 t2]
               (let [tc (quot (+ t1 t2) 2)
                     [d1 dc] (map #(- (* % (- t %)) d) [t1 tc])]
                 (cond (= 1 (- t2 t1)) t2
                       (>= (* d1 dc) 0) (recur tc t2)
                       :else (recur t1 tc))))]
    (- (root (quot t 2) t) (root 0 (quot t 2))))

oyakushev 2023-12-06T15:29:49.181649Z

Quadratic equation is 5th grade math, you make it sound complicated:)

Ivana 2023-12-06T15:31:20.735709Z

Yep, but BS allows to keep in integers, without any mistakes of floats/doubles due to accuracy etc.

oyakushev 2023-12-06T15:34:51.955799Z

By multiplying two longs together you'll get an overflow before a loss of precision from doubles in this task.

oyakushev 2023-12-06T15:35:47.511219Z

Or, actually, "might" get an overflow, not 100% sure

Ivana 2023-12-06T15:35:50.401189Z

Actually not. Look at N s in numbers literals

oyakushev 2023-12-06T15:36:48.925969Z

That's fair, but similarly BigDecimal can be used for floating-points.

Ivana 2023-12-06T15:39:29.147359Z

Yep, but when you get f.e. 3.9999999999999 as a root, but you need cell + 1, so is it 3 or 4? Of course, you can check, but integer algorythms avoid of such cases

oyakushev 2023-12-06T15:45:31.312919Z

floor(3.99999999) is 3. It takes a very large number so that the square root of it is a at the margin of error of an integer number. But I get your point.

Arnaud Geiser 2023-12-06T19:01:59.721659Z

Nothing more satisfying than brute-forcing πŸ˜„ https://github.com/arnaudgeiser/advent-of-code/blob/master/2023/clojure/src/advent_of_code/day6.clj

bhauman 2023-12-07T04:49:41.454899Z

Here’s day 6 using newtons method:

bhauman 2023-12-07T04:50:23.637069Z

only five iterations to solution on my part 2

bhauman 2023-12-07T04:55:19.074949Z

But I think the simplest solution is to search in steps of 5000 and when you cross over just search the 5000 entries for the cross over point.

Max 2023-12-13T14:55:31.279289Z

5 minutes of simple math saves you 10 minutes of brute forcing πŸ˜† The parsing code ended up being longer than the solution https://github.com/maxrothman/advent-of-code/blob/main/2023/clj2023/src/clj2023/day6.clj

πŸ‘ 1
2023-12-06T05:50:54.730069Z

https://gitlab.com/maximoburrito/advent2023/-/blob/main/src/day06/main.clj I made one assumption that I don't have any basis for, but I've learned to accept that in aoc your input is the puzzle, not the problem statement. Solve your input, not the general problem, because often times that's the only way.

rjray 2023-12-06T05:52:22.764129Z

https://github.com/rjray/advent-2023-clojure/blob/master/src/advent_of_code/day06.clj A silly mistake on part 1 lead to ~5 minutes of debugging. Part 2 took 3 minutes, total. Regexp for the win πŸ™‚.

2023-12-06T05:53:31.858179Z

Wait - did you just use the brute force solution? And it was fast enough?

2023-12-06T06:00:26.451349Z

Wow - it is! Nicely done @rjray

Brute Force:   "Elapsed time: 9315.748712 msecs"
Binary Search: "Elapsed time: 2.786305 msecs"

😁 2
2023-12-06T06:53:47.462659Z

Hi, everybody I am a bit of a novice in Clojure (completed a few days from last year's AOC) Just joined your private leaderboard https://github.com/andrewbelo/aoc2023/blob/master/src/day_6_wait_for_it.clj

jake 2023-12-06T07:08:18.697639Z

No regex for me today, I hand wrote my input in - felt good

βž• 1
alpox 2023-12-08T18:50:44.201729Z

I almost forgot about the quadratic formula but I’m glad I remembered it existed πŸ˜…

Ryan Martin 2023-12-11T14:06:44.870609Z

finally had time to work on aoc. here's my day 6 solution: https://github.com/rmrt1n/advent-of-code-2023-clj/blob/main/src/aoc/day06.clj