Author Topic: Advent of Code  (Read 116415 times)

vorsprung

  • Opposites Attract
    • Audaxing
Re: Advent of Code
« Reply #1150 on: 02 December, 2023, 09:30:10 pm »
Advent of code 2023 has started.

Day 1
(click to show/hide)

and once again i can't be arsed with it

Re: Advent of Code
« Reply #1151 on: 05 December, 2023, 06:53:42 am »
Day 5
(click to show/hide)
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Advent of Code
« Reply #1152 on: 05 December, 2023, 10:42:43 pm »
Not wanting to wait 15 mins, I spent an hour writing a recursive split which spat out the answer in 15 seconds.

Thinking I might be descending the same tree multiple times, I added a cache but it only knocked off a second. There is probably a better way, but it seems OK for < 100 lines of C#.
Quote from: tiermat
that's not science, it's semantics.

Re: Advent of Code
« Reply #1153 on: 05 December, 2023, 11:37:26 pm »
I decided that there had to be an elegant solution, and what I have now written, in far more than 15 minutes, runs in less than a second. It's not recursive.
(click to show/hide)
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Advent of Code
« Reply #1154 on: 06 December, 2023, 08:21:24 pm »
Yes, spotted the range thing later.

Day 6 was a bit easy

(click to show/hide)
Quote from: tiermat
that's not science, it's semantics.

jwo

Re: Advent of Code
« Reply #1155 on: 06 December, 2023, 09:59:39 pm »
Day 6:

(click to show/hide)

Re: Advent of Code
« Reply #1156 on: 06 December, 2023, 10:12:41 pm »
Yes, spotted the range thing later.

Day 6 was a bit easy

(click to show/hide)
jwo posted while I was writing this.
(click to show/hide)
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Advent of Code
« Reply #1157 on: 07 December, 2023, 10:51:33 am »
Symmetric rather than Normal. So you only need to find the lower bound.
Quote from: tiermat
that's not science, it's semantics.

Re: Advent of Code
« Reply #1158 on: 09 December, 2023, 12:30:18 pm »
Pickled O: I'm not really familiar with C#. What does Select(x=> x.Ways()) do?

It's Linq - Select takes an enumeration of races, and for each one asks it how many ways can that race be won, returning an enumeration of those. Aggregate takes an enumeration of numbers and applies the function on that number (y) and the previous result (x) with the seed (1) used as x for the first operation.

I'm seeing how far I can go writing all solutions in Linq. Eg, day 1 was quite neatly

    public long Part1()
    {
        return Lines.ElfinToNumber().Sum();
    }
    public long Part2()
    {
        return Lines.WordsToDigits().ElfinToNumber().Sum();
    }
Quote from: tiermat
that's not science, it's semantics.

Re: Advent of Code
« Reply #1159 on: 09 December, 2023, 05:22:06 pm »
And day 7 reads nicely with Linq

(click to show/hide)

It was fun writing the comparer.
Quote from: tiermat
that's not science, it's semantics.

Re: Advent of Code
« Reply #1160 on: 09 December, 2023, 08:15:32 pm »
Day 8, a bit of a cheat because I wrote GetSteps as normal function but the resulting Linq is still pleasing

(click to show/hide)
Quote from: tiermat
that's not science, it's semantics.

Re: Advent of Code
« Reply #1161 on: 09 December, 2023, 10:30:12 pm »
Day 9, that was interesting, I've never used Zip before

(click to show/hide)
Quote from: tiermat
that's not science, it's semantics.

Re: Advent of Code
« Reply #1162 on: 10 December, 2023, 05:12:11 pm »
Day 10 pt 2 started to be interesting.
(click to show/hide)
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Advent of Code
« Reply #1163 on: 10 December, 2023, 07:08:08 pm »
Day 10 part 2:-

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #1164 on: 10 December, 2023, 07:16:45 pm »
Day 5 part 2:-
(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #1165 on: 10 December, 2023, 07:38:03 pm »
Day 10 part 2:-

(click to show/hide)

(click to show/hide)
Quote from: tiermat
that's not science, it's semantics.

jwo

Re: Advent of Code
« Reply #1166 on: 10 December, 2023, 11:14:28 pm »
Day 10 part 2:

(click to show/hide)

jwo

Re: Advent of Code
« Reply #1167 on: 13 December, 2023, 07:02:18 pm »
Day 13

I enjoyed this one. Not so much in getting an answer, but in doing so efficiently.

(click to show/hide)

Re: Advent of Code
« Reply #1168 on: 13 December, 2023, 08:42:59 pm »
Day 13

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

jwo

Re: Advent of Code
« Reply #1169 on: 13 December, 2023, 10:19:21 pm »
Day 13

(click to show/hide)

Re: Advent of Code
« Reply #1170 on: 18 December, 2023, 12:31:26 pm »
Day 18

(click to show/hide)

Total time for 2023 so far (up to and including day 18) is 0.378s, so still a few left to optimise (days 17, 16, and 14 take the longest).
"Yes please" said Squirrel "biscuits are our favourite things."

jwo

Re: Advent of Code
« Reply #1171 on: 18 December, 2023, 10:37:56 pm »
Day 18

Total time for 2023 so far (up to and including day 18) is 0.378s, so still a few left to optimise (days 17, 16, and 14 take the longest).

Impressive. Are you still writing them in C?

I've just totalled mine (JavaScript) up to and including Day 18. I come out at 1.3 seconds total, with those same slow days being over 80% of that time.

Day 18 was my favourite so far.
(click to show/hide)

(click to show/hide)

vorsprung

  • Opposites Attract
    • Audaxing
Re: Advent of Code
« Reply #1172 on: 19 December, 2023, 09:58:21 am »
Day 96
(click to show/hide)

Re: Advent of Code
« Reply #1173 on: 19 December, 2023, 10:29:33 am »
I don't know how long I've spent on AoC over the years but all of the time isn't wasted (it's not all 100% productive/useful either though). I'd probably guess it's at least 40h each year.

Like jwo (and Ross and mTrak) I've got all of the stars (so far, for all years) and that represents a significant amount of time that has been put into it, but I'd count this as professional development - plus the fact that I enjoy solving these kinds of puzzles.

I'm using it as a challange but mostly to get more comfortable in a new language (Go). I did all of the previous years in a mixture of shell, C and predominantly perl. Now most of my professional coding is in Go and so that's what I'm doing 2023 in. In my Copious Free Time (TM) I'm also going back and redoing all of the previous years in Go (have about 90 days left to do). This helps me understand how I would implement certain things in this language, notably:
* Numbers > 264
* Number theory (modmul, modexp, lcm, gcd, crt, ...)
* Recursion, tail recursion
* Parsing, regexp, sorting
* Memoization and Dynamic Programming
* Sparse grids using maps, 2D, 3D, 4D+
* BFS/DFS
* Dijkstra/A* and using structures like a heap queue to implement an efficient priority queue
* Trees (binary, n-ary, red/black, etc)
etc
"Yes please" said Squirrel "biscuits are our favourite things."

jwo

Re: Advent of Code
« Reply #1174 on: 19 December, 2023, 01:15:10 pm »
Wot Greenbank sed.

For me, over the years I've used AoC to improve my skills in Java, Elm, JavaScript and C++ as well as general data structures and algorithm competence. I also use it with students (from first year undergraduates to PhDs) to help them develop their algorithmic thinking, reasoning and communication. I didn't do a Comp Sci or Maths degree so AoC has been useful learning tool for me (and mostly fun).

I know Eric (the puzzle setter) creates these to help people learn, and some of the puzzles are very elegantly and subtly designed with that in mind. Clearly it's not for everyone, but for some (of us), a fun and rewarding activity.