From 8b4524912f28130f0a4ea1de92447ae171684ab6 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Mon, 18 Dec 2023 18:07:22 +0100 Subject: [PATCH] day 7 --- input/7.txt | 1000 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 2 + src/seven.rs | 194 ++++++++++ 3 files changed, 1196 insertions(+) create mode 100644 input/7.txt create mode 100644 src/seven.rs diff --git a/input/7.txt b/input/7.txt new file mode 100644 index 0000000..12796c0 --- /dev/null +++ b/input/7.txt @@ -0,0 +1,1000 @@ +8T64Q 595 +79J27 258 +88885 88 +8933J 444 +72527 676 +5555T 788 +69946 463 +572QQ 827 +553JQ 932 +99T99 567 +47Q7Q 112 +8J8QQ 186 +5K499 862 +2837Q 321 +55557 310 +KAAAA 263 +J4999 783 +4QQQ4 961 +64464 329 +8AQ9K 153 +763AK 341 +Q3K3Q 353 +4TJT6 593 +KJ46J 666 +AA92Q 176 +88555 738 +8KJJJ 431 +46T35 295 +86868 400 +884A4 19 +QQK44 860 +99996 794 +6J778 159 +45Q9T 763 +8AQAQ 39 +4JJ2K 764 +Q42AT 3 +77Q7Q 905 +57ATJ 185 +QQQJ6 707 +TKT2T 115 +JK646 951 +3KT2K 324 +94J64 569 +Q278J 998 +36QKA 979 +89T98 772 +55T66 669 +62747 161 +742TK 264 +J5A2Q 252 +JKAJK 455 +72777 659 +4454T 940 +Q2278 479 +63K36 53 +3K839 512 +A5AA5 223 +T3332 27 +KQ55Q 217 +75TT7 706 +53555 775 +9KK96 348 +9A999 984 +9TT99 943 +TTATJ 906 +6964K 711 +42452 983 +22AA2 241 +22282 521 +77733 627 +KQA47 987 +738J7 963 +KK2KK 231 +22322 709 +4T7J6 665 +Q6K6A 417 +2479K 955 +7J22T 861 +77A4A 446 +8642K 934 +25J32 435 +A3A3A 883 +QQ3JQ 280 +K7666 489 +2QAQ9 732 +85422 976 +T3393 322 +28888 298 +J9759 608 +33438 564 +A3KQ4 377 +2K6TJ 209 +QQ64J 482 +8T5T3 815 +3K6K6 123 +37757 741 +555A6 858 +5TAAA 12 +2225K 965 +Q29QQ 355 +2277K 62 +99932 169 +77722 458 +Q9444 550 +KJ8KK 338 +9K99A 238 +5Q5Q2 427 +7A6A6 675 +798AQ 766 +386K8 420 +88788 681 +2K4JK 974 +53426 776 +46892 884 +7Q47T 754 +923A4 719 +449JQ 506 +2Q2Q2 596 +K888T 235 +6AA6K 232 +57T5T 314 +T3TA4 171 +3QQ4A 581 +TAA98 946 +75Q8A 170 +46A4A 807 +36836 539 +888T3 515 +5KA55 520 +92J56 164 +Q3J56 1 +KAAJ7 499 +7QJQ4 196 +TTKTK 552 +AQ4QA 257 +7JTTT 249 +7QQ89 268 +96998 733 +39933 713 +44JJ4 603 +6877K 206 +K224J 450 +TTTKJ 38 +T7999 22 +7T55J 660 +66363 61 +33363 610 +TTAAT 795 +36336 739 +55255 604 +982JJ 146 +9ATQ6 313 +TT688 293 +TT7KT 648 +93298 817 +7TJ77 288 +23J3J 184 +JT7T3 132 +Q9Q95 430 +5554A 14 +QAQQA 212 +TT33T 538 +7A7J7 97 +JQ738 968 +AKA8K 923 +K9988 498 +J424A 481 +5AT66 792 +QQ444 835 +22262 916 +TJTTJ 334 +77Q47 462 +84884 871 +959AQ 950 +9637J 492 +QKQQ3 214 +68K6A 13 +26624 843 +TTTT4 470 +48TT5 81 +A6AQA 540 +TTQ9Q 285 +A8AAA 473 +88848 900 +K779K 688 +3QJJ5 852 +66T6K 224 +55595 720 +2222T 784 +83QT5 870 +6QQQ2 426 +44K55 625 +4AJ94 472 +6A55A 284 +85584 43 +Q96J2 986 +KA5AA 939 +62662 74 +89277 390 +4JKKJ 349 +336AA 82 +A99A9 477 +Q95J9 116 +K99K8 108 +AKA6A 505 +37J92 800 +TT98T 15 +JA75Q 276 +44433 91 +93494 684 +7A772 220 +K6JKA 9 +8TT85 685 +44448 600 +64T6T 484 +A3K29 547 +4455T 698 +932J6 742 +57595 198 +937QJ 114 +69696 423 +A3A55 143 +K8J4J 25 +7AQ64 646 +8Q44A 166 +J2AQA 809 +9993Q 272 +A6JT4 812 +K44T4 222 +J5567 577 +22244 109 +TKTTT 631 +Q678K 919 +Q9KT3 157 +4AJ64 602 +7667T 912 +A9K35 282 +272A2 78 +J887J 113 +K9A57 246 +JA7A2 915 +A3T9A 73 +264T4 129 +KK777 386 +T6665 507 +JT2AT 642 +66K66 382 +J4666 94 +235KQ 966 +T3T53 868 +3QA4A 584 +QQ7QQ 432 +JKK6K 37 +64594 575 +95669 931 +37383 366 +K9KKJ 563 +4Q9T3 970 +8688T 180 +Q999Q 242 +74724 243 +6666A 623 +66AT6 250 +4KA58 451 +J622J 493 +2J32T 47 +Q4586 859 +3393Q 221 +9Q55Q 908 +66277 121 +T7A94 461 +8KT58 160 +K9K99 989 +29292 23 +48462 574 +6T443 1000 +33344 414 +22728 964 +Q58JQ 680 +35K7T 542 +5A3QK 673 +A5553 453 +84Q7T 743 +9489J 903 +TJT94 5 +2925A 195 +45954 17 +J6T79 460 +6638J 848 +977J9 192 +AAAJ5 131 +3T39T 401 +87828 447 +9JJK7 651 +42552 632 +T7TJJ 389 +AA75A 274 +KA46K 11 +Q2Q2Q 55 +KJKK3 697 +5K3K3 495 +84786 21 +5J5QQ 413 +25755 849 +29222 780 +J5A9K 630 +K6TA6 863 +AKKKJ 395 +Q4456 777 +547K7 328 +QT35K 559 +AJAA4 872 +KTJ6K 48 +TQQTQ 215 +22662 768 +28547 526 +7J77Q 958 +2J2JK 42 +AK648 691 +K6833 716 +55J55 888 +33322 904 +2A6J7 605 +58887 586 +4J8Q7 621 +9A8Q8 824 +JQ2T9 356 +3TTTT 383 +JQQQJ 699 +56T3Q 351 +22422 879 +K25AJ 585 +82J66 305 +QJQ68 703 +96974 189 +4JT36 419 +84TJ2 549 +A95A2 84 +KK3KK 724 +A5KKA 421 +TTTAT 636 +2T22K 822 +337J7 634 +98TT9 770 +J99JJ 167 +88454 236 +J2985 405 +KQKKK 798 +6KQ82 168 +AJJ9A 92 +95595 150 +82943 672 +9Q7JA 69 +43QJQ 829 +A8382 773 +332J4 8 +7777K 657 +9J999 851 +35J5J 99 +AKQ82 24 +59355 658 +AAAQA 452 +98888 44 +77947 476 +48222 533 +T6666 30 +TT4T7 144 +3Q8Q8 297 +J3888 309 +QJ22A 933 +6TQ88 977 +23A4J 18 +66A5A 262 +6T5A5 914 +5K9J6 922 +Q4Q99 751 +3874Q 60 +TTKT8 653 +7TT7T 126 +9J668 364 +9ATK2 155 +44462 187 +85AJA 692 +K54J9 594 +2TK95 318 +QT289 744 +AQ45Q 846 +K2583 841 +55556 837 +76662 286 +79577 893 +K3J47 140 +QAT37 644 +89QT7 921 +3AAAA 379 +K49K8 647 +7373Q 396 +9J5Q8 254 +799Q7 85 +5J55K 558 +TJ254 528 +Q5QJQ 207 +23223 527 +AQ83K 694 +9TJ2J 101 +9476K 590 +TTQ5J 359 +A9TQ2 641 +2J35Q 519 +55522 398 +99949 708 +94K3K 234 +4J884 336 +3T32T 633 +33J3K 137 +8J778 456 +8Q57T 726 +79975 177 +J37Q2 467 +TKKKT 553 +47442 992 +AT7K3 875 +76666 573 +424QJ 497 +333K8 597 +AJTAA 29 +89Q26 844 +3KK33 723 +A9AKJ 138 +77555 592 +33888 762 +T5342 561 +75547 190 +TT4JT 650 +45Q55 818 +7J777 935 +333TQ 478 +566J4 71 +T7QTT 854 +28558 643 +26895 273 +8762A 58 +J333J 79 +387J4 437 +T9926 980 +4K425 325 +97Q5K 546 +Q57K3 898 +AA988 579 +669JA 678 +859J5 701 +29992 700 +JA66A 141 +4J777 440 +J7A7A 816 +JQQ96 941 +43354 924 +66T22 408 +49444 865 +6KA5A 649 +Q5T28 106 +77977 352 +J56Q5 31 +22656 814 +AT333 518 +6JTT6 2 +99889 838 +JAKAK 790 +35355 247 +T2A82 32 +68888 429 +Q69T3 944 +8688K 72 +684K8 337 +T9576 385 +333A4 674 +3T633 994 +92JQK 894 +A6293 517 +KK288 327 +373Q4 66 +KKJJ8 737 +38T67 995 +KKJ4K 609 +95898 615 +AQQA9 802 +TT8J7 67 +3A438 397 +AJAKJ 895 +254A2 808 +J9T26 117 +AJAAJ 954 +94499 847 +T8999 836 +K4T7J 529 +24444 535 +J2222 956 +44KA4 45 +6A66A 95 +52778 856 +JKJKK 346 +AAJAA 211 +J52J5 103 +786JJ 693 +Q66J6 876 +5353J 511 +KK6K6 438 +K9Q99 424 +948T9 655 +K47KK 380 +97937 271 +KKK4K 617 +J4978 142 +7Q848 149 +8733J 312 +88778 172 +6A363 926 +KQQ4K 468 +AK9Q7 962 +9TQ58 436 +KJK57 165 +KA464 967 +8TTQQ 10 +7464K 306 +558Q7 583 +29999 267 +QAA82 656 +K6A75 760 +7775J 442 +KJ3K3 332 +JQ2T4 128 +T9728 350 +J4494 89 +498TT 365 +AJA4Q 193 +666Q4 806 +37476 410 +896QK 302 +KKJ6Q 614 +29522 265 +5TA48 287 +AJ24T 705 +76TK2 173 +A2749 261 +J9575 433 +KQ948 828 +59545 952 +3AT56 275 +664Q8 182 +6429T 554 +QQ8QQ 406 +24AA4 259 +5J66J 315 +9338Q 981 +66637 503 +TT888 354 +23243 179 +6K54J 804 +277J3 855 +22727 682 +3693Q 64 +97489 375 +57T88 174 +TQA36 428 +KK5KK 839 +Q343Q 589 +A2262 628 +A9AJA 373 +56757 565 +3K333 454 +96622 233 +JJJ8J 370 +9KTTT 466 +K22JK 702 +KKK33 508 +T9T9T 715 +99595 368 +TJT55 485 +J28T8 591 +T8768 291 +T7K68 845 +J666J 663 +Q966J 105 +J3333 360 +8AQA3 496 +KJTQK 316 +KTTT3 372 +A259T 181 +7777Q 191 +78777 911 +7A925 208 +QAQKQ 930 +Q736K 747 +K7KTK 920 +388T3 982 +Q5QQQ 218 +49J49 145 +23329 219 +K97KQ 736 +7KQJ7 667 +4KJA6 323 +422T2 857 +KJJKT 746 +T7TTT 727 +J552T 304 +77TKK 107 +K432J 278 +9JJ99 988 +6Q8A8 283 +2A6T8 890 +28AA5 601 +T662T 721 +55J5J 725 +4QTQ4 237 +TKK4T 175 +22682 471 +J8538 343 +498J3 910 +3T548 850 +33868 465 +K55K3 151 +947KJ 118 +3T9A5 281 +4T83K 422 +22K27 51 +J777J 80 +A8579 199 +K5AK5 972 +77233 867 +J8J88 938 +22TJ9 369 +757A8 686 +93J2Q 758 +A79T6 999 +J6KA9 239 +J4444 378 +QJJ62 59 +JQ6Q3 928 +KK888 543 +J636J 4 +9AA3A 599 +69J6J 582 +6JKJK 110 +Q77QQ 244 +Q7272 866 +2346J 689 +868J8 892 +969J9 500 +5T5K5 619 +27622 937 +99799 901 +KK336 205 +J5566 975 +2A955 947 +TKQ57 52 +99995 618 +36223 301 +T4TT8 90 +A99AA 49 +29699 969 +84QTJ 449 +3T99J 801 +TQQQQ 96 +TTK99 344 +2J282 98 +7TT79 152 +J7JJ7 480 +A288J 393 +888J8 411 +689K6 294 +4T2J4 787 +Q3344 307 +2A7TA 611 +7J86Q 624 +69J85 869 +37878 771 +355QA 292 +5757J 357 +844Q8 156 +8TTTT 416 +QK9KQ 299 +4A6K5 757 +76777 68 +K692K 710 +QJ853 813 +2JJ2J 256 +7TTKK 957 +9JK9K 56 +4A55A 303 +K6K22 228 +99747 767 +6K839 560 +JA4TA 248 +JA822 459 +J6428 668 +KKT9K 677 +A7AAA 65 +38333 796 +664Q3 120 +J7432 36 +A356J 111 +73Q49 475 +86TJ2 899 +24442 864 +55444 729 +7K6K4 753 +7269Q 960 +77J6J 194 +8K694 210 +5338J 544 +TT99J 745 +55T5T 622 +33Q33 367 +55558 342 +737J4 148 +6T6J9 613 +3AA2T 296 +434J6 319 +333T3 690 +44848 936 +A98A9 638 +7K254 670 +74AJQ 104 +69698 266 +76477 821 +TQJTT 580 +4TKK4 909 +45555 474 +53QQ5 887 +QJA3Q 443 +94A85 136 +3KAAA 913 +39999 403 +A4J4Q 825 +28T5A 874 +ATTA4 54 +43JJ4 226 +T9J48 509 +K7T23 945 +AT2Q8 557 +6Q7J4 789 +KKK9K 16 +93J79 317 +79653 200 +Q666Q 335 +AQ33A 362 +A999J 765 +5QT47 441 +JQQQT 756 +9T325 122 +4AQ8T 571 +TQ342 70 +222JK 779 +JA443 300 +J7K88 990 +646T6 154 +95569 842 +4J626 384 +44KK4 50 +JQQQQ 93 +AA6AA 735 +99888 929 +4KK9K 629 +A38K2 75 +AA2AA 163 +QQKQQ 87 +8Q56K 578 +QK467 740 +94329 687 +257A6 695 +K9929 345 +777A7 645 +QA9AA 57 +KKAAA 959 +5T5T9 188 +8JTTJ 33 +2KKAQ 371 +47747 671 +28538 202 +TJ38A 881 +656A5 491 +54Q89 134 +8Q888 704 +AKAKK 415 +J2Q92 524 +23859 347 +8K7A6 20 +JK676 826 +555K5 833 +9AK54 490 +JT658 793 +79KQ4 778 +JA7K2 229 +88883 840 +87778 791 +799K7 712 +4KKKA 487 +T6JTT 537 +ATQK2 76 +Q5679 392 +7QKQ7 147 +8KKKK 568 +772J6 363 +58545 41 +A89KT 696 +Q3T86 616 +QAK54 289 +33334 86 +2AAA2 158 +A55A5 83 +TAAT5 102 +Q9673 46 +9KKK8 882 +6JA46 486 +6A254 277 +JTTK2 556 +J76Q2 269 +9Q888 781 +J4K4K 100 +TAATA 488 +AA9AA 598 +78TQ3 722 +A888A 260 +T675Q 34 +T3T33 761 +Q32AQ 35 +4QA45 820 +87AAA 635 +QAA3K 516 +J5543 683 +64546 404 +74T67 464 +3QT3T 731 +7TT77 978 +7J77K 402 +AAKQ4 7 +349TA 251 +682QA 917 +4357T 245 +75KT6 183 +4QQ54 652 +25QK8 358 +95KKA 996 +66556 407 +ATTKK 494 +666JK 612 +3JK5K 290 +426J2 522 +JA59J 823 +5755T 308 +JTAQK 831 +T52Q9 769 +5JKKK 387 +8QKKK 333 +5K59K 541 +44454 942 +64625 530 +JK7T9 361 +2TQQQ 270 +42AK6 997 +83T87 532 +942AQ 785 +KAQQK 993 +44666 750 +43KQ8 418 +KJ522 749 +JQQ77 953 +22J26 119 +7TK6Q 531 +8TAK6 127 +44QQ3 63 +63236 853 +66A9A 873 +K3J3T 805 +73373 797 +3J336 902 +TT67T 896 +88KKK 810 +KKKQJ 139 +69Q58 718 +9AKQ5 501 +3223J 948 +55AJA 588 +99K59 434 +86568 755 +T25AT 897 +Q2532 502 +38383 388 +J2A98 832 +4TA4A 606 +32888 730 +J9TJA 545 +3328J 339 +5TTT5 907 +J3AAJ 819 +59459 880 +99933 255 +3K762 834 +9T729 448 +58885 376 +94449 6 +J7767 374 +KKT27 203 +QQJQA 133 +A4K82 326 +TTTK4 803 +5789J 661 +67633 394 +J37KK 197 +55Q57 204 +455Q2 562 +TQ539 626 +JJ222 714 +JJJJJ 728 +98599 225 +K666K 971 +QKKK7 878 +A8888 664 +99JKJ 213 +Q332Q 774 +5J525 130 +77377 786 +3KAT4 637 +48A9A 891 +7K737 409 +J8Q89 525 +TT898 877 +3Q888 534 +JTA8A 886 +J57J8 991 +9TKA5 555 +76Q27 412 +72977 504 +488TK 830 +2K748 162 +T74T9 566 +K475J 425 +KK62K 889 +AJ4TT 510 +578KT 124 +666J6 570 +74968 331 +2T265 620 +67677 439 +AAJ79 949 +88339 799 +AJQ9A 927 +J34T3 523 +929KK 551 +2479Q 227 +KKJKK 918 +85445 201 +9Q7J6 536 +47454 513 +A2A4Q 607 +A648J 759 +A97A7 514 +J86AA 240 +Q6374 576 +4J3Q5 26 +35A75 178 +46KQ4 734 +842A2 457 +AA4A4 885 +724Q5 925 +977J8 654 +TTT5T 662 +J3339 679 +67J67 548 +QTJJ6 28 +QTAAJ 330 +TTJTT 216 +7A5A7 483 +5JJ8A 973 +53AK4 639 +KKKJT 640 +43825 782 +K5KK5 381 +7QT77 77 +99777 40 +777K8 752 +2QQ77 811 +J75TQ 320 +9K552 445 +A65QA 125 +Q2379 469 +74A98 253 +69969 340 +QKT84 748 +TTQQ7 230 +74QJT 985 +57757 311 +Q7T27 587 +Q8Q99 135 +6K854 279 +3TKAA 717 +77484 391 +Q2K24 399 +Q7QQJ 572 \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ef65f33..75251ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod three; mod four; mod five; mod six; +mod seven; fn main() { let args: Vec = env::args().collect(); @@ -25,6 +26,7 @@ fn main() { "5p2" => five::run_part2(), "6" => six::run(), "6p2" => six::run_part2(), + "7" => seven::run(), _ => Ok(-1), }; diff --git a/src/seven.rs b/src/seven.rs new file mode 100644 index 0000000..c81a812 --- /dev/null +++ b/src/seven.rs @@ -0,0 +1,194 @@ +use std::{cmp::Ordering, collections::HashMap}; + +use crate::common::load_input; + +// +// Card +// + +#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Copy, Clone, Debug)] +enum Card { + A = 14, + K = 13, + Q = 12, + J = 11, + T = 10, + N9 = 9, + N8 = 8, + N7 = 7, + N6 = 6, + N5 = 5, + N4 = 4, + N3 = 3, + N2 = 2, +} + +impl TryFrom for Card { + type Error = &'static str; + + fn try_from(value: char) -> Result { + match value { + 'A' => Ok(Card::A), + 'K' => Ok(Card::K), + 'Q' => Ok(Card::Q), + 'J' => Ok(Card::J), + 'T' => Ok(Card::T), + '9' => Ok(Card::N9), + '8' => Ok(Card::N8), + '7' => Ok(Card::N7), + '6' => Ok(Card::N6), + '5' => Ok(Card::N5), + '4' => Ok(Card::N4), + '3' => Ok(Card::N3), + '2' => Ok(Card::N2), + _ => Err("Not a card"), + } + } +} + +// +// Hand Value +// + +#[derive(PartialEq, PartialOrd, Ord,Eq, Hash, Copy, Clone, Debug)] +enum HandValue { + FiveOfKind = 6, + FourOfKind = 5, + FullHouse = 4, + ThreeOfKind = 3, + TwoPair = 2, + OnePair = 1, + HighCard = 0, +} + +// +// Hand +// +#[derive(PartialEq, Eq, Copy, Clone, Debug)] +struct Hand { + cards: [Card; 5], +} + +impl TryFrom<&str> for Hand { + type Error = &'static str; + + fn try_from(value: &str) -> Result { + let cards: Vec<_> = value.chars().map(|e| Card::try_from(e)).collect(); + if !cards.iter().all(|e| e.is_ok()) { + return Err("Invalid char"); + } + + if cards.iter().count() != 5 { + return Err("To many cards"); + } + + let arr: [Card; 5] = [ + cards.get(0).unwrap().unwrap(), + cards.get(1).unwrap().unwrap(), + cards.get(2).unwrap().unwrap(), + cards.get(3).unwrap().unwrap(), + cards.get(4).unwrap().unwrap(), + ]; + + return Ok(Hand { cards: arr }); + } +} + +impl Hand { + fn get_hand_value(&self) -> HandValue { + let groups = self.get_card_cout(); + // Check Five of a kind + if groups.iter().any(|e| *e.1 == 5) { + return HandValue::FiveOfKind; + } + + // Check for Four of a kind + if groups.iter().any(|e| *e.1 == 4) { + return HandValue::FourOfKind; + } + + //Check full house + if groups.iter().any(|e| *e.1 == 3) && groups.iter().any(|e| *e.1 == 2) { + return HandValue::FullHouse; + } + + // Check for Three of a kind + if groups.iter().any(|e| *e.1 == 3) { + return HandValue::ThreeOfKind; + } + + // Check for 1 and 2 Pairs + let pairs = groups.iter().filter(|e| *e.1 == 2).count(); + if pairs == 2 { + return HandValue::TwoPair; + } + + if pairs == 1 { + return HandValue::OnePair; + } + + return HandValue::HighCard; + } + + fn get_card_cout(&self) -> HashMap { + let mut rtn = HashMap::new(); + self.cards.iter().for_each(|e| { + match rtn.get(e) { + None => rtn.insert(*e, 1u8), + Some(v) => rtn.insert(*e, v + 1u8), + }; + }); + return rtn; + } +} + +impl PartialOrd for Hand { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(&other)) + } +} + +impl Ord for Hand { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + let self_hand_value = self.get_hand_value(); + let other_hand_value = other.get_hand_value(); + + if self_hand_value != other_hand_value { + return self_hand_value.cmp(&other_hand_value); + } + + // Compare the cards + for (self_card, other_card) in self.cards.iter().zip(other.cards.iter()) { + if self_card != other_card { + return self_card.cmp(other_card); + } + } + + return Ordering::Equal; + } +} + +// +// Everything else +// + +fn parse_input(lines: &[String]) -> Vec<(Hand, u64)> { + lines + .iter() + .map(|e| e.split_once(" ").unwrap()) + .map(|e| (Hand::try_from(e.0).unwrap(), e.1.parse::().unwrap())) + .collect() +} + +pub fn run() -> Result> { + let lines = load_input("./input/7.txt")?; + + let hands = parse_input(&lines); + + let mut orderd_hands = hands.clone(); + orderd_hands.sort_by_key(|e| e.0); + + let score: u64 = orderd_hands.iter().enumerate().map(|e| (e.0 + 1) as u64 * (e.1.1)).sum(); + + Ok(score as i32) +}