Skip to content

Commit

Permalink
Fix examples/adventofcode/2022/3
Browse files Browse the repository at this point in the history
- fix obsolete method names split-every, intersect
- use modwords where needed
- insert |unique calls where needed for problem semantics
  • Loading branch information
rmolinari committed Aug 9, 2024
1 parent 0eaf804 commit 7c03f2a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
25 changes: 9 additions & 16 deletions examples/adventofcode/2022/3/main.rye
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,18 @@

read\lines %rucksacks.txt :lines
|fold 'priority 0 {
.length? / 2 :mid ,
.split-every mid |pass { .first :left } |second
|intersect left |fold 'priority1 0 {
.length? / 2 |to-integer ::mid ,
.split\every mid |pass { .first ::left } |second
|intersection left |unique |fold 'priority1 0 {
.get-priority + priority1
} |+ priority
} |+ priority
} |print

; part 2

lines .split-every 3 |fold 'priority 0 {
-> 0 :line0 ,
-> 1 :line1 ,
-> 2 |intersect line1 |intersect line0
|get-priority + priority
lines .split\every 3 |fold 'priority 0 {
-> 0 ::line0 ,
-> 1 ::line1 ,
-> 2 |intersection line1 |intersection line0
|unique |get-priority + priority
} |print







24 changes: 12 additions & 12 deletions examples/adventofcode/2022/3/main2.rye
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@

; part 1

read\lines %rucksacks.txt :lines |add-up {
.length? / 2 :mid ,
.split-every mid
|with { .first :left , .second }
|intersect left |add-up { .get-priority }
} |print
read\lines %rucksacks.txt :lines |map {
.length? / 2 |to-integer ::mid ,
.split\every mid
|with { .first ::left , .second }
|intersection left |unique .map { .get-priority } |sum
} |sum |print

; part 2

lines .split-every 3 |add-up {
-> 0 :line0 ,
-> 1 :line1 ,
-> 2 |intersect line1 |intersect line0
|get-priority
} |print
lines .split\every 3 |map {
-> 0 ::line0 ,
-> 1 ::line1 ,
-> 2 |intersection line1 |intersection line0
|unique .get-priority
} |sum |print



Expand Down

0 comments on commit 7c03f2a

Please sign in to comment.