Created
December 1, 2021 15:27
-
-
Save tatut/6e62ff9e51e269c38e3fb4b694ad1b7c to your computer and use it in GitHub Desktop.
AoC2021, day1 using SmallTalk (using blocks, instead of OO)
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
testArray := #(199 200 208 210 200 207 240 269 260 263). | |
"day1 part 1" | |
part1 := [ :input | | |
| len prev incr | | |
incr := 0. | |
prev := input first. | |
len := input size. | |
2 to: len do: [ :i | | |
(prev < (input at: i)) ifTrue: [ incr := (incr + 1) ]. | |
prev := (input at: i)]. | |
incr] | |
part1 value: testArray. | |
"day1 part 2" | |
windowAt := [ :input :i | | |
(input at: i) + (input at: (i + 1)) + (input at: (i + 2))]. | |
part2 := [ :input | | |
| len prev incr | | |
incr := 0. | |
prev := windowAt value: input value: 1. | |
len := input size. | |
2 to: (len - 2) do: [ :i | | |
| w | | |
w := windowAt value: input value: i. | |
(prev < w) ifTrue: [ incr := (incr + 1) ]. | |
prev := w]. | |
incr] | |
part2 value: testArray. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment