# 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"