From 7ffeb4f7f1657d29df9832460ce6fa33a2184bad Mon Sep 17 00:00:00 2001 From: sterni Date: Fri, 2 Dec 2022 02:53:28 +0100 Subject: refactor(sterni/aoc/2022): use scan in BQN/k We can actually use one and the same scan on the sorted list to solve part 1 and 2 of the assignment. Change-Id: I657a81bad6151ef4fe13239db88d2dbd2f9c29d8 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7491 Autosubmit: sterni Reviewed-by: sterni Tested-by: BuildkiteCI --- users/sterni/exercises/aoc/2022/01/1.bqn | 6 +++--- users/sterni/exercises/aoc/2022/01/1.k | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'users/sterni') diff --git a/users/sterni/exercises/aoc/2022/01/1.bqn b/users/sterni/exercises/aoc/2022/01/1.bqn index f95851e0d93e..440efff41c65 100644 --- a/users/sterni/exercises/aoc/2022/01/1.bqn +++ b/users/sterni/exercises/aoc/2022/01/1.bqn @@ -1,7 +1,7 @@ lib ← •Import •path∾"/../../lib.bqn" input ← lib.ReadDec¨¨ (<"") lib.SplitOn •FLines •path∾"/input" -cpe ← +´¨ input +a‿·‿b ← +`3↑∨+´¨ input -•Out "day 01.1: "∾•Fmt ⌈´cpe -•Out "day 01.2: "∾•Fmt +´3↑∨cpe +•Out "day 01.1: "∾•Fmt a +•Out "day 01.2: "∾•Fmt b diff --git a/users/sterni/exercises/aoc/2022/01/1.k b/users/sterni/exercises/aoc/2022/01/1.k index 295503905fb8..42d64dfb6cc1 100644 --- a/users/sterni/exercises/aoc/2022/01/1.k +++ b/users/sterni/exercises/aoc/2022/01/1.k @@ -1,2 +1 @@ - / a better approach is to use the downgraded list for both tasks, as demonstrated by leah2 -(|/e),+/e@3#>e:(+/.'1_)'(&0=#'i)_i:0:"input" +(+\e@3#>e:(+/.'1_)'(&0=#'i)_i:0:"input")_1 -- cgit 1.4.1