Wednesday, December 04, 2019

Coding for Fun and Advent of Code

My friend Mike Zamansky is a big proponent of the Advent of Code – 25 days of coding problems leading up the Christmas. Since I have been thinking I want to write more code for my personal enjoyment I started in on it myself. Day 1 and Day 2 were interesting (to me) problems and I enjoyed doing them. Day 3 didn’t appeal to me. It looked like something I would want to be paid to write so I didn’t do it. Day 4 looks interesting so I plan on taking it one some time today. After all, it is not coding for fun if it isn’t fun. I’m not looking to prove anything to myself or anyone else at this point in my life. Mike has been blogging about the problems he has been doing from a teacher’s perspective. I highly recommend his commentary https://cestlaz.github.io/

The Day 2 problem was particularly interesting to me though. It is a very simplified computer simulator. Only 3 instructions – 1 for add, 2 for multiply, and 99 for halt. with each of the first two operators having three parameters – location of the two numbers to operate on and the location to save the result. It is potentially self modifying code if any of the addresses points to an operator later in the list of instructions.

The obvious enhancement is to add more operators – division and subtraction for sure. Having a set number of parameters makes things easy so having variable numbers of parameters adds some complication. The more I thought about expansion the more I found myself contemplating a more complete “assembly language” especially as I found myself thinking about literal data and pointers as different types of parameters. Maybe I spent too much of my career writing in various assembly languages. In any case, as a thought exercise I found myself going far beyond what I would want to assign to a beginning programmer.

So I am pulling back a bit. I’m thinking about several smaller pieces. The easy part of a simulator with a few more operators. But maybe, also, what would a compiler look like that would create input for such a simulator? How would it load data into appropriate places? That’s a more advanced project but maybe something for me  to write to make it easier to create input for the simulator?

If nothing else, looking at Advent of Code is giving me ideas for both students and myself. Now that is fun.

1 comment:

  1. The ideas it spurs are one of the reasons I enjoy the event. I've never solved all of them, however. I completed 13 in 2015, 20 in 2016, 6 in 2017 and 12 last year.

    Sometimes I lose interest but it's also frequently that things come up and can't work on or complete a problem in a day (or it's just to hard for me), I start to fall behind and then never get back to things.

    I also have a hard time motivating myself to do problems where I have to a large amount of lay the ground work busy code.

    ReplyDelete