What are you coding?

Day 18: OK that was a lot less work than the last couple.

Part 1’s nearly trivial with the right data structure, and part 2 is basically a DFS on that structure. (I thought about looking inside for empty cells with six neighbours, but then what about clusters of empty space?)

1 Like

I am still thinking how to begin solving Day 17. It looks a lot like I should be using bit manipulation and I have never used that before for any code I’ve written. Quite daunting.

PS: on the subreddit someone mentioned they solved (my) yesterday (+friday) aka Day 16 on paper and I did think it might be an option. One person made an excel sheet and treated it like a boardgame. apparently it took them 2 attempts to get the right number for part 1.

1 Like

Day 17: you don’t have to, but I think it’s probably easier that way than any other.

I think 17 might actually be doable on paper.

1 Like

I am going to try that. I’ll be learning something.
I just turned on the coffee machine to wake up my personal “numbers guy” to verify that my plans are indeed doable. And then I need to figure out the math/code I need. But it looks quite doable

  • represent each shape as a 2-4 7-bit numbers (those can be precalculated from the starting x)
  • move right and left are just bit-shifts (java does those with << and >>
  • in my naive mind moving down is just a sequence of additions
  • collision detection is still an open–that’s what I need my “numbers guy” for :slight_smile:

So all in all I am getting a sequence of numbers instead of a matrix.

1 Like

Got there in the end and it didn’t take too long for the answer to come out. Wasn’t as quick as some I’ve seen but I’ll take <10s without all that much optimisation other than what I’d already done for part 1.

2 Likes

Day 17 spoilers:

My partner complained about me renaming all the shapes so that the names have equal length. But it does wonders for the layout. Just saying. :rofl:

(The extra bits are for the walls, do you want to see an image of my partner drawing on my pseudo whiteboard to show me why he wanted them–he’s my numbers guy, I said so :heart_eyes: :smiling_face_with_three_hearts:)

2 Likes

A non-AoC question for a change…

I have a list of boxes. I have a list of items. Each box can contain at most one item, and has a list of the items that it can potentially hold. (Looked at another way, each item has a list of the boxes it can go into.)) How can I ensure the largest number of boxes is filled?

I have a procedure that more or less works (if only one available item will go in the box, put it there; if only one available box will hold the item, put it there; then guess a bit and repeat), but the result can vary. Given that I have 50+ boxes and 200+ items, I don’t want to try an exhaustive search…

1 Like

My brain is still full of Day 17… -.-
I can’t wrap my head around the example.

The L Shape falls falls falls, stops on top of the + but then it moves left one more time and falls again. At least that is what the out put suggests. I do “command < or >” execute if no collision found. Then I move down only if no collision found. And somehow I manage to do it right for the first 2 shapes and then fail for the third because somehow the third shifts left one more time. this is not happy making. Also my result for the actual input is too low, suggesting (as this is a space saving thing) that something else is amiss…

So boxes. One item per box. Numbers can do 50 bits right? As I said, my brain is stuck. Make each item’s boxes into a number of available boxes. Then you can do collisions between the items and find both those with just 1 bit set and boxes that only 1 item can go into. So you remove the items and flip the bits for the filled boxes and do the next iteration? This way you make sure that both items that are not flexible and boxes that are not flexibel are filled from both ends? And you’re left with the flexible items that can go in the left over boxes…? Something like that?

edit: if only I could count. “my L Shape was shifted over to the right by 1 position” But I am glad I posted because it made me look at it a little harder. Now I’ll take a peekaboo at part 2 of Day 17.

edit: I am regretting that I built this nice elephant enclosure in my Ark Nova Zoo today. Those mastodon descendants are crazy

2 Likes

Day 17: I am now stuck on the last bit of math because my brain is a bit exhausted. I have (sucessfully?) detected that there is indeed a cycle (which my partner wouldn’t believe)–so I can skip a lot of computations but I have now made 3 different attempts one of which using a calculator and nothing. The testinput has a horribly long period (at least that I can detect) and so it is a bit useless for further tests. Test period on the test input I find is=33.849.713 which I find unlikely now that I am thinking about it. I am probably doing something wrong with cycle detection.

1 Like

Day 17 part 2

I seem to have got fairly lucky on this one.

Each time the rock index returns to zero (i.e. after every 5 rocks) I store cycle number and jet index. When I see the same jet index for the second time, I’ve got a periodicity.

2 Likes

I don’t know anymore. I am stuck. I am using your method to detect cycles (before I used something I saw that included the relative height of the last blocks in each column). The site is not even telling me anymore if my solution is too high or too low.

I will probably somehow at some point solve this (usually right after the post where I am writing that I am giving up) but I am really not sure I want to start the next puzzle. I’ve been on this one since yesterday.

I think I have reached the limit of my ability to a point where every further step is very educational but also very hard and the cost (in time) is higher than I can afford this week.

3 Likes

18 was relatively easy. 19 is being a Pain.

1 Like

By way of not solving Day17 I now have restructured my code into a proper project with each day being in its own class and packages and all that java stuff. Maybe it’ll help because I think I need to refactor some stuff and in the scratch file that wasn’t working.

2 Likes

I’ve been bashing at 19 all day. Three versions in PostScript, none of which produces the right answer if it produces an answer at all. Just rewritten it in Perl and that’s plugging away…

1 Like

Day 19’s Perl version took many hours to come up with the wrong answer. Leaving that one for later.

Day 20:

PostScript uses a stack.

And I don’t have to care about the original start point, insofar as that’s even meaningful.

So: (1) have a stack of enumerated entries, (2) for each number 0…=n-1 find that entry ID and then roll the stack so that it’s at the top, (3) pull it out into a temp var, (4) roll the stack the right number of places, (5) stick it back in.

I solved Day17 part 2 late last night with my partner’s help who simply managed to pull (yet another variant for) cycle detection from his brain without even having to google it. Also I had a major “Brett vor dem Kopf” (plank in front of my head) thinking that whatever period was detected had to start at position 0. Well, no. Hours wasted thinking about how I was maybe off by 1 on an index. Secondary, brainfart: forgetting to reset the rock counter between part 1 and 2. Yay. Another hour gone. Sometimes…

A major help is that I refactored my “scratch” file into a real java project with separate classes for each day and now that allows me to leverage my developer skills to make changes faster and refactor my ways to a solution.

Weirdly, once I had that I began documenting methods with javadoc. I can’t help it.

Also intelliJ’s last update brought a beta-UI with it that is just so lovely and I enjoy working with it so much. So much that I bothered to give the new project its own coding style (my preferences as opposed to work style which is awful putting opening braces on new lines… and having only 120 characters when my monitor could do 250 easily–I put it at 150 by way of compromise)

I have started the naive approach to Day 18 part 1.

2 Likes

OMG… I am … so I began coding Day18 and I am thinking … what if… and so I accidentally began coding part 2 before part 1. But I haven’t solved part 2 yet, it is still buggy, at some point I noticed however that I might be doing more thanw as asked for in part 1. This happens in software development as well, you want to anticipate too much… part 1 was not hard for once.

1 Like

I think my part 2 could be simplified to solve part 1, but that’s not the part 1 solver I wrote.

1 Like

Day18 : So for part 2 I already wrote code that let me define the difference between “droplet” and “outside” by looking at the matrix from each side until finding a piece of droplet. While printing out slices of the matrix I noticed that there are some tricky bits there. Where there are coordinates that are “connected” to the outside but not visible from the outside. Once I have that I can reuse my part1 by just adapting the test for “what is a surface”

1 Like

Btw I have looked at that, it looks like a typical engine builder problem… shouldn’t us gamers be able to solve this easily? Possibly … on paper?

In other news, I noticed that I write javadoc comments on the methods that I think are complete and working, so I can concentrate on the ones that are not…

1 Like