Discuss Scratch

davidtheplatform
Scratcher
500+ posts

Advent of Code 2025

Discuss Advent of Code 2025!

adventofcode.com wrote:

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill levels that can be solved in any programming language you like. People use them as interview prep, company training, university coursework, practice problems, a speed contest, or to challenge each other.

I made a private leaderboard for the scratch forums, the join code is 4320286-dd2a1cad
Please don’t use any form of AI for your solutions.

Last edited by davidtheplatform (Nov. 30, 2025 19:36:49)

davidtheplatform
Scratcher
500+ posts

Advent of Code 2025

I'm doing AoC in scratch this year, here's my day 1 solution: https://scratch.mit.edu/projects/1249802630/
Redstone1080
Scratcher
1000+ posts

Advent of Code 2025

Decided to do it in Elixir for that sweet functional goodness. Array operations are so nice.
TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

For a challenge, I'll choose a random proglang/interpreter listed in this website and try to solve the problem there…

For Day 1, I got… F# (Mono). Great…
mybearworld
Scratcher
1000+ posts

Advent of Code 2025

I brute forced to effectively divide a number by two for the first part today. I don't think I write my best code at 6am…
davidtheplatform
Scratcher
500+ posts

Advent of Code 2025

I made a visualization for this one that I think looks vaguely like a christmas tree: https://scratch.mit.edu/projects/1250327339/



[I did a brute force solution, which takes a while in scratch (but only a few seconds in turbowarp). Looking around on the internet the non brute-force solution seems to be to generate possible invalid IDs using some math trick, then check which ones are actually in a range. I think brute forcing it is the intended solution.]
TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

TheSecondGilbert wrote:

For a challenge, I'll choose a random proglang/interpreter listed in this website and try to solve the problem there…

For Day 1, I got… F# (Mono). Great…
To clarify: I'm only considering practical languages. The website also serves recreational languages (read: esolangs), but I'm not insane enough to solve any problem using them.

Anyway, since we already past Day 1, I can show you my solution:

#nowarn "40"
let rec input = seq {
let line = System.Console.ReadLine()
if line <> null then yield! seq { // why make this difficult =(
yield line
yield! input
}
}

let toDelta (x : string) =
x.Replace("R", "").Replace("L", "-")
|> System.Int32.Parse

input
|> Seq.map toDelta
|> Seq.fold (
fun (acc, zeros) speen ->
let added = (acc + speen) % 100
(
added + (if added < 0 then 100 else 0),
zeros + (if added = 0 then 1 else 0)
)
) (50, 0)
||> (fun _ -> printfn "%d")

(I really want to use highlighting, but apparently `echo “f#” | seq s/#/sharp/g` is a cuss)

Not sure if I'll call this jank or cursed. I do love my iterators though (or in F#, sequences).

Last edited by TheSecondGilbert (Yesterday 08:11:23)

TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

Wait, I forgot the days come in 2 parts. Whoops.

Anyway, here's the 2nd part:

open System

#nowarn "40"
let rec input = seq {
let line = Console.ReadLine()
if line <> null then yield! seq { // why make this difficult =(
yield line
yield! input
}
}

let toDelta (x : string) =
x.Replace("R", "").Replace("L", "-")
|> System.Int32.Parse

let rec count x y first =
let click = if x = 0 && not first then 1 else 0
if y > 0 then
let x_next = if x = 99 then 0 else x+1
let clicks, rem = count x_next (y-1) false
(click + clicks, rem)
elif y < 0 then
let x_next = if x = 0 then 99 else x-1
let clicks, rem = count x_next (y+1) false
(click + clicks, rem)
else
(click, x)

input
|> Seq.map toDelta
|> Seq.fold (
fun (acc, zeros) speen ->
let clicks, added = count acc speen true
(added, zeros + clicks)
) (50, 0)
||> (fun _ -> printfn "%d")

I've completely given up with division and decided to just count the zeros manually. It's clearly not a divmod (which F# absolutely butchered by the way)

Anyway, Day 2 is going to be done in Moonscript. Time to code at Lua++.
TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

Day 2 done. Here's the solution:

N3q8ryccAASU++pwHgIAAAAAAAAjAAAAAAAAAG3ZqHoJmIYi0OlTWAp6LgN213rdV2Gmh0A4ijp1
6ULoY/Y5k51MTqlOKlI1DW6NLQe9ZKAfvoBSaLst70NjoKvIeZWMwqGidTXE8gVpwqy3InuILG5a
o8o1zQRRUVCPbCie506OTMslfcR8bN577P3i+ziT1Lrj/NtisJruCnjaA2/ajiOuyj9dHeG4F01F
iDDJtAltCyGjlDNFqLDV6YPMVXB0b+iyoQjHTttor7dq+sJ7P0t1D+sqGgINv4EQgTAnQV0Z/0R7
X0BMQUHaqADr0ZEW0ZkVkUsMNuVdN4MA2yIG3pJW+xE9+Dacd27BrvqvTeJdDxjv2Laykq3rrjAh
JaqfYESl8WWgAkJmWqN+nQM8ni4GKRKiQegTLLIn43UbiM1Ji9I9oL6PCro2VKT+b2ObjiPAZJFN
g246Sb5ox/s40kenY0u47kmjlZR/iySyLXVzlfQnTrWDhYb1LOHg8oFO2gxXyMNzdJwki+tTjqR2
wZ8wobp2rIVJ8+NqCmaw7TUL4WW8Hecij4Asjo1ZZoJ9AACBMweuD9U7ArUWbCcB4PsxJTbkH1z3
RtzI5BVQ/oWRpBVKJm0rmrf9jGMo5mwSPqqgVXODYdRMYC3o4rj9afCJFgOKTMagjRqC0jq/IVhH
FpRJh+qpSbFMs9ZI2yH7V6WWzS6E4x43d0EeLt8i/pWXJQsjcGEc/YG9cNmH8alDSaT30eXozqpi
QAAAABcGgZABCYCOAAcLAQABIwMBAQVdABAAAAyApgoBR9SOIAAA
This uses the same format and password as I used last time on 2024 (the latest one).
TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

Alright, for Day 3 I got… JavaScript! (Babel Node)
Finally, a normal language! If only the input isn't as complicated as this:

// code from https://stackoverflow.com/a/49957823
const EventEmitter = require('events');
function stdinLineByLine() {
	const stdin = new EventEmitter();
	let buff = '';
	process.stdin
		.on('data', data => {
			buff += data;
			lines = buff.split(/\r\n|\n/);
			buff = lines.pop();
			lines.forEach(line => stdin.emit('line', line));
		})
		.on('end', () => {
			if (buff.length > 0) stdin.emit('line', buff);
		});
	return stdin;
}
const stdin = stdinLineByLine();
let sum = 0;
stdin.on('line', /* callback */);

Powered by DjangoBB