From 7c03f2a189366e3ed19215dfeb7580fbd6a7d0ed Mon Sep 17 00:00:00 2001 From: Rory Molinari Date: Fri, 9 Aug 2024 17:02:32 -0400 Subject: [PATCH] Fix examples/adventofcode/2022/3 - fix obsolete method names split-every, intersect - use modwords where needed - insert |unique calls where needed for problem semantics --- examples/adventofcode/2022/3/main.rye | 25 +++++++++---------------- examples/adventofcode/2022/3/main2.rye | 24 ++++++++++++------------ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/examples/adventofcode/2022/3/main.rye b/examples/adventofcode/2022/3/main.rye index 66a3926a..dd48d64b 100644 --- a/examples/adventofcode/2022/3/main.rye +++ b/examples/adventofcode/2022/3/main.rye @@ -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 - - - - - - - diff --git a/examples/adventofcode/2022/3/main2.rye b/examples/adventofcode/2022/3/main2.rye index b9a25e28..6e4f69c8 100644 --- a/examples/adventofcode/2022/3/main2.rye +++ b/examples/adventofcode/2022/3/main2.rye @@ -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