The Joys Of Programming

I liked days 16 and 19 - they build on each other, and they both have that vibe where there's no single flash of insight that trivializes the problem. Rather, there's just a big space to search, and it's too big to do naively, and there are a number of possible ways to pare it down. Neat problems.

Day 20 today was a dud. Reasonably straightforward to solve, but a lot of typing and finagling with off-by-one errors until you get there. At least for me.

That said:

Moggy wrote:

Day 13 - I saw all them nested brackets and just noped out. Need to man-up

Here's one way to do that bit in JS:

var parsed = eval(inputStr)

fenomas wrote:
Moggy wrote:

Day 13 - I saw all them nested brackets and just noped out. Need to man-up

Here's one way to do that bit in JS:

var parsed = eval(inputStr)

:D

Yeah. You can do it in Python as well. I'm assuming that gets you a nested list variable and you then put all those into one final list and then .sort() ?

Oh, I had no idea Python had an eval. But yes, that's what I did - eval'ed and then sorted with a compare function. (But then after submitting I wrote a parser so I could feel like I'd done a day's work.)

The Codingame AI Bot Fall Challenge has started, and there's still 12 days left. If you're curious what one of these looks like, you can see someone working through the first league here:

Seems like the new VSCode Server is out for everyone now and you enable it by using the “code tunnel” command.
https://code.visualstudio.com/docs/r...

I tried that briefly on my dev server and got an error so I haven’t had a chance to use it yet. Gotta find some time to debug the issue. Anyone else here try it yet?

Lately I’ve been using a Chromebook as my dev client machine which is really convenient when I want to sit anywhere in my house and get some stuff done. I installed ChromeOS’ Debian based Linux environment and was able to easily get VSCode working in that using the official deb file. Since I’m doing remote development on my dev server the Chromebook does little more than run the VSCode frontend. I’d still rather have to install nothing at all on the laptop so I’ll be trying to get that new VSCode server working. TBH Linux on a Chromebook is surprisingly good. I tried using Remmina to RDP into my dev server as an alternative and it didn’t perform as well as the local VSCode. Microsoft RDP client Android app wasn’t working for me on the Chromebook for some reason.

It’s kinda entertaining being able to develop on a potato but I’m probably going to move to a full laptop at some point here just for the bigger screen and full keyboard.

Mixolyde wrote:

The Codingame AI Bot Fall Challenge has started, and there's still 12 days left.

I submitted my first code to the arena and it kicked ass! I fine tuned my strategy until it could beat Boss 1 in the IDE before submitting.

It's now battling in the Bronze league, but seems to be tapping out in the 300s. It's also getting spanked by Boss 2 in the IDE.

Not sure if we should talk about strategy here or not. What do you think?

A week later, I finally finished an Elixir version of Day 15, part 2, that runs in milliseconds, and it's correct on the real input, but not the example, so I got my star, and I don't care. My long national nightmare is over.

I finally got time to start today. Almost done Day 3. I sometimes wonder if I should be writing good quality code, or just whatever it takes to get the answer. I can see Day 12 coming back and asking me to do something with the Day 2 code and I am kicking myself for using a lot of nested for loops and if statements.

Moggy wrote:
Mixolyde wrote:

The Codingame AI Bot Fall Challenge has started, and there's still 12 days left.

I submitted my first code to the arena and it kicked ass! I fine tuned my strategy until it could beat Boss 1 in the IDE before submitting.

It's now battling in the Bronze league, but seems to be tapping out in the 300s. It's also getting spanked by Boss 2 in the IDE.

Not sure if we should talk about strategy here or not. What do you think?

Congrats! That's a huge first step. I used a version of the movement and single spawn bot from the end of the video above and it jumped me straight from wood league to silver, no recyclers needed. I plan to tweak this one a little to see if I can improve my rank a little before adding recycler logic. It looks like the Boss at my current level drops one well-placed recyclers every turn if it can. Hard to tell what its movement strategy is right now. I am fine with discussing strategy here, other player's talk general strategy on the Discord and forums, so I think it's fine. It's not like I have time to write some crazy simulation AI like I normally would.

I have three strategy threads I'm iterating on. One each for spawn, build, and move.

Build:

v1 - do not build
v2 - Max recyclers = 1
max build / turn = 1.
Build in the tile not in range of a recycler with max potential
v3 - Max recyclers = 1
max build / turn = 1. Only build if enemy has more units
Build in the tile not in range of a recycler with max potential
v4 - Max recyclers = 1
max build / turn = 1. Only build if enemy has more units
only build if I lost units last turn (to stop those situations where the map had split and I ate away my territory for scrap I didn't need)
Build in the tile not in range of a recycler with max potential

v1 caused me to be overwhelmed by enemy units pretty quickly after the enemy built a recycler
v2 solved that but caused me to be cut off from parts of the map
v3 seems to be better but I was experiencing cases where the map split and I dissolved my lead by spawning builders in my territory. Hence v4

Spawn:

v1 - spawn as many robots as possible in first tile
v2 - spawn as many robots as possible in random tile

v1 was a bust
v2 works better

Move:

v1 - pick random direction. Move all units
v2 - pick a random enemy tile. Move all units in tile
v3 - If adjacent is owned by enemy move there,
else if adjacent tile is neutral move there,
elsemove to random enemy tile.
if more than 1 unit, leave one behind

v1 was really random
v2 worked OK (got me to bronze), but didn't cut it in the bronze league
v3 seems to be working OK

so my v3/v3/v3 code had me with a score of 15.07 (rank 217) on the ladder.

changing to v4/v3/v3 got me a score of 17.99 (rank 11).

So I'm close. More intelligent spawning location next, I think

My current move strategy is:
1. Build a target list of enemy tiles without recyclers, and neutral tiles with at least one scrap (i.e. - not grass)
2. For each tile of mine with units, sort the target list by Manhattan distance ( abs(x1 - x2) + abs(y1 - y2) ), and move all units on that tile to the closest target.

Right now I am not handling ties for closest tile, or duplicate moves at all. I am thinking of some simple strategies for these cases, like removing a target tile from the list if it has been picked, or randomizing ties, etc.

My current spawn strategy is:
Sort the list of tiles I can spawn by lowest total Manhattan distance to all tiles with enemies. This tends to find the shortest average distance to enemies.
Spawn 1 unit on the first tile in the list.

This was enough to get me to Silver.

Just checking in to report that Advent day 22 part 2 is... kind of a bear. I flailed at it for a couple hours making no progress, then I took a walk in the park and thought of a way to flatten it down. But even then it was challenging to get the details and implementation right. Very satisfying once I finally got there!

(OTOH part 1 is just a setup for part 2, and will be trivial for anyone who's reached this point.)

I quite enjoyed day 22, although my solution is not robust enough to work on anyone else's input. I basically hardcoded the configuration of the cube faces. And I had to make a prop to help out:

IMAGE(https://media.mstdn.social/media_attachments/files/109/567/920/226/552/845/original/da18b16382cac00f.jpg)

That seems to be Reddit's 'prop du jour' for day 22. Along with distain for those who hard-coded the 14 edge cases.

I've been too busy to keep up for the last few days, but hope to knock off a couple of part 1s today.

All finished with Advent! Really nice of the author to furnish all the challenges.

As a pointless flex, I added a button to my test page that runs all 25 solutions in sequence, and they finish up in under two seconds on my potato laptop. Which seems good enough.

Day 22 part 2 was definitely the one that took the most thinking. I don't know if there's a better crazy twist way to do it, but my way was...

Spoiler:

...from staring at the diagrams for a while, it eventually occurred to me that if you walk the perimeter of the cube layout, everywhere you find an inner (concave) corner you know that the two nearest edges will match up when the cube is made. I then thought I'd seen the answer and I started typing, but later on I realized you can't just walk the perimeter from any concave corner, as some later edges won't match.

Then after more staring, I realized (?) that if you start from any concave corner and trace both edges, those edge stitch together until you reach a point where both traces have reached a outer (convex) corner. If you do that process starting from all interior corners you will have traced the whole perimeter and you now know all the edge connections and directions.

Then I coded all that up and it worked, and then I realized that the algorithm isn't actually universal - on layouts like the following it wouldn't find the outside edges:

..X... .XXXX. ..X...

But those layouts happen to be exactly the Advent part 2 would be trivial, as the outside edges would work just like in part 1. So I guess it's safe to ignore them here.

Then the final thing I realized was, I apparently don't know WTF the words "convex" and "concave" mean, as I used them wrong throughout my code comments (and also while typing this very answer).

A lot of fun stuff in this years Advent. I have working solutions to all problems, but some still take a while to run (almost a minute in some cases) so I'd like to go back and figure out how to do them more efficiently. I should also redo day 22 part 2 correctly too... I feel vaguely ashamed for not doing it more rigorously. fenomas, your solution is pretty smart, I will definitely steal your ideas!