Nice. Roassal? Is that Smalltalk then?
Advent Of Code
An unofficial home for the advent of code community on programming.dev!
Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.
AoC 2024
Solution Threads
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 |
Rules/Guidelines
- Follow the programming.dev instance rules
- Keep all content related to advent of code in some way
- If what youre posting relates to a day, put in brackets the year and then day number in front of the post title (e.g. [2024 Day 10])
- When an event is running, keep solutions in the solution megathread to avoid the community getting spammed with posts
Relevant Communities
Relevant Links
Credits
Icon base by Lorc under CC BY 3.0 with modifications to add a gradient
console.log('Hello World')
Yep, I took the opportunity to learn smalltalk while doing aoc
Have you published the source for this somewhere? I’m interested in seeing what Roassal is like to use.
Here's the code. Everything prefixed with 'RS' is from Roassal. Alternatively, just look at where I use canvas
. Keep in mind this is quick spaghetti code, and it includes the full solution for day 10 part 2.
day10p1vis: in
| input starts canvas |
canvas := RSCanvas new.
input := CTNewArray2D
fromArray: ((in copyWithRegex: '\n|\r' matchesReplacedWith: '')
collect: [ :v | v asString asInteger ] as: Array)
width: (in lineNumber: 1) size.
input withIndexesDo: [ :x :y :val |
canvas add: (RSLabel new size: 5; text: val; x: x * 12; y: y * 12) ].
canvas signalUpdate.
(canvas @ RSCanvasController) open.
14 seconds wait.
starts := (input contents indicesOf: 0) collect: [:v | input indexToCoord: v].
d9heads := OrderedCollection new.
^ starts sumNumbers: [ :s | | thead |
canvas signalUpdate.
0.08 seconds wait.
d9heads removeAll.
thead := RSBox new size: 12; position: s * 12; color: Color red translucent.
canvas add: thead.
self d9graphvis: input start: s dir: -1@0 canvas: canvas.
]
d9graphvis: input start: start dir: dir canvas: canvas
| next sum direc bounded bnext |
bounded := [ :p | (p x between: 1 and: input width) and: [ p y between: 1 and: input height ] ].
direc := dir.
sum := 0.
4 timesRepeat: [
next := start + direc.
bnext := RSBox new size: 12; position: next*12; color: Color blue translucent.
canvas add: bnext.
"canvas signalUpdate."
"0.034 seconds wait."
sum := sum + ((bounded value: next) ifTrue: [
((input at: next) = 9 and: [(input at: start) = 8])
ifTrue: [ bnext color: Color green translucent. 1 ]
ifFalse: [ (input at: next) = ((input at: start) + 1)
ifTrue: [ | t |
t := self d9graphvis: input start: next dir: direc canvas: canvas.
t = 0 ifTrue: [ self canvasRemove: { bnext } canvas: canvas ].
t ]
ifFalse: [ self canvasRemove: { bnext } canvas: canvas. 0 ]
]
]
ifFalse: [ self canvasRemove: { bnext } canvas: canvas. 0 ]).
direc := direc rightRotated.
"canvas signalUpdate."
"0.034 seconds wait."
].
^ sum.
Great, thanks! I've always had Roassal at the back of my mind as a way of generating visualisations for AOC, but never got round to it. This might kick-start me, but maybe for next year at this point :-)
I haven't but I can send it here, when I get home