day 2 part 1

This commit is contained in:
Tove 2024-12-02 10:47:58 +01:00
parent c6ae367939
commit 319cfb3204
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 1094 additions and 0 deletions

1000
2024/2/input.txt Normal file

File diff suppressed because it is too large Load diff

94
2024/2/main.spl Normal file
View file

@ -0,0 +1,94 @@
"../lib.spl" import
func main { exitcode | with args ;
def input
args:2
read-file
:split<"\n">
:iter
:filter<| "" eq not>
:map<| :split<" ">:map<| _mega>>
:collect
=input
0 input
:iter
:map<&report-check>
:foreach<| 1 gt if { ++ }> println
"broken" println
0 input
:iter
:map<&report-check>
:foreach<| 0 gt if { ++ }> println
0
}
func report-check { mega | with report ;
def kind, last, item
report:len 4 gt if {
[
report:0 report:1 gt
report:0 report:2 gt
report:1 report:2 gt
report:1 report:3 gt
report:2 report:3 gt
report:2 report:4 gt
report:3 report:4 gt
] sort:insertion :3 dup if {
^up =kind
} not if {
^down =kind
}
}
def i 0 =i
2
while { i report:len lt } {
i report:get =item
last null eq not if {
item last eq if {
--
i ++ =i
3 stop
}
kind null eq if {
item last lt dup if {
^up =kind
} not if {
^down =kind
}
}
^up kind eq if {
last item - 3 gt if {
--
i ++ =i
4 stop
}
item last gt if {
--
i ++ =i
4 stop
}
}
^down kind eq if {
item last - 3 gt if {
--
i ++ =i
4 stop
}
item last lt if {
--
i ++ =i
4 stop
}
}
}
item =last
i ++ =i
}
}