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 (Dec. 2, 2025 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 */);
davidtheplatform
Scratcher
500+ posts

Advent of Code 2025

Day 3: https://scratch.mit.edu/projects/1250862299/
I thought this one was easier than day 2, but I also found a trick for it pretty quickly: [Ignore the last N-1 digits, where N is the amount of digits left to pick. Then pick the largest digit. If there's a tie, pick the one that comes first. Repeat until 12 digits have been selected. I was really expecting part 2 to break this approach, although it is only day 3.]

I was going to make a visualization for it, but I'm not aware of a way to draw a lot of very small characters (160 characters would require each character is 3 pixels wide) so I gave up on that.

Last edited by davidtheplatform (Today 05:23:40)

mybearworld
Scratcher
1000+ posts

Advent of Code 2025

davidtheplatform wrote:

(#11)
I was going to make a visualization for it, but I'm not aware of a way to draw a lot of very small characters (160 characters would require each character is 3 pixels wide) so I gave up on that.
I've added a visualization to it that doesn't show the numbers. Still looks interesting, I think. https://scratch.mit.edu/projects/1251429637/
TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

Oops, forgot to share Day 3's solution. Here they are:

N3q8ryccAASgDaFPzAMAAAAAAAAjAAAAAAAAANmI18q90CSxVaSHU/0bhIeBeO/I1omTAbT3U7Fi
C2R1RFnHbiqocbcFokSIhySLbb3euAzIe1JHO086evdYj+9Me/y21FgiA6uEkhpzCGJheR82goal
pGrNpoadQW7dP35RR7MzYRVCsy7BsAnXnrbIThoplko+XAShbpLkKfs2nvcoTvDPgF+z8Y43nXgA
g5oTWl+X5nO62oBGwxuZxvSpXb/bxGYJDMzXXEkTv4BerJj3y5GA8Szdsv3RAwfR08OQrcadoeEt
/PISriOupzRBIFp/unnCx66mL1I5Veykaa5nRTgt97fBdwHW4Pcl/PaYIM76+kJmK04yblSQxOPZ
xGEaa3Nppma3ZdlW+Ux8Nr4tIZmm0yLMu+mahMIMAIMWeUdVn9K10h1jSwuqZmloLcMHzz/cn1lL
+t7XHw9BRoJmxeFa207FkQAJEBUEA9cPkq40I/HgozksTLrzMYYgxl3YTYbg26VrLhHr5g5iDYO4
zJ1AUAgl4y5Rkltccyqr9M2T0jIGrgfHt+vrdkkXdpRBJ9LIDOuEdvA+BdF7oC4FDP2p884RaW5Z
TgwdaOyksC2s6bwh3ll0XBW5uWHm7KmRzkJyPM/tgjzHOrlbEBGSSPbcTRTkL8RrLhOHXjYxp1Ka
C8YQtJMA798DtUcySue+UwslUT/hZROI0znARgbvaTuzczvfECoUekjbwybSkWJzPGqN0aBgKDAd
SAKURIEZ8jhmnNm5OkplPqma2D56wJBi1rHfV3IBxXdviEORTtMx2slLKelg1bWHTqBw8Nnf8fRc
EUqv0LCjBaMzl/jO+8skuAah1WLCcvN8Xa6c75wAUBw7z64ZSDeq9XKW9xn1/Guycmjnm3vtdgyl
pn7lGVxWwBYC+4T07lc0QQ+fl/0ZJESRQ3paKwV8ydkV1yGnarRBy0q6n2MkrPqwK2CtoE0v5OBN
oRh/zM2wHtfW1dx0V/USmM15GSwqC6SD81EgLA2GLC91ld7OidI3vDcxPQZ2U39O7GgyCCVOa21r
TF2xa6OgtcPw+WCgoVnBIFyMNEsn8unEcrPSMeWi1XqTtZ9Ol6sTJI+JYBCWiMJE0cI02lPNE+an
iNCJuhAkuKVDAACBMweuD9VPPeEXJNHP5AQoBS8Xg5Nplf/zj62n8dhnJfSj6wd85JRXwY0UYwIf
9jUK9CXx0sOguLnekKk2ePiy0uD6xtfpeAUDw+Hi1d53SbXsHAyDZAgMNOM/PmUGRb6spkwV8qZr
F0kJa4qFGgMHsGsSQFXBzr8nzhQ2j9WBwk9CjnibrWAAAAAXBoNAAQmAjAAHCwEAASMDAQEFXQAQ
AAAMgJ4KAZx75ycAAA==

Anyway, Day 4 is going to be written in… Idris.
Really? A functional proglang? Something like APL would be nicer for this problem.

Last edited by TheSecondGilbert (Today 07:54:29)

TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

Okay, I got it to work. That took way too long to code.

It would also take too long to calculate. 13 seconds for the example? No way this can do my input for less than 60 seconds (the limit)

So, change of rules. If there's some limitation from the chosen language I can't circumvent, I'm allowed to use another language that I can use locally (most likely Python). I would have to do (and show) both parts though.

Powered by DjangoBB