Forum menu
Advent of Code
 

Advent of Code

Posts: 1748
Free Member
 

...


 
Posted : 14/12/2021 12:48 pm
Posts: 1335
Full Member
 

Day 14 was another quick one. Quite liked it but you could pretty much guess where part 2 was going to head..


 
Posted : 14/12/2021 1:16 pm
Posts: 8857
Full Member
 

I've just got round to Day 6 - lanternfish. I assume it's going to need some kind of clever coding to cater for part 2 to not make my laptop go pop?

using namespace System.Collections.Generic
$newlist = [List[int]]@()
$myList = [List[int]]@()

[int[]]$new

$lanternfish = Get-Content .\Day6.txt

$lanternfish.Split(",") | ForEach {
$mylist.add($_ )
}

for ( $i = 0 ; $i -lt 80 ; $i ++ ) {

$mylist | foreach {

If ($_ -gt 0 ) {
$new = $_
$new --
$newlist.add($new)
}
ElseIF ($_ -eq 0) {
$newlist.add(8)
$newlist.add(6)
}
}
$mylist = $newlist
$newlist = [List[int]]@()
}

$mylist.Count


 
Posted : 14/12/2021 5:15 pm
 Aidy
Posts: 2977
Free Member
 

I assume it’s going to need some kind of clever coding to cater for part 2 to not make my laptop go pop?

Yep.


 
Posted : 14/12/2021 5:40 pm
Posts: 3323
Full Member
 

Not got d14p2 yet. Yes, knew what was coming based on the use of the phrase 'This polymer grows quickly' in the description, but can't see a way to do it yet


 
Posted : 14/12/2021 6:13 pm
Posts: 1335
Full Member
 

If you want a hint...
The way I did it - there may well be better - I just kept track of the number of each pair. You don't need to know the order. You do, however need the first and last letter.

Then each generation - each Pair - for example NN becomes the same number of the two new pairs.

After all your generations - add how many of each letter you have, add the end ones, then divide by 2 to get the actual numbers (pairs double count all the letters except the end ones - but you've added those).

Now you have a (in my case) Map N -> 1234, C -> 4321, etc.

Edit - reading that, not sure it makes much sense.


 
Posted : 14/12/2021 6:55 pm
 Aidy
Posts: 2977
Free Member
 

If you want a hint…

I'm not sure that's a hint, so much as a spoiler.


 
Posted : 14/12/2021 7:41 pm
Posts: 403
Free Member
 

I'm just catching up - spent FAR TO LONG on the second half of day 12.

I was getting all the right answers for the test cases, but the wrong final answer for the real test data, which was a bit miffy as that was the first wrong answer submitted.

Spent half an hour looking at the code changes for p2 which were about 5 lines, only to find the true problem was a single line route length sanity check right out of the way I put in last night when I started it and mocked up the recursive search function, and the p2 changes made routes much longer than that, but all the test data was fine.

Doh. On to day 13.


 
Posted : 14/12/2021 8:09 pm
Posts: 403
Free Member
 

I’ve just got round to Day 6 – lanternfish. I assume it’s going to need some kind of clever coding to cater for part 2 to not make my laptop go pop?

Don't think about fish, think about where they go to learn.


 
Posted : 14/12/2021 8:12 pm
Posts: 2809
Free Member
 

You lot are clearly geeks, you'll know - Javascript, what's the best way to learn it, good beginner resources etc?

Any answer that starts with "ignore it and learn "x" instead will be given a good stiff ignoring, it's JS or nowt apparently.


 
Posted : 14/12/2021 9:35 pm
 Aidy
Posts: 2977
Free Member
 

Do you know any other programming languages?

And, what do you need to learn JS to do? Most of the interesting JS is using some kind of framework - you probably want to start from the right one.


 
Posted : 14/12/2021 9:37 pm
Posts: 2809
Free Member
 

Nope, complete beginner.

No idea why, it's just something they've been told they could do with learning for work. Yes, it's a very vague requirement!


 
Posted : 14/12/2021 10:03 pm
Posts: 3323
Full Member
 

w3schools


 
Posted : 14/12/2021 11:21 pm
Posts: 0
Free Member
Topic starter
 

I'm sure there must be a cleverer way of doing Part 2 today, but I just made a coffee whilst my workspace was running instead 🙂


 
Posted : 15/12/2021 9:46 am
Posts: 2809
Free Member
 

@LLama - Thanks for that - it looks like it should do the job, I might even have a go myself.


 
Posted : 15/12/2021 10:12 am
 Aidy
Posts: 2977
Free Member
 

I’m sure there must be a cleverer way of doing Part 2 today, but I just made a coffee whilst my workspace was running instead 🙂

I'm not even sure how to do part 1 in a reasonable amount of time


 
Posted : 15/12/2021 12:04 pm
Posts: 1335
Full Member
 

That took longer than I'd be happy telling my boss!

I'm not sure there's a quick way to search all the possibilities. I managed to get part 1 down to <1s but part 2 was about a minute to run (2019 MacBook with an i9).

Is there a clever way to do it so that it's not just crunching away?


 
Posted : 15/12/2021 1:32 pm
 Aidy
Posts: 2977
Free Member
 

Devised a reasonably efficient way of solving part 1, finally.


 
Posted : 15/12/2021 2:00 pm
 Aidy
Posts: 2977
Free Member
 

... and it only took a couple of seconds to execute for part 2, which was nice.


 
Posted : 15/12/2021 2:29 pm
 Aidy
Posts: 2977
Free Member
 

Huh, I'd not actually seen the common algorithm used to solve the problem before.

I'm reasonably impressed with myself that I managed to invent it for myself relatively quickly.


 
Posted : 15/12/2021 2:55 pm
Posts: 1335
Full Member
 

@Aidy - throw up a link to the common algorithm, will you? Intrigued


 
Posted : 15/12/2021 4:43 pm
 Aidy
Posts: 2977
Free Member
 

@euain - RGlqa3N0cmE= (base64 encoded)

My input grid is sufficiently large that I can't work out how you get a solution for part 1 that doesn't scale linearly for part 2.


 
Posted : 15/12/2021 6:23 pm
Posts: 1335
Full Member
 

Thanks - will have a play. 🙂

Happy to share my non-optimal solution if interested but I'm pretty sure this is going to be much better.


 
Posted : 15/12/2021 6:28 pm
 Aidy
Posts: 2977
Free Member
 

Happy to share my non-optimal solution if interested but I’m pretty sure this is going to be much better.

Yeah, if you wouldn't mind.

My initial approach was to try to brute force every possible route, which worked okay for the sample set, but failed pretty miserably for the input. Tried a few approaches around making that more efficient, but it was fairly obvious that there were just too many permutations at that scale for it to ever fly.


 
Posted : 15/12/2021 6:44 pm
Posts: 0
Free Member
Topic starter
 

I've not attempted today's in just FME yet, I've completed it with FME/Python, I'm pretty sure part 1 is possible but I'm not sure I can be bothered as it will be a pain! Too much hard work understanding the puzzle today rather than actually solving it


 
Posted : 16/12/2021 6:17 pm
Posts: 1335
Full Member
 

It was a bit of a slog to work out what they were wanting. Nice wee recursive function at the end which was satisfying to see work.


 
Posted : 16/12/2021 6:30 pm
 Aidy
Posts: 2977
Free Member
 

Fiddly one today. I still haven't gotten part 2.

Passes the examples, and the first few params look okay (after decoding by hand), but I'm not getting the right answer :/


 
Posted : 16/12/2021 6:47 pm
 Aidy
Posts: 2977
Free Member
 

Oh, I missed the stupid prefix


 
Posted : 16/12/2021 7:07 pm
Posts: 1335
Full Member
 

Today was easy enough. Carried on with a slow brute-force solution (45s to solve) to part 2 but rejigged for 0.4s :).


 
Posted : 17/12/2021 2:12 pm
 Aidy
Posts: 2977
Free Member
 

Yeah, I just brute forced today. Wasn't proud of it.


 
Posted : 17/12/2021 2:26 pm
Posts: 3323
Full Member
 

had to put on hold now due to trying to get the stuff I'm paid for done in time for hols

might give todays a shot later


 
Posted : 17/12/2021 2:41 pm
Posts: 1335
Full Member
 

Mid dog-walk, worked out how to do part 1 with pen and paper (and managed to prove to myself there couldn't be any higher values of height that I hadn't reached). 14ms for the solution to b now :).


 
Posted : 17/12/2021 3:59 pm
Posts: 8857
Full Member
 

Finished Day 6Pt2 Lanternfish. Quite simple in the end but again, techie code issues muddied the water. Getting better tho.


 
Posted : 17/12/2021 5:32 pm
 Aidy
Posts: 2977
Free Member
 

Fiddly one today. Not really difficult, just some annoying code to write.

At least part 2 was trivial.


 
Posted : 18/12/2021 2:45 pm
Posts: 1335
Full Member
 

Yup, that sums it up. A bit of a slog on this one - and I managed to mess up the "get the number to the right of this one" stuff in a way I didn't spot for a while (trying to be too clever).

The folding one is still my favourite so far. (Or yesterday's one about launching drones but that's just because I managed to work out the first bit with a pen, paper and calculator - and that was being lazy).


 
Posted : 18/12/2021 8:02 pm
 Aidy
Posts: 2977
Free Member
 

Gosh, today's was hard work.


 
Posted : 20/12/2021 12:33 am
 Aidy
Posts: 2977
Free Member
 

Today's was a bit sneaky, but went okay.


 
Posted : 20/12/2021 11:55 am
Posts: 1335
Full Member
 

Found Sunday's bloody hard work. Plenty of chance to get thoroughly confused for me.

Relief that today's was a lot easier - though I was disappointed I didn't get a nice picture out at the end. (Or maybe I should have and my output isn't working properly?). Not sure about sneaky - they repeated "it's infinite" a few times but took a wee bit of head scratching.


 
Posted : 20/12/2021 12:05 pm
 Aidy
Posts: 2977
Free Member
 

Properly confused by part 2 today


 
Posted : 21/12/2021 10:48 am
 Aidy
Posts: 2977
Free Member
 

Worked it out, that required a lot of thinking.


 
Posted : 21/12/2021 2:31 pm
Posts: 1335
Full Member
 

Agreed - took a bit of thinking about and my clever shortcut didn't work at all and I had to start again.

Then I was getting the wrong answer and thought it should be right. Parked it to do some proper work. Fresh eyes found I'd managed to overtype something and put a bug in my code that works out the position when you add the dice roll to your current position. Step 1 was fine - step 2 was never returning position 10. Doh..


 
Posted : 21/12/2021 3:56 pm
Posts: 1335
Full Member
 

Annoying today - mine was just about working but numbers were slightly off. In a messy bit of code I was checking a "xmin" instead of "zmin" - so my cuboids weren't as they should be! OK after that.


 
Posted : 22/12/2021 5:12 pm
 Aidy
Posts: 2977
Free Member
 

I really can't seem to get today's to work, I'm doing something weird with calculating a compound sum, I think.


 
Posted : 22/12/2021 5:35 pm
Posts: 0
Free Member
Topic starter
 

I'm playing catchup as busy over the weekend but now away on holiday and it's peeing it down so it's keeping me occupied


 
Posted : 22/12/2021 5:53 pm
Posts: 1335
Full Member
 

I think mine's pretty solid for today so happy to supply alternate test cases / debugging scenarios if that helps.


 
Posted : 22/12/2021 6:07 pm
Page 3 / 5