Advent of Code 2025 in Charly
Day 1
This article is part of my series on implementing each Advent of Code 2025 challenge in my own programming language Charly.
Today’s challenge involved determining the final dial position, given
a series of turn descriptions. The second part had me modify the
solution, to instead determine how many times the dial clicked past the
0 position.
#!/usr/local/bin/charly
if ARGV.length < 2 {
print("Missing filepath")
exit(1)
}
const input_file_path = ARGV[1]
const input = readfile(input_file_path)
class Dial {
property limit = 100
property dial = 50
property total_zeroes = 0
func turn(dir, count) {
count.times(->@click(dir))
}
func click(dir) {
switch dir {
case "L" {
@dial -= 1
}
case "R" {
@dial += 1
}
}
if @dial == @limit {
@dial = 0
}
if @dial < 0 {
@dial += @limit
}
if @dial == 0 {
@total_zeroes += 1
}
}
}
const dial = Dial()
const operations = input
.split("\n")
.map(->(line) {
const dir = line.substring(0, 1)
const count = line.substring(1).to_number()
return (dir, count)
})
operations.each(->(op) {
const (dir, count) = op
dial.turn(dir, count)
})
print("dial: {dial.dial}")
print("total_zeroes: {dial.total_zeroes}")Changes to the stdlib / VM
Today’s challenge exposed a lot of shortcomings, notably the lack of
any string processing capabilities. Additionally, for some
reason, the remainder (%) operator wasn’t implemented
yet. I stumbled over this fact while experimenting with the REPL
interface of the language. Computing the remainder of two constants
worked just fine, but threw an exception when actual variables were
involved.

It turned out that my AST optimizing pass understands how to constant-fold remainder-operations, but the actual VM didn’t. I quickly added the missing opcode and the error went away.
The full set of changes can be found in the following commits
264a8e2Implemented a readfile function640313aShebang support617020bString::split, String::substring, String::index_of5f412a4Added String::to_number86fec8bImplemented mod (%) opcodef0405b7Implemented Number::floor
My
apprentice at work @HartoMedia
implemented a getenv builtin method which allows you to
read a value from the process environment variables.
9a3beeaImplemented getenv builtin function
Links
Copyright © 2024 - 2025 Leonard Schütz | Attributions This post was written by a human and reviewed and proof-read by LLMs