Goto 10 RetroComputing: Atari and more

Share this post

Advent of Code 2022 in BASIC

www.goto10retro.com

Advent of Code 2022 in BASIC

Bonus Post!

Paul Lefebvre
Dec 7, 2022
4
2
Share this post

Advent of Code 2022 in BASIC

www.goto10retro.com

I was encouraged to give this year’s Advent of Code a try. If you’ve not heard of Advent of Code it is an annual programming puzzle that takes place in December. Each day leading up to Christmas has a new puzzle with two parts.

This was the first time I had looked at Advent of Code and decided to give it a try in BASIC. I of course used my favorite variant, OSS BASIC XE.

Share

After hooking up my account and downloading the sample data for the Day 1 project, I quickly realized my first challenge would be actually getting the data over and then reading the data in.

I used the Atari800MacX emulator. I’d have preferred to use my actual 130XE, but it’s not currently set up well for typing (plus its keyboard is not great, especially compared to the fancy mechanical one I use with my Mac). I copied the text file containing the data to one of the emulated hard drives (H4:), booted into DOS and copied the file from H4: over to the floppy image.

The data was in a standard text file which meant that each line was terminated in a LF character, which is ASCII 10. As many of you probably know, the Atari 8-bits don’t use standard ASCII. Instead they use a variant called ATASCII (ATari ASCII) and one of the big differences is that the line terminator character is ATASCII 155.

This means I could not use the standard commands to read a file line-by-line. Instead I used the BGET command (Byte GET) in BASIC XE to read the file one character at a time, looking for a LF and building the data character by character. This was also tricky because of the weird string handling that most Atari BASICs use. But once I got this figured out, the rest of the AoC Day 1 problem was pretty straightforward.

My program (in FAST mode) take about 5 minutes to run to spit out the answer for part 1 and and slightly longer for part 2 since it has to loop through the results a couple more times.

CleanShot 2022-12-05 at 21.16.43.gif

Other than FAST mode and BGET I didn’t use any other BASIC XE features. I haven’t yet had time to look into the subsequent projects, but I’m sure I will at some point.

If you liked this post, let me remind you that Goto 10 is having a year-end sale. Save 20% on a yearly paid subscription and get access to double the posts and other extra perks, including a disk image with this Advent of Code program.

Join the free Goto 10 mailing list to be notified of other great retrocomputing content as soon as it is published!

2
Share this post

Advent of Code 2022 in BASIC

www.goto10retro.com
Previous
Next
2 Comments
Mark Miller
Dec 8, 2022Liked by Paul Lefebvre

Atari800MacX separates its hard drive numbers into drives that translate between ASCII and ATASCII, and those that don't. If you try H6:, it should work. Look in the Help documentation, under Preferences and Hard Drives tab.

Expand full comment
Reply
1 reply by Paul Lefebvre
1 more comment…
TopNewCommunity

No posts

Ready for more?

© 2023 Paul Lefebvre
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing