aoc-forth

Advent of code solutions in UF forth
git clone git://git.alexwennerberg.com/aoc-forth
Log | Files | Refs | README

commit ce9751898e3f8c62d89b90005fe7f657b6b7785b
parent 0c47913ca94bd41591e28550cf21254083be18d5
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Fri, 11 Nov 2022 19:26:19 -0800

Rename files, add slides for twitch stream

Diffstat:
A2021/01.f | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
D2021/01.fs | 57---------------------------------------------------------
R2021/02.fs -> 2021/02.f | 0
R2021/template.fs -> 2021/template.f | 0
A2022/.gitkeep | 0
Aslides | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 170 insertions(+), 57 deletions(-)

diff --git a/2021/01.f b/2021/01.f @@ -0,0 +1,55 @@ +h# 5000 constant filespace + +: initfile s" input01.txt" filename ; + +: readnum + 0 ( return val ) + begin + ( push char to stack [awkward] ) + filespace 1 fileread filespace c@ + swap over h# 0a <> and while ( not [newline or eof] ) + h# 30 - swap 10 * + ( convert ascii val ) + repeat + drop +; + + +: solvea + initfile + 0 + readnum + 2000 1 do + readnum dup -rot > 0<> 1+ rot + + swap + loop + drop +; + +: 3dup 2 pick 2 pick 2 pick ; + +variable total +variable last + +: solveb + initfile + readnum readnum readnum \ read 3 nums + 2000 3 do + 3dup + + dup \ sum + last @ + swap < 0<> negate total +! + last ! \ store variable + rot drop \ remove oldest value + readnum + loop + total @ +; + + +: boot + s" input01.txt" filename + solvea . cr + solveb . + bye +; +save 01.rom \ Replace with soln number +bye diff --git a/2021/01.fs b/2021/01.fs @@ -1,57 +0,0 @@ -h# 5000 constant filespace - -: initfile s" input01.txt" filename ; - -: readnum - 0 ( return val ) - begin - ( push char to stack [awkward] ) - filespace 1 fileread filespace c@ - swap over h# 0a <> and while ( not [newline or eof] ) - h# 30 - swap 10 * + ( convert ascii val ) - repeat - drop -; - - -: solvea - initfile - 0 - readnum - 2000 1 do - readnum dup -rot > 0<> 1+ rot - + swap - loop - drop -; - -: 3dup 2 pick 2 pick 2 pick ; - - - -variable total -variable last - -: solveb - initfile - readnum readnum readnum \ read 3 nums - 2000 3 do - 3dup + + dup \ sum - last @ - swap < 0<> negate total +! - last ! \ store variable - rot drop \ remove oldest value - readnum - loop - total @ -; - - -: boot - s" input01.txt" filename - solvea . cr - solveb . - bye -; -save 01.rom \ Replace with soln number -bye diff --git a/2021/02.fs b/2021/02.f diff --git a/2021/template.fs b/2021/template.f diff --git a/2022/.gitkeep b/2022/.gitkeep diff --git a/slides b/slides @@ -0,0 +1,115 @@ +( Slide deck for my advent of code Forth challenge + Written for https://wiki.xxiivv.com/site/adelie.html +) +SIZE 30,1c + +( Intro + +Points to cover: +- I'm Alex +- Going to talk about what I'll be doing this year for Advent of code + +) + +NAME Introduction +FILL 03 +MODE 0c +GOTO 04,08 +HEAD Advent of Code 2022: UF Forth +MOVE 02,07 +TEXT Alex Wennerberg + + +( slide 2 + +- Explain advent of code +- I'm going to stream it on Twitch, every day at 9PM! I'll also post VODs on Youtube +- Going to try to do all 25 days, but work/life and my forth skills may get in the way +- Going to try and do some fun stuff / visualizations + +) + +NAME Advent of Code +FILL 03 +GOTO 2c,08 +GOTO 04,0d +HEAD Advent of Code +GOTO 06,15 +TEXT - Daily puzzle challenge Dec 1-25 +MOVE 00,03 +TEXT - Vibrant, growing communtiy since 2015 +MOVE 00,03 +TEXT - Any language or approach! + +( slide 3 -- forth + +- A bit of background / history about forth +- Extremely simple +- Very "low level" +- Magical, bizarre. Unlike any programming language I've ever used. Ineffable. + Once I started reading about it, it consumed my interest. +- I hope more people experiment with Forth. Forth is extremely niche, but I + believe it is strongly underrated. Forth is the most radical alternative I know + of to the trends of mainstream computing. +) + +NAME Forth +FILL 03 +GOTO 04,08 +HEAD Forth +MOVE 03,06 +TEXT - 1970 Chuck Moore: Stack-based, concatenative language +MOVE 00,03 +TEXT - Radically minimalist +MOVE 00,05 +TEXT "You really can write a complete FORTH in, say, 2000 lines of code. I don't just +MOVE 00,03 +TEXT mean a FORTH program, I mean a complete FORTH operating system, environment and +MOVE 00,03 +TEXT language. You could boot such a FORTH on a bare PC and it would come up with a +MOVE 00,03 +TEXT prompt where you could start doing useful work. [...] It's possible to +MOVE 00,03 +TEXT completely understand the system. Who can say they completely understand how +MOVE 00,03 +TEXT Linux works, or gcc?" - Richard Jones + +( slide 4 -- uf + +- There is no "one forth", there are "forths" +- The forth I will be using is UF, created by Felix Winkelmann +- a forth for the uxn/varvara "fantasy console", developed by Devine Lu Linvega +- Varvara is a small computing system to run simple audio/visual applications. Runs on the UXN virtual machine +- What we'll be working with: 64KB of memory, file/device io, a screen with 4 + colors and 2 layers +- Look into the UXN ecosystem, there are some amazing things happening there +- This slide show presentation is written in it! +) + +NAME UF +FILL 03 +GOTO 04,0d +HEAD UF +GOTO 06,14 +TEXT - A Forth targeting the UXN/Varvara virtual machine +MOVE 00,03 +TEXT - 64KB memory + +( slide 5 -- conclusion + +- Looking forward to this! +- Let me know if you're doing this +- Follow me on mastodon if you use it, Or twitch or youtube + +) + +NAME Conclusion +FILL 03 +GOTO 04,0d +HEAD Going forth +MOVE 02,06 +TEXT mastodon: aw@merveilles.town +MOVE 00,03 +TEXT twitch: twitch.tv/0000 +MOVE 00,03 +TEXT site: 0000.lol