Friday 4 January 2013

BASIC programming and VIC-20 emulation

I enjoy a maths problem. A friend sends me one every Friday.

The type of question determines the best way to go about solving it. I like it best when I can write out the problem as an equation and work out the answer.

Some problems can only be solved (as far as I can see) by 'testing' different numbers. This was the case today and I managed to get the correct answer with a spreadsheet. But with more than one variable, this was a bit of a tedious process.

This is where BASIC programming comes into its own. As a teenager I would have tapped out a few lines of basic into my Vic-20 and had an answer very quickly.

I've tried to solve such problems more recently using C and my usual development environment with various degrees of success.  Those used to writing CLI tools may argue that it's very easy to tap out a few lines of C, compile and run the app and get an output. But I've run into various problems, and no question about it - that's not as easy as this:

Today's problem was about sharing a box of chocolates (we don't know the total number) and one boy ends up with the same number of chocs as the percentage that his brother has. We need to know the smallest numbers for which this can be true. You can see here the two possible answers for numbers up to 100 chocs total. (20 chocs and 5 chocs (20%) out of a box of 25 and 50 chocs each (50%) from a box of 100)

I haven't written a BASIC prog like this for about 30 years, but it all flowed from the fingers very naturally. With a few more minutes of messing about I could have refined it and have a much smaller and more efficient programme.

Two points. First it's awesome to be working in such a small space. You can see that there are 3583 bytes to work in (yes, bytes. That's about 3.5k). The computer had a bit more on board but some is used by the screen. I bought an 8k ram pack for my Vic which seemed a massive amount of space at the time. (it brings to mind this challenge which involves writing a game in 140 characters!)

Second, this kind of programme could be written by a classroom of newbies in the first lesson. I'm well behind the Raspberry Pi project, but I'm not convinced it will inspire new coders like our 8-bit machines did. Switch it on with very little knowledge and within seconds you've filled the screen with your name. With a little more knowledge you'd made a small animation and after that made a simple game. My suggestion is a basic interpreter in the Applications folder of OSX and windows (and Rasp Pi). (As I have now!)


  1. This comment has been removed by the author.

  2. I'm with you Shiela, I think you can't beat simple basic for inspiring kids (tested on Cain who was 5 at the time) and for tackling little problems like todays maths question.

    I once used a basic program to help me work out how to cut wind turbine blades from plastic guttering, as well as various little games and odds. My formal introduction to creating algorithms (hash tables, binary search, linked list etc) was all done using basic on Commadore Pets. But at home I was very much a sinclair kinda guy.

    I did borrow a Raspberry PI and I wasn't overly impressed. Seems it misses a lot of marks, being neither one thing or another. It's certainly underpowered to be a small computer running Gnome, and it doesn't come in a case. Yet when aimed towards electronics projects it really needs add-on interfaces. When I turned it on, I wanted to just see a blinking cursor - laffs, just like the old days.