diff --git a/2023/full/day07.txt b/2023/full/day07.txt new file mode 100644 index 0000000..b1b4379 --- /dev/null +++ b/2023/full/day07.txt @@ -0,0 +1,1000 @@ +55AAA 534 +QKK3Q 408 +Q4Q4Q 607 +5J5K5 793 +J6396 841 +AK359 693 +4A6A2 453 +A6632 967 +Q2Q22 196 +AK265 673 +K868K 514 +5T9K5 848 +5QQQJ 223 +22JA2 337 +383J3 879 +J3232 416 +6983J 351 +QK6K9 229 +98J25 852 +7733A 964 +89AK4 637 +K5A82 720 +A4664 230 +K4994 634 +T5888 314 +QQJAA 364 +77K78 296 +93322 159 +78777 462 +649J8 434 +692K7 709 +AJAAA 457 +838Q9 893 +37K77 853 +8KKKK 473 +4555A 880 +2252J 645 +T2332 326 +TT4JT 75 +44847 949 +23733 470 +24766 419 +2QKQK 302 +65A3Q 39 +7Q87J 297 +6Q7KJ 519 +TTTTK 989 +T5936 463 +6J922 686 +2TT5J 553 +8975A 353 +787Q5 172 +K7J77 840 +Q4QKJ 493 +A5K83 723 +4JQ53 97 +KJKQK 582 +KK4KJ 17 +8768J 120 +4444Q 905 +76776 842 +KK9A2 439 +J8QJ8 474 +8QQ88 718 +QQJ55 139 +AK8TA 546 +Q945T 478 +Q8K49 369 +43332 30 +694T7 940 +K4KKK 494 +84843 182 +AAAQA 646 +737JA 614 +85QQ4 104 +6JAA2 333 +83388 565 +T7999 826 +TQ96Q 947 +83333 784 +T7T8K 689 +4KQT6 491 +TT3TT 624 +88J66 836 +7AA77 13 +2QJJ4 996 +79777 273 +3333K 930 +2QQQ2 151 +K2K4J 6 +8338A 911 +8QTTT 891 +3QQ9Q 721 +555Q4 522 +6A79A 26 +9J347 270 +8QJT6 483 +QQTTJ 91 +6Q396 617 +58J36 244 +4K55K 630 +666J3 301 +5K555 204 +TJKTT 595 +66692 584 +66233 874 +A88AT 994 +45854 960 +77767 888 +TQTT3 854 +AJQ6A 259 +9JAAA 149 +JKKQQ 479 +55598 576 +A28A2 925 +828KK 41 +Q3J93 203 +AT3TT 827 +335KK 93 +5K56K 778 +4747Q 894 +A77K7 295 +2K634 154 +KJT5Q 480 +49854 445 +T5TJT 342 +763AQ 981 +J6643 305 +J76T3 787 +TJ7KJ 241 +7J332 344 +QA3T3 265 +25222 366 +53552 877 +8Q696 111 +Q9567 174 +774J9 184 +79977 126 +94T64 377 +J8888 783 +33267 367 +T5J53 768 +246A7 141 +37QTQ 88 +J99T2 64 +4J792 220 +963A2 517 +43348 101 +Q8K57 832 +44744 197 +4J2J2 262 +K5KKT 892 +A53AA 348 +QT9T9 79 +54644 242 +39369 503 +78J87 427 +J99A4 663 +KKK6K 569 +8JK88 896 +84648 42 +AJKAQ 687 +5A94Q 636 +33T33 495 +9Q2T2 716 +A749J 760 +4J8K4 65 +99499 209 +42JA4 137 +2K62K 228 +59Q28 482 +5AA73 188 +QTTTA 293 +66642 953 +2KJ2K 564 +AAJAJ 532 +A5453 51 +44K24 797 +22992 320 +66555 800 +947JT 9 +A8265 313 +TA76Q 598 +8473A 810 +99Q95 845 +8Q85K 805 +J3596 157 +JKK66 59 +TA888 794 +JA7A7 712 +9J59K 513 +Q3Q33 600 +3J448 310 +QA44T 666 +32K39 983 +T2JQ8 133 +43345 939 +85Q45 436 +8J898 424 +4QQJQ 49 +8KA9J 961 +55J59 507 +4724Q 504 +4KQQQ 12 +33999 256 +QA8A7 100 +AAAAK 508 +59A55 368 +66J56 144 +487AA 736 +KQTKK 186 +7QQQT 56 +7K246 767 +QQQQ9 487 +QQ3J2 398 +J7K7A 798 +22228 995 +64Q73 688 +J2TJ4 901 +3636T 675 +55444 21 +76QQA 4 +A2232 922 +2AJ54 672 +JA37A 746 +55T53 520 +QKK3J 906 +K8466 119 +AK653 758 +J3533 710 +AAAAT 391 +25KKJ 379 +58T39 107 +9T9T9 871 +AT7AQ 47 +2QQ24 661 +96226 168 +65555 975 +88K88 443 +848J6 160 +QQAQA 189 +7J36K 875 +34484 770 +T4J38 383 +8942A 33 +AQA4Q 338 +9697T 977 +K3K7J 887 +T498T 472 +KKQ2K 243 +KTJAK 872 +57655 109 +QJQQQ 886 +57777 345 +66JQ6 623 +5992J 660 +TAAKK 191 +27228 837 +79A26 604 +T8JTT 245 +T55TT 862 +4558K 526 +37777 627 +QQ3QQ 458 +KA9AT 124 +88488 449 +4Q26K 796 +98984 393 +Q63J5 791 +8QKQQ 644 +A7AAK 371 +666JJ 924 +A7974 913 +TJA66 199 +AA6KK 931 +77454 727 +9J697 954 +444AA 294 +AKA58 142 +3K3J5 396 +8T6KJ 456 +53735 706 +66444 817 +3J784 698 +9A7AJ 570 +J64AA 251 +K5932 819 +958K2 485 +979J9 775 +77333 52 +J622J 247 +TTJ6T 324 +6TT73 788 +77477 2 +5K55K 652 +KJ525 115 +7AT56 594 +66766 869 +K9A2Q 602 +34434 180 +77K72 388 +3K8T5 253 +4Q3KK 711 +66665 632 +T2T66 690 +KKK74 616 +747J4 702 +796QA 497 +829K9 464 +K78K5 628 +34334 657 +2T453 161 +8369Q 912 +99J99 57 +774K7 19 +4A94A 897 +2QAJ2 389 +27K78 62 +7KKKK 530 +KJKKK 319 +T76Q9 999 +2T998 361 +A9Q29 855 +J44J4 681 +T57J9 813 +9459T 631 +5J7J5 500 +9JT68 164 +6222J 78 +22662 166 +J347A 280 +5TQA8 418 +AK7Q4 45 +36666 618 +AK545 32 +KA9KQ 236 +5T55K 649 +Q8A4J 68 +K4K44 117 +T64TT 193 +46666 308 +K79KK 501 +777A8 615 +52TT2 306 +KKJKJ 486 +Q3932 102 +6J972 738 +55888 974 +4J476 838 +6JQ4Q 140 +TTT4Q 303 +KKK88 701 +35QKJ 69 +5J325 902 +2J555 190 +55J55 572 +Q373T 311 +KAJAA 422 +Q3QQ7 328 +463TQ 263 +JQ663 839 +88858 428 +94853 475 +56Q55 821 +7777J 561 +Q66J7 726 +9A7A5 700 +98868 907 +A2AK2 288 +647A3 968 +K2988 903 +AA2JT 890 +A8T69 926 +T44TJ 252 +2A2AA 354 +KK4J9 136 +9889Q 620 +63J33 860 +222TT 667 +22T72 238 +5T88T 691 +233TT 250 +96649 210 +58474 765 +99939 668 +AT3AJ 959 +999Q9 824 +9KJ99 550 +Q5J5K 551 +TAT6T 235 +7J77J 406 +68586 318 +AQ475 169 +J424T 705 +AKK97 541 +AKT75 412 +AAQJA 432 +K77K7 834 +6Q594 535 +J2772 699 +85Q78 477 +KT986 552 +6Q84J 980 +77T48 868 +5AQAT 756 +666T6 282 +97899 46 +QQ794 792 +Q33KT 173 +57JK4 948 +4K664 433 +Q36AT 195 +82282 287 +44724 724 +K8637 547 +7377J 70 +79J7Q 3 +TJ6KK 549 +7766K 512 +J44K7 53 +5Q425 211 +AA5JA 878 +27A89 781 +99988 225 +Q72T8 734 +Q454Q 105 +A8AT7 601 +JTTTT 260 +Q9J78 407 +3K999 782 +AKK6K 917 +K3535 86 +22JT5 307 +55855 332 +6KA98 187 +T2JQQ 215 +4T39K 942 +QQ8QQ 329 +494J4 357 +46T27 829 +3548T 316 +555K6 224 +K9AQQ 833 +TAT5T 340 +77888 671 +22673 899 +K3237 43 +T9TT9 129 +5555T 613 +98596 529 +99669 921 +4443A 825 +AQA54 806 +TTA5A 163 +K99KK 946 +93997 779 +49544 945 +QT383 350 +67667 694 +K7997 207 +TAT52 695 +53563 346 +387QK 461 +J4T56 339 +TTTT7 330 +59QA7 401 +T5T55 861 +27774 246 +TJ99T 505 +2ATAT 679 +64A43 420 +28J5J 993 +5J5K9 741 +5QQQQ 446 +994Q9 73 +Q33A6 866 +A337A 965 +55A88 669 +A82AQ 885 +QJ6J8 331 +AA72A 923 +K574Q 934 +33TKT 347 +Q6J73 384 +63782 970 +TT8TT 471 +2445K 984 +5QT35 202 +89888 662 +KA39A 611 +3985A 548 +TTJ6K 234 +A67J3 125 +9Q743 540 +5QAAQ 179 +K3K32 95 +83J5K 465 +782TA 883 +52QJ2 380 +TTT6T 285 +K8469 198 +QT7AT 409 +99995 143 +J5856 586 +T9KJT 175 +6Q42Q 966 +JAQJ8 764 +9939J 625 +55858 258 +QQ828 356 +JQ2Q2 18 +27722 81 +K3Q46 740 +46767 704 +J8KKK 284 +999K9 555 +J3J44 233 +K99K9 286 +55994 910 +394JT 847 +22472 8 +95K5Q 882 +4T454 859 +Q3333 521 +49495 717 +J5JJ5 112 +3K827 421 +8Q799 876 +6T7T9 735 +TT8T2 402 +J77A7 774 +K68QK 40 +KJK76 11 +7AT7A 312 +9T999 90 +TKAQ5 928 +AQ27K 481 +K3477 545 +QJTAA 375 +44884 937 +8822K 466 +23333 38 +4KKK4 773 +46AJ4 130 +2AA3A 648 +7K7A4 523 +TT3A4 381 +TT444 16 +K8889 909 +64875 404 +84929 932 +78485 566 +32584 809 +83348 664 +9AAAK 237 +7AA7K 626 +JK2T2 559 +96A7K 255 +75A65 745 +68266 656 +KJK54 269 +6QQ4Q 358 +787TT 276 +6AK66 484 +22262 278 +58J88 828 +QQAAA 987 +2K67J 146 +7QQQA 459 +27453 415 +K842J 920 +5873T 914 +JJJJJ 155 +67JJ2 499 +6T98T 927 +T9KKK 82 +43956 823 +4464T 743 +98999 150 +95922 606 +K7KK7 183 +937JA 728 +6688T 816 +Q3594 392 +6JJTT 766 +99JQ4 603 +444QQ 642 +KJ6KK 85 +QQK3J 15 +A4KJ6 870 +76KA5 5 +66J66 957 +36663 153 +55A5A 851 +QQ5T7 176 +A7999 873 +428JQ 973 +T7777 83 +8A452 991 +2699J 54 +97959 218 +9559Q 221 +25794 200 +57555 560 +A5Q5A 413 +3JJ82 212 +TK783 399 +T83TT 621 +55955 807 +5TT8K 410 +4A7J5 633 +3K6TQ 373 +3TJTT 956 +KT5KT 639 +AT2TT 803 +K28A6 574 +87598 67 +4KQQ9 327 +8852Q 580 +9K58K 732 +8A8AA 437 +A468K 647 +44743 943 +44423 605 +22863 343 +666J2 213 +99922 692 +728KK 84 +23J77 752 +7J49Q 426 +62Q2Q 469 +TKQ4J 205 +J5AA5 802 +A7359 447 +88666 864 +KQT7T 976 +A22A2 29 +Q77KK 643 +87888 750 +T6663 992 +J2767 106 +22J2J 579 +66A66 588 +TT9TJ 14 +33A26 941 +492A9 219 +9JT44 323 +QJK3J 670 +74747 733 +634K8 352 +8J68A 325 +55Q5Q 808 +44644 118 +3KK33 322 +28QAJ 22 +T226K 780 +Q33A5 298 +98928 998 +7772J 544 +8A688 979 +J8J88 811 +JKK3K 334 +AKA4J 448 +6686K 568 +3K752 35 +7JT77 986 +938J5 511 +262A2 89 +AQ966 192 +83338 858 +6J7QQ 889 +3KK77 655 +9524K 589 +3TJT3 349 +42Q67 577 +K249K 537 +857Q3 997 +4QJQ4 37 +Q999J 96 +66262 321 +A6A6A 460 +5A539 908 +34999 592 +22T9J 452 +27A2A 1000 +4A2AJ 638 +QQ76Q 730 +A6A33 867 +247QA 678 +72277 309 +QTQQT 23 +3K636 36 +99733 222 +677J4 581 +J8JJJ 835 +KT6A4 116 +3JT33 275 +2Q978 596 +66969 685 +K8A88 441 +3TKJ7 985 +78AA7 134 +KKTKT 158 +575J7 58 +J2362 578 +9JKK7 749 +282A2 916 +4J424 390 +J7QQ7 865 +4A4T4 206 +55JKK 254 +33399 754 +99QQQ 776 +5Q76K 571 +37T2A 201 +6QT96 355 +QQT4Q 267 +86A34 653 +76T59 92 +9QQ9K 430 +55995 516 +22322 599 +2876K 822 +77233 831 +4T2T2 360 +T2777 988 +2222A 110 +KK6K6 385 +44J4K 622 +A93A3 162 +64A75 658 +5JK88 846 +357A2 747 +KK69J 814 +K4A3J 7 +A4444 395 +33535 759 +T8Q5Q 363 +J48K3 216 +82JK5 900 +9A833 538 +TAA6T 587 +Q453T 194 +5T5T9 629 +QQQAQ 299 +86T3J 820 +32465 659 +373Q8 729 +A8AJA 227 +777J9 25 +9QJ9J 1 +8888A 898 +5898Q 543 +98852 558 +AA9AA 289 +TTT5T 147 +5AATA 476 +Q3A85 488 +6Q86Q 919 +63655 387 +24668 274 +7JT42 856 +9993Q 751 +AAAA3 266 +666T5 71 +95777 972 +86Q22 239 +2AAAQ 226 +33JJ3 515 +AAA52 527 +33J33 113 +99A9A 771 +62922 442 +37KQ4 772 +66AAQ 641 +T2KTT 703 +KAK3K 610 +TQTJT 411 +AAKAK 121 +KQ97T 496 +4QQ5K 597 +55QJ5 431 +44J44 257 +69956 933 +6T2A5 99 +J59J5 382 +6K8J6 264 +JKKTK 573 +87447 714 +TAT2Q 94 +477JK 138 +QTTTT 696 +89988 978 +23J7Q 556 +668K8 378 +J5444 372 +96997 533 +K887K 283 +KAKKK 170 +22TQ2 165 +7J2JT 400 +KJ495 790 +777QQ 951 +68J33 722 +57577 963 +35873 128 +22JJA 952 +8338J 77 +78585 414 +QQAJ4 131 +8848T 969 +AKAJT 50 +J8Q88 468 +7TTT7 763 +67267 122 +A22AT 27 +5AQT4 31 +28468 506 +AAAA5 958 +55666 10 +55252 66 +272J2 114 +J2AAJ 849 +7A8JJ 248 +J5557 277 +5954J 762 +6K3KK 98 +98788 108 +66423 72 +67636 489 +5A555 403 +T9524 261 +7T284 268 +55554 677 +JTAT8 61 +K922K 936 +A6T6T 272 +74K2J 815 +9KQ45 181 +KK4T2 397 +8JQ8Q 528 +53Q73 748 +6Q5Q5 683 +K66TT 950 +AJJ8A 341 +8A228 524 +AQ4A3 804 +9JJ99 904 +35976 608 +33AAJ 609 +55J53 335 +59988 208 +222K2 799 +36J9Q 498 +K4654 177 +25522 531 +T737A 881 +55K45 20 +A3383 24 +99595 593 +J8K2K 455 +4KQ9K 635 +34A33 231 +53TQ7 362 +K9KKK 640 +7TTT4 249 +Q49J2 127 +T538J 590 +J2288 684 +92993 674 +2A6AA 214 +QKKKQ 785 +87QTJ 370 +TKT3K 737 +JQQ75 502 +K9AAJ 850 +258K8 857 +9K2JQ 76 +JJJ6Q 217 +QJ399 557 +K2JTT 135 +J2922 148 +QQQ7Q 317 +92T9T 405 +Q274T 962 +44J9J 509 +QTQQQ 232 +37737 757 +88J83 938 +AJJ89 279 +855K3 744 +82928 28 +7427K 185 +JTQK8 884 +33363 585 +67662 971 +22272 359 +44442 450 +TQ746 650 +58553 715 +J5558 830 +25625 315 +67KK8 583 +6K768 304 +Q9KQ2 417 +8A485 429 +K5KKK 518 +J3JJ3 510 +45554 525 +TT777 145 +KK666 490 +9AK97 492 +Q76A4 818 +88382 34 +39545 423 +3JT4K 376 +2Q722 789 +K9KAK 87 +84847 152 +A33J8 440 +5K8J4 132 +54585 680 +K55KT 281 +95T8J 990 +66QQQ 44 +6T734 707 +57JJ7 454 +Q6QK7 425 +Q4852 575 +63266 731 +2KA9A 739 +96924 394 +J3T2Q 654 +T44TT 451 +9992J 542 +46664 178 +42442 944 +QQQ6J 755 +JTQT2 271 +59575 682 +Q86T8 708 +82888 801 +9595J 300 +38832 48 +3332J 935 +Q7Q57 769 +K85T9 812 +3A994 665 +44544 725 +7K878 591 +84K24 336 +K885K 982 +3TA4A 742 +4T7T7 915 +75JAT 895 +453AQ 786 +QQKQQ 713 +JJ6K4 386 +7J766 290 +2T735 435 +227K7 753 +656Q6 240 +QQQQ2 929 +K566T 467 +KAT6J 563 +A2888 156 +222J2 374 +6Q6Q4 567 +47474 438 +95939 171 +3434J 843 +8AJ75 863 +9K62A 536 +6699J 123 +97979 651 +43966 844 +833Q4 697 +3A4TQ 795 +ATTK4 719 +7A992 777 +J938K 562 +JQJQQ 539 +J22AA 554 +KKKTK 619 +2T873 292 +QKKAK 103 +77A77 612 +T7Q4K 55 +A46AA 60 +72778 365 +QQQ45 74 +6K372 676 +3J522 80 +AK5AJ 291 +329K6 444 +55Q55 918 +64545 167 +82288 63 +3993J 761 +622J8 955 diff --git a/2023/python/day07.py b/2023/python/day07.py new file mode 100644 index 0000000..a772582 --- /dev/null +++ b/2023/python/day07.py @@ -0,0 +1,83 @@ +import matrix +import shared +from dataclasses import dataclass +from collections import defaultdict +from pprint import pprint + +STRENGTHS = list(reversed("A, K, Q, J, T, 9, 8, 7, 6, 5, 4, 3, 2".split(", "))) +STRENGTH_HANDS = [ + "Five of a Kind", + "Four of a Kind", + "Full House", + "Three of a Kind", + "Two Pair", + "One Pair", + "High Card", +] + +def determine_hand(cards): + card_set = set(cards) + if len(card_set) == 1: + return "Five of a Kind" + + + same_cards = sorted([cards.count(a) for a in card_set]) + if len(same_cards) == 2: + if max(same_cards) == 4: + return "Four of a Kind" + elif max(same_cards) == 3: + return "Full House" + elif len(same_cards) == 3: + if max(same_cards) == 3: + return "Three of a Kind" + else: + return "Two Pair" + elif len(same_cards) == 4: + return "One Pair" + return "High Card" + +@dataclass +class Hand: + cards: str + bid: int + + def counts(self): + return Counter(self.cards) + + def kind(self): + cards = [c for c in self.cards] + return determine_hand(self.cards) + + + +# @shared.profile +def part1(rows): + hands = defaultdict(list) + for row in rows: + cards, bid = row.split() + hand = Hand(cards=cards, bid=int(bid)) + hands[hand.kind()].append(hand) + pprint(hands) + + + + +# @shared.profile +def part2(rows): + pass + + +def main(): + rows = [row for row in shared.load_rows(7)] + with shared.elapsed_timer() as elapsed: + part1(rows) + print("🕒", elapsed()) + + rows = [row for row in shared.load_rows(1,True)] + with shared.elapsed_timer() as elapsed: + part2(rows) + print("🕒", elapsed()) + + +if __name__ == "__main__": + main() diff --git a/2023/samples/day07.txt b/2023/samples/day07.txt new file mode 100644 index 0000000..e3500c3 --- /dev/null +++ b/2023/samples/day07.txt @@ -0,0 +1,5 @@ +32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483