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 (Yesterday 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 (Yesterday 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 on the chosen language though.

Last edited by TheSecondGilbert (Yesterday 14:29:57)

TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

TheSecondGilbert wrote:

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 on the chosen language though.
Turns out that 13 seconds is actually just Idris compiling the code into (checks docs) Chez Scheme. The actual program is quite fast (if 4 seconds is fast to you). I think I spoke too soon.

Anyway, here's my solution for Day 4:

N3q8ryccAAT2BEWIiwUAAAAAAAAjAAAAAAAAAObNlQYPZRCu2U24oU3vCg8EpN/EYRY8iwuJef3m
XighrHOAiGPePWU79NIzFIcptTqiFvWT77fiwDgOs34R7/gYA6QoKtxJ+FFDoqbz7oidc/FM0k5+
mYzoAuTb94ZHL+7VZ0zFJkRs3RAhZLz1fFmeIT+1FLLQdKycGjPNop4Od68FURLFbbqz3OF2jZ57
IIxk5b47FPVFzYnVxFtsTfjnyWJK02qAjQAr3Ah1a33Q6E1y2m4fc+PafhGVcnA96Qy1g7SLcSQU
sD5tfzFGwCmJXNd4DIo1yUrelk9+st+IijlnBHaYfzUKGzGAKTpqc9NSKcnQKWbojOH+i9NG/zAv
VG84OAKUJFoS3Z23xkKUVIOAIQsw8o8HtKUSCwqYzkH0/dsOOA4TCGkeSs9IRppFjGVz2D395hmp
nNBzhlzHK1Wzv/Ce4PngNLy7aNOxvWYCjLIDVS2HT8O+Iz6Pu12uazQvIq/jbULubP2UUVbtqwcH
i4IXZEKIl6q2eMjBE9mur1C8Fnos89X2tPNWEBqUpbYU4d7djzIICAFJ6WQMKrFuGLHVZya7dXog
HBOX7eCQfJN5qSaC8guqSZpafVhoycZcuUm6pK7UFyAq6Nmq5KeNgfPVpbnT3HlpxlBO6eoRMLxu
s/MRs6c2L/ypTfBpCf/3aoD/WPyVZ6xWNW8r8yig3aW9uNbL3keGNKCLrVfFmFmjjQ0DZTQ9rGIS
TbmdDqbJw+slZ2ZWTA57vMQmySPE1feUn1JgiKuhsOIZNUTo8aMgYM6Nt10myf8nQ0h1AJBro/HI
vLgW6uL3Vpw9Qa1beToQdyppbCafU948rj1rpT+Xs88t2TnEY9GlK1frjYg+bhcfGOMNh7Mj6576
NTtpTz57wP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For those that loves bonus questions, I have one for you:
In the code, I have this function defined:
-- translated into Haskell for your pleasure
window3 :: ([a] -> b) -> [a] -> [b]
window3 fn arr = case arr of
    (x0:x1:x2:xs) -> (fn [x0, x1, x2]) : (window3 fn (x1:x2:xs))
    _ -> []
It just applies `fn` to a sliding window of `arr` with 3 elements. I'm interested for a more general `window` function, where instead of a window with size 3, the size of the window can be specified.
davidtheplatform
Scratcher
500+ posts

Advent of Code 2025

Day 4: https://scratch.mit.edu/projects/1251459563/
Part 2 continues to be easier than I expect.
TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

Day 5 is going to be written in Clean… another FP. Ugh.
davidtheplatform
Scratcher
500+ posts

Advent of Code 2025

Day 5: https://scratch.mit.edu/projects/1251959128/
This is my favorite day so far, I had to think about part 2 a decent bit. The input handling was kind of annoying though.
[Part 1 is just checking if each ingredient is in one of the ranges. Part 2 is harder though. My initial strategy was to have a second list of ranges that starts empty, and merge each of the original ranges with this new list. The problem is that a new range can overlap _two_ existing, non-overlapping ranges. The way I handled this is by running the merge algorithm again until everything has been merged. ]
Pufferfish_Test
Scratcher
500+ posts

Advent of Code 2025

TheSecondGilbert wrote:

For those that loves bonus questions, I have one for you:
In the code, I have this function defined:
-- translated into Haskell for your pleasure
window3 :: ([a] -> b) -> [a] -> [b]
window3 fn arr = case arr of
    (x0:x1:x2:xs) -> (fn [x0, x1, x2]) : (window3 fn (x1:x2:xs))
    _ -> []
It just applies `fn` to a sliding window of `arr` with 3 elements. I'm interested for a more general `window` function, where instead of a window with size 3, the size of the window can be specified.

something like this perhaps
window :: Int -> ([a] -> b) -> [a] -> [b]
window n f xs
  | length xs < n = []  
  | otherwise     = (f . map (head . (`drop` xs)) $ [0..n-1]) : (window n f (drop n xs))
TheSecondGilbert
Scratcher
100+ posts

Advent of Code 2025

TheSecondGilbert wrote:

Day 5 is going to be written in Clean… another FP. Ugh.
…or maybe not.

I think the Clean compiler in the website is misconfigured and all of the libraries not already in the prelude can't be imported. The escape rule applies; I'll do it in Python instead.'

Here's my solution:
N3q8ryccAAS6ZSnvGwIAAAAAAAAjAAAAAAAAANN7c6tgZiU7n+eLmbdL1B/SGR7GONUuxyTNW8Dn
fIFskYvW1nZXsi7Dibbpe6zAxxcjKrAk7AOoxc8y5QkHv3RmXhdeN/whRwB6dlRyPciNDqhr0m1e
qad4RCuju70fRqAfZ63wscoJEnPYjZ9OF0yWQ7JKxgR1GG6D8zaMUp9om3bfy43ULqTVeuewDywC
zElr/EP7LpQibzBr+uWk9Fz7UxMgNQk2u1t9UpY0XR6dzAm1M/nTaDWB6eWV1N2f2VtuJawco1+V
8AyrZCbKtRG0hknAgMdY5yn88URnrbYiImyegotFRNObBRwB+PpPYLrNJPVdV9jUxGAsv0J2LG0f
UILAslJh/YrmbBmgvfZq8yBcodF5v/9F525oyb6EicnrTgm8p6uinM3QgJRSXJRR5U81i68bUfTn
kHerRyVNFqqUMmT5gNn2W+qYoVPaqekEmHt0QgkReM/SbFzaY4hRFDy9/mKnL+7xQTPXYbvMCfs9
8Z3oQU7JX0XCVgZIdlP4cSBBlcTHX/6p0BRXQMod2rMsAACBMweuD9U7ArUWbCcB4PsxJTbkH1z3
R3BNI5RDaFVErO/cuSxo6ZkNv7jw/H9a+VCuW+dxWA3h9LymsXQHkpqayY/VF/BivA4ydaXFdeh4
ETKHvkohVM67rzBiWu82opqDjXjJub0S4jpTQKJJwKEZ63PwX35Fh+VCMO7FbZ+FUalsI3CqQAAA
ABcGgZABCYCLAAcLAQABIwMBAQVdABAAAAyAngoBd/MGMAAA

Last edited by TheSecondGilbert (Today 15:58:04)

Powered by DjangoBB