Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Day 7: Camel Cards

day-07.livemd

Day 7: Camel Cards

Mix.install([
  {:smaoc, git: "https://github.com/nettinho/smaoc"}
])

Part 1

Your all-expenses-paid trip turns out to be a one-way, five-minute ride in an airship. (At least it’s a cool airship!) It drops you off at the edge of a vast desert and descends back to Island Island.

“Did you bring the parts?”

You turn around to see an Elf completely covered in white clothing, wearing goggles, and riding a large camel.

“Did you bring the parts?” she asks again, louder this time. You aren’t sure what parts she’s looking for; you’re here to figure out why the sand stopped.

“The parts! For the sand, yes! Come with me; I will show you.” She beckons you onto the camel.

After riding a bit across the sands of Desert Island, you can see what look like very large rocks covering half of the horizon. The Elf explains that the rocks are all along the part of Desert Island that is directly above Island Island, making it hard to even get there. Normally, they use big machines to move the rocks and filter the sand, but the machines have broken down because Desert Island recently stopped receiving the parts they need to fix the machines.

You’ve already assumed it’ll be your job to figure out why the parts stopped when she asks if you can help. You agree automatically.

Because the journey will take a few days, she offers to teach you the game of Camel Cards. Camel Cards is sort of similar to poker except it’s designed to be easier to play while riding a camel.

In Camel Cards, you get a list of hands, and your goal is to order them based on the strength of each hand. A hand consists of five cards labeled one of A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, or 2. The relative strength of each card follows this order, where A is the highest and 2 is the lowest.

Every hand is exactly one type. From strongest to weakest, they are:

  • Five of a kind, where all five cards have the same label: AAAAA
  • Four of a kind, where four cards have the same label and one card has a different label: AA8AA
  • Full house, where three cards have the same label, and the remaining two cards share a different label: 23332
  • Three of a kind, where three cards have the same label, and the remaining two cards are each different from any other card in the hand: TTT98
  • Two pair, where two cards share one label, two other cards share a second label, and the remaining card has a third label: 23432
  • One pair, where two cards share one label, and the other three cards have a different label from the pair and each other: A23A4
  • High card, where all cards’ labels are distinct: 23456
  • Hands are primarily ordered based on type; for example, every full house is stronger than any three of a kind.

If two hands have the same type, a second ordering rule takes effect. Start by comparing the first card in each hand. If these cards are different, the hand with the stronger first card is considered stronger. If the first card in each hand have the same label, however, then move on to considering the second card in each hand. If they differ, the hand with the higher second card wins; otherwise, continue with the third card in each hand, then the fourth, then the fifth.

So, 33332 and 2AAAA are both four of a kind hands, but 33332 is stronger because its first card is stronger. Similarly, 77888 and 77788 are both a full house, but 77888 is stronger because its third card is stronger (and both hands have the same first and second card).

To play Camel Cards, you are given a list of hands and their corresponding bid (your puzzle input). For example:

32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483

This example shows five hands; each hand is followed by its bid amount. Each hand wins an amount equal to its bid multiplied by its rank, where the weakest hand gets rank 1, the second-weakest hand gets rank 2, and so on up to the strongest hand. Because there are five hands in this example, the strongest hand will have rank 5 and its bid will be multiplied by 5.

So, the first step is to put the hands in order of strength:

  • 32T3K is the only one pair and the other hands are all a stronger type, so it gets rank 1.
  • KK677 and KTJJT are both two pair. Their first cards both have the same label, but the second card of KK677 is stronger (K vs T), so KTJJT gets rank 2 and KK677 gets rank 3.
  • T55J5 and QQQJA are both three of a kind. QQQJA has a stronger first card, so it gets rank 5 and T55J5 gets rank 4.

Now, you can determine the total winnings of this set of hands by adding up the result of multiplying each hand’s bid with its rank (765 1 + 220 2 + 28 3 + 684 4 + 483 * 5). So the total winnings in this example are 6440.

Find the rank of every hand in your set. What are the total winnings?

Part 2

To make things a little more interesting, the Elf introduces one additional rule. Now, J cards are jokers - wildcards that can act like whatever card would make the hand the strongest type possible.

To balance this, J cards are now the weakest individual cards, weaker even than 2. The other cards stay in the same order: A, K, Q, T, 9, 8, 7, 6, 5, 4, 3, 2, J.

J cards can pretend to be whatever card is best for the purpose of determining hand type; for example, QJJQ2 is now considered four of a kind. However, for the purpose of breaking ties between two hands of the same type, J is always treated as J, not the card it’s pretending to be: JKKK2 is weaker than QQQQ2 because J is weaker than Q.

Now, the above example goes very differently:

32T3K 765
T55J5 684
KK677 28
KTJJT 220
QQQJA 483
  • 32T3K is still the only one pair; it doesn’t contain any jokers, so its strength doesn’t increase.
  • KK677 is now the only two pair, making it the second-weakest hand.
  • T55J5, KTJJT, and QQQJA are now all four of a kind! T55J5 gets rank 3, QQQJA gets rank 4, and KTJJT gets rank 5.

With the new joker rule, the total winnings in this example are 5905.

Using the new joker rule, find the rank of every hand in your set. What are the new total winnings?

Solution

defmodule Smaoc.Solution do
  def solve(part, input) do
    input
    |> parse_input(part)
    |> Enum.sort()
    |> Enum.with_index(1)
    |> Enum.reduce(0, fn {{_, bid}, rank}, sum -> sum + rank * bid end)
  end

  defp parse_input(input, part) do
    input
    |> String.split("\n", trim: true)
    |> Enum.map(&parse_line(&1, part))
  end

  defp parse_line(line, part) do
    [cards, bid] = String.split(line, " ")

    cards_score = score_cards(cards, part)
    bid = String.to_integer(bid)

    {cards_score, bid}
  end

  defp score_cards(cards, part) do
    card_chars = String.to_charlist(cards)
    card_counts = Enum.frequencies(card_chars)

    kind_score = score_kind(card_counts, part)
    card_scores = Enum.map(card_chars, &score_card(&1, part))

    [kind_score | card_scores]
  end

  defp score_kind(card_counts, :part1) do
    score_kind(card_counts, 0)
  end

  defp score_kind(card_counts, :part2) do
    {jokers, card_counts} = Map.pop(card_counts, ?J, 0)
    score_kind(card_counts, jokers)
  end

  defp score_kind(card_counts, jokers) do
    card_counts
    |> Map.values()
    |> Enum.sort(:desc)
    |> score_kind()
    |> apply_jokers(jokers)
  end

  @five_of_a_kind 6
  @four_of_a_kind 5
  @full_house 4
  @three_of_a_kind 3
  @two_pairs 2
  @one_pair 1
  @high_card 0

  defp apply_jokers(score, 0), do: score
  defp apply_jokers(nil, 5), do: @five_of_a_kind
  defp apply_jokers(@high_card, n), do: apply_jokers(@one_pair, n - 1)
  defp apply_jokers(@one_pair, n), do: apply_jokers(@three_of_a_kind, n - 1)
  defp apply_jokers(@two_pairs, n), do: apply_jokers(@full_house, n - 1)
  defp apply_jokers(@three_of_a_kind, n), do: apply_jokers(@four_of_a_kind, n - 1)
  defp apply_jokers(@four_of_a_kind, n), do: apply_jokers(@five_of_a_kind, n - 1)
  defp apply_jokers(@five_of_a_kind, _), do: @five_of_a_kind

  @card_values "TJQKA"
               |> String.to_charlist()
               |> Enum.with_index(?9 + 1)
               |> Enum.into(%{})

  defp score_card(?J, :part2), do: 1
  defp score_card(c, _part), do: Map.get(@card_values, c, c - ?0)

  defp score_kind([5]), do: @five_of_a_kind
  defp score_kind([4 | _]), do: @four_of_a_kind
  defp score_kind([3, 2]), do: @full_house
  defp score_kind([3 | _]), do: @three_of_a_kind
  defp score_kind([2, 2 | _]), do: @two_pairs
  defp score_kind([2 | _]), do: @one_pair
  defp score_kind([1 | _]), do: @high_card
  defp score_kind([]), do: nil
end

year = "2023"
day = "7"
run_config = ["example", "puzzle", "part1", "part2"]

inputs = %{
  "puzzle" =>
    "Q94A5 121\nAQ56Q 611\nT6746 196\n38853 434\n69K88 178\n44454 238\n6KKKQ 913\n4446J 425\n9KK38 281\nKQ8TK 319\nA6A62 407\n26J93 60\n9A47Q 110\n4464K 656\n35373 558\nQ222Q 258\nT6377 243\nTQ9JQ 554\nJ373A 525\n59222 150\n44JJ4 738\n6Q662 452\nJTK95 684\n29KKK 697\n63363 254\nQ53A2 543\nT55T5 479\n5J39Q 743\nT338T 629\n8K5QT 561\nK6T45 902\n32544 857\nAA8A8 421\n66922 105\n222J2 833\n87878 949\nA966A 661\n4AA68 415\nJQ2Q7 794\n3QT93 618\n665Q6 78\n5599J 467\n575A5 577\nQJ699 846\nKKKKQ 28\nTKJTT 242\nKJ868 115\n59TTT 120\n87J44 861\n3A269 128\n292T2 70\n5AJ3K 412\nJ7TK8 916\nJQJ6Q 241\n22K22 590\nT868J 584\nA887A 971\n77787 701\nQ882J 758\n4AA4A 880\n3AJQ3 423\nK3KK7 465\n6956T 512\nQ2Q52 530\n98883 922\n58AQ8 963\n223TT 565\nTT53T 626\n6K244 843\n6JQ3T 687\nA7A7K 708\n5TK62 457\n4T44J 280\nK3K22 470\nQ8QK5 184\n4Q9Q4 164\nKKK66 934\n9Q875 753\n3Q98Q 230\n22K2K 789\n59949 553\n33388 478\nTTTAA 5\n73787 501\n4236J 222\n4J665 749\n6T666 431\nJ42K8 469\nQ2722 598\n33539 840\n55445 204\n98J88 302\n87778 305\n678J4 123\nJ464J 134\nKKAKJ 32\n98JQ9 329\nQ9TQQ 36\nA8569 380\nT2447 726\n3558T 609\nK23JQ 335\nAK9T3 303\n98ATJ 156\nTAJKT 291\n3A4T7 894\n48J28 327\n8K3JT 386\nTTT3K 486\nQ8K28 528\n9A4AA 444\n3AA5Q 657\nTT6TT 781\n428JA 569\n99899 176\n63666 80\n9AJ9A 273\n8829A 364\n68TQ4 151\nA5849 202\n47TT4 961\n44483 999\n3Q9A5 777\nK383J 55\nT2274 122\n99J66 326\n9939T 550\nTQJ56 219\nQ58T6 992\nK93KK 937\n44A38 797\nT4428 266\n6AAAJ 87\nQQ444 505\n4Q62Q 279\n63623 983\n969J3 223\n8J888 357\nJA3A3 354\n88JQQ 878\nA42J3 336\n7A7A3 828\nJQ68J 323\n25555 883\nQ488Q 669\nT6784 395\nT7524 683\n98969 659\n9894K 159\n7Q2QQ 655\nJ7946 304\n532QT 998\n22QT2 935\n9TT9T 564\nK999J 769\n5AK4A 968\n8AAAA 490\n92356 627\nAA8J8 21\n3Q343 986\nTKTKT 824\nK2465 770\nJ7774 535\n8J97K 124\n4444J 976\n75Q79 283\nJJJ44 668\n4JK47 317\n8A268 276\n99Q6Q 389\nJ7J75 109\nAAJKK 931\n73366 347\n37997 403\n6572J 345\nJ48J4 763\nA9AAQ 648\n87A99 172\n787A8 51\nTJ24J 92\n4T278 852\n77T2Q 264\n22J44 991\nQ666Q 958\nJ74A9 318\nTQJKA 265\nJA5AK 454\nA5J3J 808\n3TT3J 796\n62QJ5 539\n5QA5Q 563\n6QQQQ 495\nT48J5 893\nK9259 334\n957AK 671\n97393 481\nK4848 216\nKJJ3T 647\nQQJJ7 125\n354T3 921\n55777 112\n47TA7 810\nJ3J29 520\nQJTQQ 874\nTT272 277\nQJQQ6 728\nJ55TK 518\n22622 850\nJQ236 155\nQ7TTK 489\n7TKTJ 41\nAAAAJ 14\nT3A3J 192\n433K4 508\n55545 398\n77KQ9 361\nA737J 967\nA66J6 84\n4745J 793\nT2Q2T 666\n5A54A 1000\n753J2 714\n55556 485\n8TT8T 775\nT9767 908\n99299 907\n227JJ 568\n64952 62\n555Q7 414\nT86T9 943\nJJ6K6 463\nKKK3K 703\nQ553J 370\n97QQ7 596\n44484 491\n69367 730\nJ583K 206\n35898 194\n4K2QK 179\nA56J7 405\n4282Q 126\n225JK 786\nQ5J33 806\nT44T8 941\n99AAA 442\nT88T8 670\n3T963 69\nQ33Q3 381\nJ2K2K 394\nA99K8 167\n739QK 400\n8J93K 635\n88688 891\n5J232 66\n57252 376\nQQQQT 306\n33232 628\nAJJAA 915\n72J22 750\nA77AA 270\nQQTTT 75\n536A4 170\n95795 61\nKQJ2J 16\n9TA6Q 617\n999J8 33\nQA63J 952\n6QT28 246\nT787J 127\n3J373 496\nJ8QK4 691\n383KK 477\n97757 988\n727J2 585\n9992T 368\nTT222 225\nQQ33J 191\nT656A 373\n42222 873\n44A4A 4\nT9ATJ 725\nQKJKK 166\nTT633 153\n833QJ 274\n23993 22\nTQ99Q 267\nJ9583 605\n798TK 823\nK33KK 331\nA25J7 212\n949Q9 514\n62T66 911\nT5239 851\n97733 385\nT2Q6J 845\nAA66A 311\n5Q5K3 129\n89J98 152\nQ6374 161\n966K6 586\n82J3A 175\nQT7K7 308\nQQ67Q 203\nT9Q28 587\nK2539 445\n5554J 48\n859J6 436\n92A92 677\n64JQ8 499\n88885 9\n88A3T 945\n299J2 674\n4QQ4K 435\n64TJ8 630\n238T7 169\nTTTT4 784\nAAAA2 290\nQQKQQ 453\n3924J 716\nTT6KK 56\nQQKTT 751\nA2658 531\n7AT3Q 145\nJKKKK 948\nQQQ8A 972\n4484K 706\n9A6Q7 64\n343TT 46\nAJQ2J 523\n655T6 23\n4KK4K 15\n3TJK7 792\nT78T4 527\n3J57A 817\n24444 675\nK3459 599\nAAAA9 734\n663T6 658\n5Q555 456\nQQQ2Q 927\n32594 960\nT65KQ 841\n28T76 44\n97777 287\n66544 429\nJ5K58 135\n33Q33 236\n222J3 804\n64J59 532\n4335A 707\n3782A 195\nQ29A6 358\n89JA2 771\n26QQ5 650\nT99TJ 2\n635J6 637\n27723 106\n6KQT8 404\nT3TTT 868\n3KJ27 560\n6KAJ3 409\nKTKKK 724\n58T34 85\nQA223 136\nTTTKA 578\nQ44A4 989\n6J7J6 946\n2Q2T6 890\n34982 278\n2242K 548\nJ9333 181\n88448 686\n757QQ 38\n2KK2Q 340\n74JJK 341\nAJ8Q6 93\n7JJ95 757\nKK8K8 131\n55252 83\n9T557 269\n523T4 722\n9TA9K 207\nK242K 209\n26666 830\n8888A 768\n92QQQ 116\n2222A 210\nJ4287 417\nA55Q9 875\nTA74A 330\nQ87A7 160\n2876J 694\n28992 715\nA5996 954\n3J53J 90\n2A2JK 259\n8JA4A 936\n8QTJK 638\nTTQTT 113\nJAT79 455\n6J72A 606\n26J42 94\nT68KK 138\n4QQA9 919\nQ55Q3 869\n22JJ5 570\n4AJA3 837\n3TQQA 250\nAJAJ6 693\nAK9AK 372\nJ4795 576\n3235K 108\n9A88A 799\n2K5J6 933\n95QA7 613\nQJ7A4 838\n262QQ 787\nQ5J99 189\nKK7T3 262\n88779 342\n6QQ6Q 174\nA2656 119\nJ555J 393\n3T2T6 723\n562J3 767\nQ46Q4 422\nT3QQQ 897\n56T28 99\n95J32 182\n6888T 574\nTQTQQ 881\n9T9T9 353\n77KKK 289\nQT555 625\n56655 74\n84442 72\nJT883 81\nQQ7Q7 297\n5555K 337\n8A2AJ 371\nA4266 188\nQ5J52 964\nJ6666 406\nJQ382 825\n66J4J 253\nTT998 877\n4382A 622\n88AA5 460\n29869 374\nKK6J4 295\nK792J 268\n44474 612\n66669 947\n4Q9T3 990\n66K56 511\nJJ88Q 664\nJTTTJ 923\n49499 672\nQ7683 855\nJQQ66 232\nJ2KK7 383\n995KA 65\n4A272 52\n223QQ 620\n9J9J9 420\n289AA 63\nTTJTT 944\n339K9 45\nTA586 886\n46767 836\n65A66 871\n22499 892\n25533 292\nJT4T4 676\n447A2 592\nQ2KKJ 733\n777T7 26\n57T77 39\n73763 809\n77774 978\nT449Q 484\n44996 382\n7836A 464\n99488 667\n2333K 211\nAJ8KT 524\nK4444 284\n6AAAA 483\n5AQ65 940\nT67J7 766\n9QQQQ 811\nJJAJA 816\nQ8898 199\nKKKK8 77\n9J499 737\n24472 352\nKKK9K 709\n7887K 631\n588T2 688\nK72T7 829\n26578 831\n72AQ3 348\n38KQK 79\n76676 545\nKJ577 447\nT2696 239\n84A67 760\n4T6QA 905\nKKQT5 256\nQ9K25 190\n67TT4 820\nQTAJ6 149\nQ5JQ5 86\n5QQ56 173\n6KK9J 807\n77789 288\nAA666 815\n7742A 788\nA5T8Q 889\nQTJ75 299\nQ7QK7 717\n4QQQ8 102\n52J25 526\n33633 953\nT97A3 594\n9A48K 17\nJ87QJ 76\n2TTTT 433\n2Q222 660\n6626J 416\n6T5TQ 387\n3233A 778\n257K8 597\nJ77J7 957\n2777A 40\n6K666 538\nQ666K 271\nK3J59 339\nT4TJ9 441\nTA3JT 193\n65695 350\n4JKK8 761\n732KK 482\n6AAK9 980\nA8TA8 754\nTKK4T 926\n4K42Q 426\n793KK 286\n84Q95 25\n87K8J 461\n5588A 519\n34Q82 472\n86688 663\n57QQ9 581\n6K6K7 973\n26T2J 870\n2T983 100\nK269J 720\n752J7 712\nQQQQJ 731\nAJ5J5 31\n59QQ5 437\nK8TAQ 969\n38737 408\n58K88 756\n54379 493\nQ5Q44 1\nAAKKK 614\n99898 680\nT7T77 552\n3Q3QQ 111\nJTQJT 604\n824K7 739\nJ243T 965\n49849 682\nQ666J 513\nQ27K5 970\n888Q8 917\n87364 762\n885TA 180\n5T44T 517\n399JA 791\n366T4 301\n54858 928\n2TT39 997\n33A3T 579\n82883 492\n8A99A 765\n93939 480\n7K7K4 296\nA5TQ5 785\n3J22J 801\n8J688 466\nAAQ77 678\n9A68J 856\nTJ7TT 546\nT8A96 529\n33J85 649\nJ84JJ 369\nJ3QJQ 918\n8T4AT 746\nAT8TT 428\n8JJJJ 685\nT3A5T 430\nJQJQQ 247\n95926 818\n58885 424\n55K8K 312\nJA6JK 231\n7K8KK 154\nT676T 993\n5Q4A3 692\n5T455 118\n5QQ55 862\n42422 607\nQ4QA4 542\n66AA7 57\nA2K7K 547\n454K4 711\n5Q546 379\n7365A 834\nQA737 887\nJ3683 704\nAJKT5 474\n79299 772\n8K2TA 476\n6K6QJ 397\nT36TT 349\n68466 537\nK34KK 427\n92722 224\n95444 309\n44494 187\nKQT2K 795\nKK884 310\n5T399 3\n7A77A 803\n5QQ5Q 975\n4295K 89\n363Q3 313\n9KK9K 333\n44577 632\nJ4456 747\nJ86A6 205\n77J42 275\n28442 43\n3333J 654\n3754J 744\n49T85 411\n7A7K7 904\n6TTQK 853\n474J7 168\n44434 813\n3676K 324\nKJKJT 867\nAJ77A 551\nT42TT 681\nAAQA3 589\nKAT2T 197\nA422Q 98\n52JKK 619\nQ6Q26 144\n33666 600\nT85T4 237\nKTA88 536\nQ68A7 752\nJ7676 282\n7JK93 872\n98TA7 399\n35757 186\n35533 634\nKKAKQ 745\n9JJ2J 163\nT7K36 325\n8TAJ5 251\n28628 924\n7K723 7\n43626 139\n2QAAA 826\n77822 215\n7KJ79 567\n22J29 864\n88223 201\n645Q2 471\n9959A 458\n777J2 884\n9KA5Q 462\n6J464 88\nQ639Q 10\n5J595 974\nJ4454 146\n33JA3 54\n24228 49\nJ525T 996\n2J22J 549\n55JT5 20\nAKJ8K 583\n35635 645\n295Q8 914\n73TQK 615\n23333 229\n6J6K2 446\n282J6 502\n5J5A7 59\nKQQK2 504\n2KKKK 162\nJ3Q6J 510\nA8AA5 249\nATA55 593\n7A7A8 955\n7333Q 137\n6TA79 858\nTTJT8 117\n53939 509\n8848A 198\n9J2K3 402\n5Q855 418\n7KKK9 410\n44Q44 498\n82J83 540\nK89QQ 696\n82J87 293\n95T99 995\n54834 741\nA7865 396\n28262 73\nT4JTT 557\nT9T8T 977\nK2K82 29\n8686J 865\n77766 101\nQ5Q6Q 245\n423A4 879\n6AT29 515\n83J88 432\nAA62A 322\n777A7 344\n99994 727\n4297A 451\n3AQT8 157\n2652J 355\n4T4KA 640\nKA976 158\n22559 285\nQ7K36 842\n6655J 362\n555J5 764\n85887 367\n35588 141\n59995 805\n56Q6Q 208\n9T2Q2 494\nT4Q58 616\nA74Q8 366\n8J885 779\n96AJ9 702\n83333 67\n7TQ55 748\nAJ6KQ 679\n9999J 822\n87Q6T 544\nJ77TJ 882\nKK4KK 328\n29995 651\n3J33J 534\nK3774 721\n99599 556\nKT528 27\n38938 147\n5QKA6 876\n4K869 885\n8TJQJ 300\n6A22A 653\n68A8J 263\n6A666 588\n439QQ 863\nK8256 713\n57466 213\n923A7 384\nA9696 255\n7Q7JQ 755\n95955 895\n7Q279 800\n43895 140\n3T332 835\n5KK55 298\nKT2A4 591\n3K33K 930\n4TJ5T 500\nKA2AK 690\n45556 363\n76TT7 903\n333A3 13\nJ2TQQ 939\nKAKKK 782\nTT778 185\n9Q99Q 143\n77224 227\nKJTKT 860\nJ4K73 956\n737J3 377\n3844J 440\n34K4K 689\nA5A66 966\n2AQ5K 200\n27774 896\n227TQ 776\nJ448Q 673\n45JT5 221\n57J74 97\n55355 47\n8T888 641\nAAA3A 50\n392A2 774\nKKK7K 475\nQQ96J 35\nK444J 96\n44632 37\nJ52J4 220\n56839 644\nJ5TTT 438\n5Q49K 866\nK8888 742\nQK9K2 468\n2J4TA 951\nAA888 888\n5K65Q 356\n6T548 859\n9J799 261\n55KJK 165\n56AQJ 320\n77T82 844\nT8AKK 316\nQKKKQ 392\nT9236 448\nJ7339 639\nJ6998 705\n88338 82\n7Q5A3 929\n5JJ88 847\nATKQ7 783\nJJ22T 332\nT999Q 595\n5A5AA 773\n4484Q 987\n7622Q 950\nQQ44Q 602\n8T43A 942\n2A88A 95\nJ23T3 228\nJ7T86 42\n3Q66T 981\nQA28T 8\n5522T 925\n22437 260\nTQ758 759\n398JQ 582\n32Q24 272\nA3QQ8 315\n9QK6Q 906\nA25A4 580\n49JK9 214\nAQAAA 994\nK565K 572\n93792 812\nQT8QQ 391\nT9595 506\n468Q9 827\nA52J4 351\n98779 718\n344TT 848\n552J5 832\nA5JA2 573\nKJK7K 473\n63QQJ 699\n99799 503\nK2JKK 19\n448A8 443\n3K44Q 522\nKJ8KK 662\nK77JJ 623\nA5Q8A 912\n2K968 68\n7TTJ8 307\nQ4QQ7 621\nT68QJ 962\nKQ8Q8 375\n45A55 360\n27727 819\nJQ53T 900\n97979 798\n7T6QA 642\n77377 790\n286TT 218\n69A52 566\n444A4 854\n66TK9 610\nJ7777 740\n34J3J 901\n2QQQ2 821\n5A6J3 58\n863T6 910\n777Q7 624\nQ78K9 507\nK3333 652\n8J6Q9 439\n29TQ5 91\nQ2727 177\n6JK6T 571\n28J6T 240\n884JT 450\n58J85 541\n4K4KA 24\nKAQ23 314\n22992 601\n5J454 736\nQ3332 107\nAJ9Q5 710\nTA979 521\n6TJTQ 575\n29242 735\n3JJQ3 608\n7J252 183\nQJTQK 388\nAAQAK 802\n48775 248\n65666 378\n5389A 234\nTTTQ2 979\n7J7T7 71\nQ894A 603\n8Q86Q 6\n55T55 343\n33343 34\n3636Q 103\n5JJ5J 390\n8996K 633\n788A6 898\nK7777 985\nQ999K 114\n35333 732\nTK83A 53\n88887 235\n5TT5T 359\nQQAAQ 132\nQTTQ2 12\n25975 346\n2A72J 839\n888JJ 719\nKKKJT 365\n4QJ44 533\nTT335 636\n5J2Q2 459\n5556K 130\n97A39 148\n6A5Q8 133\n4A45A 104\n9TTTJ 233\n8J8JJ 338\nA9AJ3 413\nQK2QT 497\nQ929Q 401\n44949 899\nK666K 30\n555AA 932\n66Q6T 11\n65258 559\nA75AA 18\nK7QK7 814\nJ7923 217\n66667 226\n55K5Q 909\n9TJAA 562\n632AJ 294\nJJJJJ 488\n55KQQ 849\nJ6336 780\n2Q2J4 244\n285J5 698\n7QT3J 321\nKKKK5 555\nQ39K6 257\n4A693 643\n2T97A 665\n26624 419\nT9J95 646\nKKJKJ 959\n5J55K 700\n6TA39 171\n7TT74 487\n9K494 729\n44JJ9 449\nTAK79 984\nT2992 516\n9QK6T 938\n79272 982\n22282 695\n4JT95 920\n56AK9 142\nTT66T 252\n",
  "example" => "32T3K 765\nT55J5 684\nKK677 28\nKTJJT 220\nQQQJA 483"
}

response =
  for part <- ["part1", "part2"], input_key <- ["puzzle", "example"] do
    {part, input_key}
  end

response =
  response
  |> Enum.filter(fn {part, input_key} ->
    part in run_config and input_key in run_config
  end)
  |> Enum.map(fn {part, input_key} ->
    [part, input_key, Smaoc.Solution.solve(String.to_atom(part), inputs[input_key])]
  end)

Smaoc.Response.new(%{response: response, run_config: run_config, year: year, day: day})