#BabelOfCode 2024
Week 1
Language: Applesoft BASIC
NEXT WEEK: mastodon.social/@mcc/113783248…
"Advent of Code" is an online event where you're given 25 two-part code puzzles, which you're supposed to solve in 25 days in December. I was busy so instead I'm doing a slow-motion, 1-puzzle-per-week version over the course of 2025, but with an added restriction: I have to do it in a different language each week.
@unjello proposed a hashtag, so maybe there are two of us on this
mastodon.gamedev.place/@unjell…
(1/2)
Questa voce è stata modificata (9 mesi fa)
Oblomov reshared this.
mcc
in reply to mcc • • •My rules for this challenge:
mastodon.social/@mcc/113676228…
And my language candidates list (note C and C++ are NOT on it):
mastodon.social/@mcc/113676267…
As I go I will be posting my progress here:
github.com/mcclure/aoc2024
For week one I'm doing Applesoft BASIC, for a few reasons: I want to get it out of the way on an early, easy puzzle; and two, it was my first language, on an Apple //c at age 6, so there is a poetry to starting there.
(2/2)
GitHub - mcclure/aoc2024: Advent of Code 2024 challenge (laid-back/"babel" version)
GitHubmcc
2024-12-18 22:39:45
mcc
in reply to mcc • • •Language confidence level: Medium-high
"Day 1" is all manipulation on lists of numbers, so this fits BASIC nicely. It's simple enough I believe I'll be able to do it in BASIC without struggles, but complex enough I have to use a language feature I've never used (arrays).
With some difficulty ( mastodon.social/@mcc/113739186… ), I've set up the AppleWin emulator; I'm going to use this tool as an "IDE" to write the code:
mastodon.gamedev.place/@xot/11…
But I'll be loading into AppleWin to generate results.
mcc
in reply to mcc • • •mcc
in reply to mcc • • •So far largest difficulty is typing something, getting a SYNTAX ERROR, staring at it not being able to figure out what was wrong, and then realizing I used a lowercase letter
NO lowercase letters!! there is NO SUCH THING as lowercase letters. "x" this is not a variable!! it is not anything!! "X" ok that's better
yuubi
in reply to mcc • • •as the dos 3.3 system master disk says if you boot it on a new enough machine,
BE SURE CAPS LOCK IS DOWN
mcc reshared this.
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Generation Z might be wondering: What's up with the 30,000?
We didn't have "editors" on C64/Apple era BASIC! Instead you'd type into the REPL lines beginning with a number, and saying like
10 PRINT "BUTTS"
would be "load this line into the program at index 10". At runtime it executes all lines in order. You'd usually leave 10 between each statement in case you needed to insert something in between. In the case of the DATA, I want it to go at the end, so it's close to the limit of 32768.
Oblomov reshared this.
mcc
in reply to mcc • • •10 A = 4
20 B = 5
and then later you realize you need more than 9 statements between 10 and 20? THEN YOU'RE IN BIG TROUBLE.
You are going to be retyping a bunch of stuff, with repeated use of LIST and CTRL-C, and then maybe introducing bugs because those line numbers doubled as GOTO targets. We actually used to live like this
Brent Cook
in reply to mcc • • •mcc
in reply to Brent Cook • • •Jae
in reply to mcc • • •mcc
in reply to Jae • • •Jae
in reply to mcc • • •mcc
in reply to Jae • • •Jae
in reply to mcc • • •Paul Lalonde
in reply to mcc • • •yuubi
in reply to mcc • • •there were some slight mitigations to the retyping though. the editor was weird and was mainly "right arrow over text on the screen types the character unless you're in move mode (which you toggle with esc)
]LIST 20
]25 space, esc, arrow-keys to get to the start of line 20 after the line number, esc, right-arrow over the text, enter
]20 enter (to delete the copy with number 20)
if you want to skip some text, you can esc and arrow over it; to add more, esc, move somewhere else on the screen to type it, esc and move back to the text you want to copy.
there were also line renumbering programs, which i think weren't part of the base "os".
i'm pretty sure this was in the base apple //e, only saw a plus about once and never did much to it.
mcc
in reply to mcc • • •Roy
in reply to mcc • • •It's good to be reminded occasionally that things have gotten better. 🙂
mcc
in reply to mcc • • •"A Touch of Apple //", Apple Computer, 1986
Left: Section "Break a Few Rules"
Right: Table of contents, final section of book
mcc
in reply to mcc • • •reshared this
Oblomov e Matteꙮ Italia reshared this.
JP
in reply to mcc • • •mcc reshared this.
Owen Nelson
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •UPDATE: LOL, oh no, oh *no*. After running for quite a while and me writing the above comment, my program prints the following one (1) line. That means the first two smallest numbers in two columns are 565 and 743, and the difference between them is 224. Neither of those numbers is in the list. In fact, every number in the list is five digits.
I'M WORKING WITH SHORTS. MY PROGRAM WORKS, BUT MY COMPUTER IS TOO WEAK TO PROCESS NUMBERS OVER 65,536. I HAVE NO IDEA WHAT I'M GOING TO DO NEXT LOL
Oblomov reshared this.
Paul Lalonde
in reply to mcc • • •Paul Lalonde
in reply to mcc • • •mcc
in reply to Paul Lalonde • • •Avi Drissman :vm:
in reply to mcc • • •mcc
in reply to Avi Drissman :vm: • • •mcc
in reply to mcc • • •Avi Drissman :vm:
in reply to mcc • • •OK, now you’re teaching me. There is a difference between int and float arrays? Wow it’s been too many decades.
Probably worth switching to float arrays.
mcc
in reply to Avi Drissman :vm: • • •stilescrisis
in reply to mcc • • •You're using integer BASIC. Emulate an Apple IIe with a disk drive and use the modern floating point BASIC instead.
EDIT: It's not integer BASIC
Something spooky named Gregly
in reply to stilescrisis • • •stilescrisis
in reply to Something spooky named Gregly • • •@gregly yup I figured that out and posted it immediately below the post you replied to 😀
At this point I'm guessing something is weird about DATA/READ but it's only a hunch.
mcc
in reply to stilescrisis • • •stilescrisis
in reply to mcc • • •mcc
in reply to stilescrisis • • •stilescrisis
in reply to mcc • • •Something spooky named Gregly
in reply to mcc • • •stilescrisis
in reply to Something spooky named Gregly • • •@gregly There goes that theory! Thanks for checking it.
(Is it cheating to debug the program in a faster, easier to work with BASIC and then finish by running it on the Apple II?)
mcc
in reply to stilescrisis • • •stilescrisis
in reply to mcc • • •@gregly I was thinking something like calormen.com/jsbasic/
Although it sounds like you solved it?
Applesoft BASIC in JavaScript
www.calormen.commcc
in reply to Something spooky named Gregly • • •Something spooky named Gregly
in reply to mcc • • •@stilescrisis I mean, not particularly vital since it didn’t reveal anything new 😅
But I thank you for that bit of motivation. It’s been a while since the days when I floored my teachers with my uncanny ability to… copy programs out of magazines.
What can I say, they were very easily astonished. 😑
mcc
in reply to mcc • • •Okay ok so talking to some people with contemporaneous memories and consulting the manual more carefully, I *think* the *variables* are 40-bit floats, but the *array* I'm using for storage is clipping to signed 16-bit. So I think I can fix my program by converting the array declaration to use floats.
The manual… *suggests* DIMs can have a type, but… doesn't explain how I specify it.
I'll figure this out… but first I'm going to walk around the block, eat some fried rice and angrily play Tetris.
Dag Ågren ↙︎↙︎↙︎
in reply to mcc • • •Dag Ågren ↙︎↙︎↙︎
in reply to Dag Ågren ↙︎↙︎↙︎ • • •DIM - C64-Wiki
www.c64-wiki.comDag Ågren ↙︎↙︎↙︎
in reply to Dag Ågren ↙︎↙︎↙︎ • • •mcc
in reply to Dag Ågren ↙︎↙︎↙︎ • • •Avi Drissman :vm:
in reply to mcc • • •mcc
in reply to Avi Drissman :vm: • • •Avi Drissman :vm:
in reply to mcc • • •mirrors.apple2.org.za/Apple%20…
You should get real arrays automatically if you don't use %. However, I'm completely doubting myself now, so lemme hack in Virtual II and see.
Avi Drissman :vm:
in reply to Avi Drissman :vm: • • •mcc
in reply to Avi Drissman :vm: • • •i'm gonna have to run a few different test programs, and probably verify that the CYAN||DE ide is giving the same results as the AppleWin emulator.
stilescrisis
in reply to mcc • • •There's two entirely separate BASIC implementations. There's a tiny integer-only one written by Woz and a more full-featured one written by Microsoft. What do you get if you try to execute PRINT 0.1 ?
EDIT: mcc was using Microsoft BASIC
mcc
in reply to mcc • • •@avidrissman YOU WERE RIGHT mastodon.social/@mcc/113745200…
mcc
2024-12-31 03:00:14
Avi Drissman :vm:
in reply to mcc • • •It’s never the ~compiler~ emulator 😀
In any case, it’s a blast watching you wrestle with Applesoft; enjoy the beginner-mind.
mcc
in reply to Avi Drissman :vm: • • •mcc
in reply to mcc • • •mcc
in reply to mcc • • •Okay so before proceeding I need to show you my Tetris score from the arcade. This is not actually very good, but it is not *bad*. This represents one week of practice with TGM3. Notice also my Easy record, which I got during warmup today. It's decent. Someone had left a stuffed Cinamaroll on the Tetris cabinet and it kept me company.
That out of the way…
mcc
in reply to mcc • • •I AM A FOOL!!!!!!!!
When I took the screenshot earlier that made me abort and question all my assumptions about Applesoft BASIC, I believed I was seeing a printout of `PRINT A(SMI(0),0),A(SMI(1),1),DIFF`.
I wasn't!!! I had several REM'd PRINTs and the uncommented one said `PRINT SMI(0),SMI(1),DIFF`.
Those numbers I posted earlier, which I believed represented values being truncated?
No!!! Those numbers were INDEXES!!
The screenshot above showed my code WORKING CORRECTLY!
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Apologies to everyone ( retro.pizza/@gregly/1137451313… ) who spent time trying to help me fix my entirely nonexistent bug.
Since I now *believe* I have a working program,it's time to move it to the "regular" emulator to actually run it.
CYAN||DE has a "Get Disk" button, which exports all the saved programs from your current browser session plus ProDOS 2.0.3 to a disk image. Here's my disk, with a hello world program, the two sample programs, and the hypothetical "real" one (with clearer debug prints)
Something spooky named Gregly
2024-12-31 02:42:46
mcc
in reply to mcc • • •Running the programs on my exported disk, TEST is empty; it looks like I saved it wrong. Well, whatever. SAMPLE and SAMPLE2 run totally as expected. So I expect PUZZLE to run. But there's still a problem: My program is still really slow.
I'm tired. I'm grumpy. I say, fuck it. I decide to cheat, just a little. I overclock the emulator.
…oh, that runs MUCH faster.
mcc
in reply to mcc • • •mcc
in reply to mcc • • •Part 2 looks actually slightly easier than part 1, but I am done for today. I have a pretty amazing headache right now! Maybe I shouldn't have intentionally chosen to spend my day off from my job programming doing the most unnecessarily difficult programming challenge I could think of
EDIT:
Run instructions in run.txt
github.com/mcclure/aoc2024/tre…
My 01-01 source code:
github.com/mcclure/aoc2024/blo…
aoc2024/01-01-lists at stable · mcclure/aoc2024
GitHubLawful Regime Change Now! 🇺🇦
in reply to mcc • • •"Maybe I shouldn't have intentionally chosen to spend my day off from my job programming doing the most unnecessarily difficult programming challenge I could think of"
I can't remember a time since Y2K when I *didn't* spend my long periods of time off from my job programming doing hobby programming on Linux.
jhamby
in reply to mcc • • •Nice. Very readable. I'm not used to seeing LET in front of variable assignments since it's not required, but now that Rust is popular, it looks more modern. For loops where it matters, it helps to know how to shave every extraneous token & REM.
Some folks think mistakenly that % integer vars are faster, but on MSFT 8-bit BASIC, they're actually slower than the default because it converts them to/from FP for math.
ProDOS patches Applesoft BASIC with a fast string GC not in MSFT/Commodore.
mcc
in reply to jhamby • • •@jhamby I went with the LET because in the CYAN||DE IDE it would cause those lines to have a highlight at the start that distinguished them from REMs…
I actually got 😠s from a friend once by making a programming language which was ML-like but used BASIC-like LET statements instead of ML-like LET statements and they are not the same (in functional programming languages, it's expected every instance of "let" creates a new lexical binding… in Emily 1 it did… not exactly this.)
jhamby
in reply to mcc • • •mcc
in reply to mcc • • •I said I was done for the evening, but instead of going to bed I went ahead and did an attempt at the next problem, because it looked *so* easy. This time I used an advanced technology I'd never used in Applesoft BASIC before: for loops. Of course, it does not work.
Check this out. I've got two nested FOR loops for AIL and AIR. If you look at "PRINT AIL,AIR", it seems each time AIR increments, it's incrementing *BOTH* the AIL and AIR variables. AIL doesn't exist on line 271; line 280 thus fails
mcc
in reply to mcc • • •This *looks* as if nested for loops simply aren't supported, and the inner loop screws up the outer one. Fine. Except looking in "Applesoft Basic toolbox" (Addison-Wesley microcomputer books, 1984, vintageapple.org/apple_ii/pdf/… page 183) I see a flat out claim that this works, as long as I unroll in the correct order and don't GOTO out.
Does anyone see an obvious error I made and am not noticing because I ought to be in bed? This couldn't possibly be a Prodos/Applesoft BASIC difference, could it?
mcc
in reply to mcc • • •Holy shit. Holy shit. Holy shit. Holy shit. This was it.
mastodon.scot/@nettles/1137458…
All letters in an Applesoft Basic variable name after the first two are *advisory*. Basically a comment
Steve Wozniak— I have never had reason to say this before in my life, but— Steve Wozniak, you have done me wrong
( Possibly this is actually on Bill Gates? He has done me wrong previously actually. mastodon.social/@mausmalone/11… )
Annette
2024-12-31 05:45:32
Oblomov reshared this.
Irenes (many)
in reply to mcc • • •Irenes (many)
in reply to Irenes (many) • • •mcc
in reply to Irenes (many) • • •mcc
in reply to mcc • • •STEVE WOZNIAK, I HAVE SLANDERED YOU, YOU ARE WONDERFUL AND YOU HAVE NEVER DONE ANYTHING BUT IMPROVE MY LIFE
plush.city/@fluffy/11374593064…
fluffy 💜
2024-12-31 06:06:02
Oblomov reshared this.
mcc
in reply to mcc • • •I've done it! It took me 35 or 36 years, three scanned reference manuals, and the help of multiple people on a global telecommunications network, but for the first time in my life I have SUCCESSFULLY WRITTEN A WORKING FOR LOOP IN APPLESOFT BASIC.
I will now write no more Applesoft BASIC for the rest of the week, probably the rest of my life. If I ever need to write an Apple // program again I'm writing my own assembler.
Run instructions:
github.com/mcclure/aoc2024/tre…
Source:
github.com/mcclure/aoc2024/blo…
aoc2024/01-02-lists at stable · mcclure/aoc2024
GitHubOblomov reshared this.
Tom Forsyth
in reply to mcc • • •slembcke
in reply to mcc • • •mcc
in reply to slembcke • • •mcc
in reply to mcc • • •Something spooky named Gregly
in reply to mcc • • •Zeh Fernando
in reply to mcc • • •Brad Grzesiak 🦆
in reply to mcc • • •* function calls can be implicitly abbreviated up to the point of ambiguity
* one universal data type, which is implicitly coerced to string, integer, or floating-point data types as context requires
* globals persist between executions
Meg
in reply to mcc • • •mcc
in reply to Meg • • •mcc
in reply to mcc • • •mcc reshared this.
Rhialto
in reply to mcc • • •mcc
in reply to Rhialto • • •Annette
in reply to mcc • • •mcc
in reply to Annette • • •mcc
in reply to mcc • • •cassie
in reply to mcc • • •mcc
in reply to cassie • • •cassie
in reply to mcc • • •I’m not sure at what point, I’ve only been following other people doing it this year.
(Although thinking about it more—maybe you don’t need to worry? I think all the early ones are probably thoroughly randomized and within a few weeks people probably won’t care much about spoilers for this year’s problems.)
Something spooky named Gregly
in reply to mcc • • •jhamby
in reply to mcc • • •When I got into RISC OS on the Raspberry Pi a few years ago and discovered BBC BASIC, I was angry for a few days that such a good BASIC never got exported outside the UK, for the most part. Apparently they were going to try to sell in the US, and had patched the ROM to recognize "COLOR" as well as "COLOUR", but Jack Tramiel had a price war going and they figured the BBC Micro wouldn't have been competitive with the C64, Apple II line, etc..
Applesoft BASIC has a really bad line editor.
reshared this
mcc e Oblomov reshared this.
Rachel Stantz
in reply to mcc • • •stilescrisis
in reply to mcc • • •There are two BASICs. One is integer only and one is floating point. It should be easy to tell the difference (e.g. try PRINT 0.1)
According to this, the floating points use five bytes per number so it should hopefully be sufficient, albeit very slow: groups.google.com/g/comp.emula…
How did the Apple II do floating point?
groups.google.comstrangefour with the Pleiades
in reply to mcc • • •slembcke
in reply to mcc • • •Jae
in reply to mcc • • •aeva
in reply to mcc • • •Efi (nap pet) 🦊💤
in reply to mcc • • •I do have some books on this, but they diverge too much towards other less interesting aesthetics
ideaPDish
in reply to mcc • • •ideaPDish
in reply to mcc • • •I think I now believe that the fetishizing of beautiful objects is a slipery slope into the world of porn... wait.. not people porn, but
seductive objects or books, catalog pictures, and displays an demos that make you drool, then that once you get them leave you cold and empty on the inside, craving more.
The whol point of wich is having the desire, not the thing itself.
Duke of Germany 💫
in reply to mcc • • •This looks incredible! 😍 I would buy it just for the cover!
@mcc
stilescrisis
in reply to mcc • • •Not really! Most BASICs included RENUM which would renumber your lines automatically. Not sure about Apple II, but Apple IIgs and MS-DOS BASIC could do this.
Also, you can smash as many statements as you like on a single line with the : mark. The only limitation is that you can't target those statements via a GOTO/GOSUB.
Fish Id Wardrobe
in reply to mcc • • •all the basics I used (which doesn't include yours) had RENUMBER.
I fondly remember a BBC basic error message:
> renumber 0,0
*silly
Alley Stoughton
in reply to mcc • • •Play Ball and Fight Fascists
in reply to mcc • • •BASIC was my first programming language, too! But I was ancient compared to you - learned it on an Apple IIe when I was 12.
That was really fun and I probably should have pursued it more aggressively.
Charlotte
in reply to mcc • • •mcc
in reply to Charlotte • • •Charlotte
in reply to mcc • • •mcc
in reply to Charlotte • • •@Foritus oh yeah! I should actually add TCL to my list.
I've been working with FPGA stuff and to my absolute shock the entire FPGA ecosystem is completely stuffed with TCL? I think the idea is Verilog is a bit unfriendly and TCL is easy to slap on as a preprocessor in a language that doesn't expect to have a preprocessor. So I'm talking to the deep horrors electrical engineering people and the only programming language they know is… TCL
Clifton Royston
in reply to mcc • • •@Foritus
This finally explains to me why Spirent, where I was a software contractor almost 20 years ago, had so much TCL all over the place. (Lots of FPGA-based products for network load emulation and similar activities.)
Arch 💕
in reply to mcc • • •woooah! clojure!
that language has just so many super-cool ideas in it, and so many neat little experiments
there's a lot of really neat picks in here

good luck with the challenge!
mcc
Unknown parent • • •J3RN
in reply to mcc • • •mcc
Unknown parent • • •mcc
Unknown parent • • •Klara in the hidden land
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •mcc
Unknown parent • • •fluffy 💜
Unknown parent • • •fluffy 💜
in reply to mcc • • •reshared this
Oblomov reshared this.
Jordan
Unknown parent • • •mcc
Unknown parent • • •reshared this
Oblomov reshared this.
Pare
Unknown parent • • •Sensitive content
@mausmalone Also, some versions of BASIC had the RENUMBER command, which basically would take all the lines in the code and, well, renumber the lines, usually by default to be at invervals of ten.
Of course some versions of the command, like the C=64 expansion Simons’ Basic, didn’t touch the GOTO or GOSUB commands when doing this. You can imagine how badly this mangled any program.
Oblomov reshared this.
mcc
Unknown parent • • •@tomjennings Yeah, I don't know what I would have done if the AOC input had turned out to be too large to fit in the emulator RAM…!
I also wonder what would have happened if someone on here hadn't spotted the two letter issue. I guess I would have rewritten the code to use GOTOs, and at some point realized the problem was the AIL/AIR variables, not the FORloops themselves…
sergio_101
in reply to mcc • • •@pare @mausmalone
The thought of running into this in the wild makes my head feel like it's gonna explode..