From 0b190c67a18b7ab480d03d05b1540a975392f188 Mon Sep 17 00:00:00 2001 From: aprzn Date: Thu, 7 Dec 2023 03:03:50 -0500 Subject: [PATCH] day 7! --- day07.ua | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 day07.ua diff --git a/day07.ua b/day07.ua new file mode 100644 index 0000000..260a6e2 --- /dev/null +++ b/day07.ua @@ -0,0 +1,42 @@ +# approach: give each hand a score s.t. better hands always have higher score +# score: card5 + card4 * 13 + card3 * 13^2 + card2 * 13^3 + card1 * 13^4 + type * 13^5 +# where type is: high card = 0, one pair = 1, ..., five of a kind = 6 + +$ 32T3K 765 +$ T55J5 684 +$ KK677 28 +$ KTJJT 220 +$ QQQJA 483 +TestInput ← + +ParseI ← ⊜{⊓⊗⋕ ⊙"23456789TJQKA" ⊃(↙5|↘6)}≠@\n. +ParseII ← ⊜{⊓⊗⋕ ⊙"J23456789TQKA" ⊃(↙5|↘6)}≠@\n. + +ScoresI ← ( + :≡/+פ⇌ⁿ⇡5 13. + ≡( + ⊃(⊞=1_2_0_3_0_4_5/↥|⊟∩≍1_2_2,2_3⊏⍏.)≡/+⊞=⊝. + /↥⊚⍜(⊏2_4)+ + ) + +×ⁿ5 13 +) + +ScoresII ← ( + :≡/+פ⇌ⁿ⇡5 13. + ≡( + ⊃(▽¬|/+)=0. + ▽±.⍜⊡+⊗/↥..⊂0≡/+⊞=⊝. + ⊃(⊞=1_2_0_3_0_4_5/↥|⊟∩≍1_2_2,2_3⊏⍏.) + /↥⊚⍜(⊏2_4)+ + ) + +×ⁿ5 13 +) + +PartI ← /+×+1⍏⍏ScoresI⊐≡°⊟ +PartII ← /+×+1⍏⍏ScoresII⊐≡°⊟ + +PartI ParseI TestInput +PartII ParseII TestInput + +PartI ParseI &fras "day07.in" +PartII ParseII &fras "day07.in"