Last active
December 3, 2025 09:53
-
-
Save SizableShrimp/1255bf8136821c69242abe5e8d327df2 to your computer and use it in GitHub Desktop.
AOC 2025 Day 3 in Scratch (compile with https://github.com/aspizu/goboscript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %include std/string | |
| costumes "blank.svg"; | |
| var input = ""; | |
| # var input = "987654321111111\n811111111111119\n234234234234278\n818181911112111"; | |
| func chartodig(c) { | |
| return $c + 0; | |
| } | |
| func argmax(bank, start, endExclusive) { | |
| local i = $start; | |
| local maxIdx = 0; | |
| local maxVal = 0; | |
| repeat $endExclusive - $start { | |
| local jolts = chartodig($bank[i]); | |
| if jolts > maxVal { | |
| maxIdx = i; | |
| maxVal = jolts; | |
| } | |
| i++; | |
| } | |
| return maxIdx; | |
| } | |
| func calc(bank, maxDepth) { | |
| local res = ""; | |
| local depth = $maxDepth; | |
| local idx = 1; | |
| repeat $maxDepth { | |
| local bestIdx = argmax($bank, idx, length($bank) - depth + 2); | |
| res = res & $bank[bestIdx]; | |
| idx = bestIdx + 1; | |
| depth--; | |
| } | |
| return res; | |
| } | |
| proc doit { | |
| } | |
| proc main { | |
| ask "Paste your input below; replace all newline characters with \"\\n\" to make the paste work."; | |
| input = replace(answer(), "\\n", "\n"); | |
| split input, "\n"; | |
| local part1 = 0; | |
| local part2 = 0; | |
| local i = 1; | |
| repeat length(split) { | |
| part1 += calc(split[i], 2); | |
| part2 += calc(split[i], 12); | |
| i++; | |
| } | |
| say "Part 1: " & part1 & ", Part 2: " & part2; | |
| } | |
| onflag { | |
| doit; # Necessary for other blocks to be executed for some reason? | |
| main; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| costumes "blank.svg"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Configuration Reference: <https://aspizu.github.io/goboscript/configuration> | |
| std = "2.1.0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment