Skip to content

Instantly share code, notes, and snippets.

@celestefox
Last active December 22, 2019 21:47
Show Gist options
  • Save celestefox/cb9ee0bbce263c079b90adfc6421624f to your computer and use it in GitHub Desktop.
Save celestefox/cb9ee0bbce263c079b90adfc6421624f to your computer and use it in GitHub Desktop.
Advent of Code Day 1 in Multi User Forth

AoC Day 1 in MUF

There's some needed setup to use this. You'll need to take your input and insert lsedit aocd1=input at the start and .end at the end, and save it as day1.txt (or remember what you named it and use that instead below).

Then, do this on a MUCK, from a user with at least a M1 bit:

@program aocd1.muf
q
@set aocd1.muf=1
@action aocd1=me
@link aocd1=aocd1.muf

Finally, quote the contents of aocd1.muf and day1.txt using your client. If everything went right, you should be ready to go: just run aocd1 and you should get your result.

@q
@edit aocd1.muf
1 9999 d
i
(aocd1.muf, v1.0, by glowpelt 12/19
A MUF program to solve Advent of Code day 1.
Looks for its input in the list 'input' on the action that ran this
program.
)
: fuelfor (i -- i)
3 /
2 -
;
: fullfuelfor (i -- i)
(Set up the sum)
var total
0 total !
fuelfor
begin
dup total @ + total ! (add current fuel to total)
fuelfor (next fuel step down)
dup 0 < (do we end yet?)
until
pop total @ (return the total)
;
: main
"me" match me ! (Enture me is who actually ran the program)
trig trigger ! (Ensure trigger is the actual trigger)
0 (Set up our sum)
trigger @ "input" array_get_proplist (Get the input)
foreach
swap pop (Remove the index)
atoi fuelfor (Get the fuel needed)
+ (Sum it up)
repeat
intostr "Part 1: " swap strcat me @ swap notify (Output the result!)
(Part 2, same as above except fullfuelfor)
0
trigger @ "input" array_get_proplist
foreach
swap pop
atoi fullfuelfor +
repeat
intostr "Part 2: " swap strcat me @ swap notify
;
.
c
q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment