fn typ(hand : array(uint8, [5])) : uint8 [ var counts := array_fill(uint8, 0, [13]); for i := 0 to 5 do counts[hand[i]] += 1; var jokers := counts[0]; counts[0] := 0; counts := array_sort(counts); counts := array_reverse(counts); if counts[0] + jokers = 5 then return 6; if counts[0] + jokers = 4 then return 5; if counts[0] + jokers = 3, counts[1] = 2 then return 4; if counts[0] + jokers = 3 then return 3; if counts[0] + jokers = 2, counts[1] = 2 then return 2; if counts[0] + jokers = 2 then return 1; return 0; ] fn main [ var ctoi := "J23456789TQKA"; var lines := list_break_to_lines(read_lazy(h[0])); var hands := empty(tuple3(uint8, array(uint8, [5]), int)); for line in lines do [ var l := list_break_whitespace(line); var hand := array_fill(uint8, 0, [5]); for i := 0 to 5 do hand[i] := list_search(ctoi, l[0][i]); var t := typ(hand); hands +<= mktuple3(t, hand, ston(l[1])); ] hands := list_sort(hands); var sum := 0; for i in list_iterator(hands) do sum += (i + 1) * hands[i].v3; write(h[1], ntos(sum) + nl); ]