What are you coding?

My neighborhood has a yearly tradition of doing a bicycle parade on Independence Day. One of the residents usually rides his motorcycle and performs the role of the grand marshal.

I questioned why there needs to be a motorcycle at all- the surprising answer was that a lot of the neighborhood boys like to race and the motorcycle is able to set a pace they can compete to maintain.

Races are fine. But let things be parades, too.

2 Likes

Looks as though https://everybody.codes/ is going to be running again from Monday.

(I have no interest in racing and the puzzles tend to come out at inconvenient times for me anyway.)

2 Likes

Considering the day I had… it is not surprising that part 2 of Day 1 of Advent of Code took me hours to figure out. I solved part 2 half asleep … I guess that’s something, too.

What is not helping is that the auto-complete of my IDE almost solved part 1 on its own without me telling it about the actual puzzle (and i doubt the chatbots can get the solutions that are published today into their models this fast)

So my brain went on auto-pilot. For part 1. And then for part 2 I had not really thought the problem through I had just sleep-walked my way through some object orientation that more or less told the IDE what it was supposed to program.

But part 2 is confusing enough that the auto completion cannot solve it. Yay for confusing problems.

Because I had not thought it through … and additional object oriented programming was not going to crack it… it took me very needlessly long.

I ended up creating a parameterized unit test to debug the thing. I only solved it however when I added a test-case beyond the websites example … not because I had not thought of it before but because when I saw the result my brain’s pattern matching realized what I had been doing wrong with the failing test cases (yes half asleep it still works, maybe I usually imagine I am sleeping)

    @ParameterizedTest()
    @CsvSource({"L68,1,82","L30,0,52","R48,1,0","L5,0,95","R60,1,55","L55,1,0","L1,0,99","L99,1,0","R14,0,14","L82,1,32","L300,3,32"})
    public void testSomething(String turnAsString, int zeroesExpected, int valueExpected){
        ...
        Assertions.assertThat(dial.value).isEqualTo(valueExpected);
        Assertions.assertThat(zeros).isEqualTo(zeroesExpected);
    }

I software-developed my way through the problem or what I call “brute force problem solving by way of endless test cases”

Solution.

3 Likes

For me it was the classic AOC Day 1, whereby I started with Part 1 assuming that Part 2 would just blow the scale out of the water, so I did the usual math trickery most anybody (well, most anybody prone to doing a coding Advent Calendar) would do.

And then Part 2 made me stop and blink exactly 3 times, once for each time my brain spun around in my head – not because Part 2 was mind-altering on its own… but rather, I couldn’t easily slot into my brain the mathematical model to account for the new wrinkle.

And so, as with many of these… I resorted to some brutish force… or… at least… a bit of deoptimization, because the scale was entirely doable in less than a second.

3 Likes

This morning I briefly considered if there was a trick to be found by ignoring the ordering of commands but I think not. I had no bandwidth for math last night … I really need to consider turning off the auto-completion circus.

2 Likes

The interesting angle of day 1 for me was that some languages define -5 % 2 == 1, some as -1. Rust gives me % for -1 and the rem_euclid() method for +1. (But it’s rarely enough important that I mostly just use % and I forget what the other one is called.)

I enjoy Everybody Codes but I’m seeing a lot more interesting subtlety in the AoC puzzles so far. (Had a glimpse of day 2, no time to work on it yet.)

3 Likes

I haven’t had a look at AoC yet this year but from my memory I thought the first few days tended to be straightforward, even for beginners? Have they adjusted the difficulty now that there are fewer days? I quite liked how accessible it was for the first week or so.

1 Like

This year it’s down to only 12 days rather than 25, because of the length of time it takes to construct the puzzles. I’d say the first two have been relatively simple problems, but needing care in the programming. (There’s an interesting subtlety here that wasn’t as present in this year’s Everybody Codes.)

(spoiler day 2)

I don’t like stringifying numbers, so I didn’t. That may have made my solution rather more complex than it needed to be, but I had fun with it. Glad I found the ext-range crate a couple of years ago, though, which gives you the primitives to do reliable range intersections; it makes life much easier!

Regexes? Where we’re going, we don’t need regexes.

3 Likes
Day 2 Spoilers

I really wanted to delve into string pattern reverse-globbing and coming up with an optimized approach… but reverse-globbing is something I’ve tried to wrangle before and, in my experience, is long-winded for little payoff.

So I wrote a function to detect where the number of digits changes in a range, split those, and then iterate the range and checking for repeated digits.

Crude and brute-forcey yet again :slight_smile:

2 Likes

Completed day 1, part 1 and 2 in Python. Completely brute-forced part 2 as I didn’t fancy figuring out the maths.

3 Likes

Hmm no regexes today. Would have been neat though. Maybe I might add that later.
I am still writing unit tests. Am I getting old or what?

Anyhow here’s the main part

    static boolean isInValidProduct(String product,int repeat){
        int length = product.length();
        if(length % repeat != 0) return false;
        int sequenceLength = length / repeat;
        return product.substring(0, sequenceLength).repeat(repeat).equals(product);
    }

Not pretty. I got no time for pretty this year.
edit: just noticed i built in a mistake. but dinner is calling. I have my stars it’s just a mess I made in “post”. Later.

3 Likes

Day 2 done as well, I also avoided regex.

python’s built in functions made this super straightforward once i realised I just had to count for substrings and compare it to the length

2 Likes

how i didn’t think of regex is beyond me. it’s by far one of my favorites to solve problems.

2 Likes

Day 3 done. Quite liked the jump from part 1 to part 2 which felt like a logical next step while introducing interesting complexity. Took a few tries to get it right but got there eventually.

2 Likes

I was treating 2 as a special case of 1 rather than as a special case of infinity.

(I don’t try to second-guess how part 2 will change things. I just know that it will and try to keep things flexible.)

2 Likes

Same. But I pivoted to a recursive approach for part 2.

Overall, I rather enjoyed Day 3. It’s a shame the ones I enjoy the most are the ones I can do quickly.

2 Likes

Day 3. Nice puzzle, not too hard. But

  • first recursion
  • first BigInteger also known as stupid java long overflow
  • first off-by-1

I almost gave up but then added another testcase: I had one for 2 flips and for 12 flips obviously. Adding one for 4 proved enlightning. So I did finish and now I am off to bed.

But can someone explain to me why the first method works for smaller numbers and the second for larger but I can stil convert the result to long afterwards.

(Low spoiler, just some multiplcation math for the final result)

long calculateVoltage(List<Integer> flips){
    return flips.stream().map(f -> batteries[f]).reduce(0,(sum,f) -> sum*10+f);
}

BigInteger calculateVoltageBigInt(List<Integer> flips){
    return flips.stream().map(f -> BigInteger.valueOf(batteries[f])).reduce(BigInteger.ZERO,(sum,f) -> sum.multiply(BigInteger.TEN).add(f));
}

PS the auto completion completely did the conversion of the first method into the 2nd. Which I found quite impressive even though it seems so simple.

Full Solution.

Day 4: I think I just don’t like having to write adjacency checks on a grid. Give me individual lines as my input any day. Not difficult just needs a few loops that feel like a waste of time. I suppose some AI autocomplete might solve that for me but I haven’t got on well with them in the past.
Part 2:

Weirdly straightforward? Like, take part 1 and put it in a loop and you’re done? Didn’t find it very interesting compared to earlier days, although I suppose there’s probably a smarter solution by checking the original layout instead of just looping through and removing stuff

2 Likes

Well, my “grid” is a HashSet of coordinate pairs, which makes it more fun. I convert that out into a HashMap with value zero at the set points, calculate neighbours, then filter that back to build the grid for the next cycle.

2 Likes

Since I already have a Matrix helper class that did all the heavy (or not so heavy) lifting for today. It was the most straightforward day today, especially for anyone who has previously done these coding problems.

Today I was able to complete the problem during my lunchbreak.

I also found out that one more of my colleagues (one is on vacation to be able to concentrate on AoC) is also semi-seriously attempting the puzzles and we made another one quite curious to try some of them :slight_smile:

3 Likes