What are you coding?

Tripping some antivirus thingy?

1 Like

I guess Chrome/Windows wasn’t happy with it being download. Copy&Paste saved the day.

Enjoyed day 8 much more than day 7 :smiley:

There was probably a prettier way to do it, but happy to arrive at a solution quickly.

3 Likes

Day 9 feels like AoC in a nutshell. Code works on the example, but there’s something implied or assumed from the description that doesn’t quite work on the real data and I’m not sure if I can be arsed to debug it.

I’ve written some maths to work out the vector additions needed, my guess is it’s not working in one of the diagonals with negative co-ordinates.

2 Likes

The problem in my case was blatantly using the wrong variable in an addition. :slight_smile: Maybe I should call them something other than xh, xt, xd, etc.

3 Likes

I just wrote a debug routine to print out the state at each iteration.

.....|.....
.....|.##..
.....|..##.
.....|TH##.
.....|...#.
-----s###--
.....|.....
.....|.....
.....|.....
.....|.....
.....|.....
~~~
13

Still none the wiser.

3 Likes

If you want to pm the code I’ll gladly look at it, but that diagram looks right (assuming that s, T and H are all being counted as T-locations, and the total is right for that).

3 Likes

Nothing wrong with my code, it was the parsing of the input. They introduce something mean about halfway through and I hadn’t scrolled or debugged that far.

3 Likes

Having the debug printout for part 2 was certainly handy. Should have guessed that would be how they extended things.

2 Likes

I finally got to Day 7 and it took me a good little while, too. Back in highschool my comp science teacher was known to worship at the Altar of Recursion. Over my years as a dev though I have come avoid it like the plague and yet… it seemed a better solution here. At least for the data structure needed.

I also spent some time solving a problem that wasn’t asked for and I needed some iteration to help my recursion because… I am just human and my brain thinks more straight-forward than I usually assume:

Once the data structure is parsed, the processing... becomes this:
int sumOfSmallDirs = directories.stream().map( Directory::size ).filter( s -> s<100000 ).reduce( 0, Integer::sum );
int sizeOfOptimalDir = directories.stream().map( Directory::size ).filter( size -> space + size > needed ).min( Integer::compareTo ).get();
3 Likes

I can do recursion if I need to, but very often when the Obvious™ solution is recursive, I find myself using a queue or stack instead (e.g. tracing all possible routes through a graph).

3 Likes

As I am trying once more for elegant code I needed to look up some stuff and stumbled across this banner on Stackoverflow that I swear wasn’t there last Thursday:

I had to google GPT… but I mean from the banner it was immediately clear someone has built a powerful enough AI that it’s becoming a problem because AI’s right now only seem intelligent …

I had been evaluating github coPilot for work before I started advent of code. It worked quite well for writing tests especially. But as soon as I began to tackle solving actual puzzly pieces of code the copilot became so annoying with its suggestions (none of which were correct), I had to turn it off.

Pattern recognition alone will–in my absolutely not humble opinion–NEVER lead to a superintelligent AI. Pattern recognition sadly works well enough that its inherent stupidity is already causing problems. The creators say it is a form of artificial intelligence and the consumers (people) tend to assume that intelligence means the same thing in all contexts.

2 Likes

As far as I can see, the effect of ChatGPT is to make random (or training-poisoned) answers look superficially plausible because they’re expressed in grammatical sentences. In effect it’s what Douglas Adams was writing about in Dirk Gently’s Holistic Detective Agency:

"Well, it was a kind of back-to-front program. It’s funny how many of the best ideas are just an old idea back-to-front. You see there have already been several programs written that help you to arrive at decisions by properly ordering and analysing all the relevant facts so that they then point naturally towards the right decision. The drawback with these is that the decision which all the properly ordered and analysed facts point to is not necessarily the one you want.

[…]

“Well, Gordon’s great insight was to design a program which allowed you to specify in advance what decision you wished it to reach, and only then to give it all the facts. The program’s task, which it was able to accomplish with consummate ease, was simply to construct a plausible series of logical-sounding steps to connect the premises with the conclusion.”

In an ideal world, this realisation would cause people also to look at the content of things people said rather than their form. I don’t think this will happen.

As for day 10:

I did it inside-out, building a time-based array of x values, and reading it out with

[ 20 40 220 { } for ] {
    dup xtrack exch get mul
} map { add } reduce ==

(Yes, my PostScript utility library contains implementations of map and reduce written in pure PostScript.)

I wasn’t expecting an off-by-one error in part 2, but at least I have some idea of what they look like when they happen. Nor was I expecting x to remain in the range 1..40.

4 Likes

Day 10 was fine. Felt like part 1 was a little bit disconnected from part 2 even it it did get some of the required parts in place.

2 Likes

Day 8. The only part about it that was neat was parsing the input.

int[][] treePatch = input.map( line -> line.chars().map( c -> c - 48 ).toArray() ).toArray( int[][]::new );

The rest… I am like Taravangian on a bad day today. First it took me forever to get the matrix transposition right. Then it was even worse for part 2. Stupid index manipulations … I considered figuring out something object oriented to solve this… but I couldn’t think of anything pretty enough.

PS: I just had a look at Day 9 and I think my head wants to explode.

3 Likes

Day 9. Waaah. So many mistakes. And then it all came down to intelliJ telling me I should have used the builtin compare function all along.

The key piece
if ( Math.abs( this.row - head.row ) >= 2 || Math.abs( this.col - head.col ) >= 2 )  {
   col = col + Integer.compare(head.col, this.col);
   row = row +  Integer.compare(head.row, this.row);
}

Part 2 just made the code uglier. It is way past midnight and I am still 2 days behind.
Around 430 lines of code now.

3 Likes

In the BASIC I learned first, abs was matched with sgn, which would give -1 for negative numbers, 0 for 0, +1 for positive numbers. I ended up reimplementing that here.

3 Likes

My partner just sent me this. As with all things on the internet, the age of this is indeterminate…

4 Likes

Forth, PostScript: Everything stack was what if?

1 Like

Day 10 was a lot easier than day 9. Except for how I already had the solution for both parts–though my first crt column had mysteriously moved to the other end of the display like one of those old TVs–and then I tried to refactor it to look better and now I don’t have the solution. For part 1 I used to test-input and result to finetune the initial values for both clock and register because I can’t read apparently.

I have given up finding that bug

    static AtomicInteger clock = new AtomicInteger( 0);
    static AtomicInteger register = new AtomicInteger(1);
    static List<String> crt = new ArrayList<>();
    static int WIDTH = 40;
    private static int day10Part1( Stream<String> lines )
    {
        AtomicInteger frequency = new AtomicInteger(0);
        lines.forEach( line -> {
            frequency.addAndGet(computeCycle(0));
            if ( line.startsWith( "addx" ) )
            {
                frequency.addAndGet(computeCycle( Integer.parseInt(line.substring( 5 )) ));
            }
        });
        crt.forEach( System.out::print );
        return frequency.get();
    }

    private static int computeCycle(int delta){
        int cycle = clock.incrementAndGet();
        int X = register.addAndGet( delta );
        crt.add((Math.abs(X - (cycle%WIDTH))<=1 ? "#" : ".") + ( (cycle)%WIDTH ==0 ? "\n" : ""));
        return List.of(20,60,100,140,180,220).contains( cycle ) ? cycle * X : 0;
    }
1 Like

Day 11: code is done, looks easy enough. I wonder if it is quicker to process the input by hand rather than writing a parser. edit: I decided to go with my alltime favorite regexes…

3 Likes