From 17049c1f98a5f2dc5d4a6c40ada33bb6442ec9d9 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 9 Dec 2023 11:10:31 +0100 Subject: [PATCH] solve day 7 part 1 --- 2023/day06_boats.go | 3 - 2023/day07_camel_cards.go | 220 +++++++ 2023/day07_camel_cards_test.go | 170 ++++++ 2023/inputs/day07 | 1000 ++++++++++++++++++++++++++++++++ 2023/inputs/day07_test1 | 5 + 2023/inputs/day07_test2 | 6 + 2023/lib_test.go | 5 + 2023/types.go | 5 - 8 files changed, 1406 insertions(+), 8 deletions(-) create mode 100644 2023/day07_camel_cards.go create mode 100644 2023/day07_camel_cards_test.go create mode 100644 2023/inputs/day07 create mode 100644 2023/inputs/day07_test1 create mode 100644 2023/inputs/day07_test2 diff --git a/2023/day06_boats.go b/2023/day06_boats.go index 4815f5e..a200c68 100644 --- a/2023/day06_boats.go +++ b/2023/day06_boats.go @@ -2,7 +2,6 @@ package _023 import ( "bufio" - "fmt" "io" "math" "strings" @@ -15,7 +14,6 @@ func Day06Part1(input io.Reader) (int, error) { times := lineToInts(strings.TrimPrefix(scanner.Text(), "Time:")) scanner.Scan() distances := lineToInts(strings.TrimPrefix(scanner.Text(), "Distance:")) - fmt.Println(times, distances) margin := 1 @@ -47,7 +45,6 @@ func Day06Part2(input io.Reader) (int, error) { times := lineToInts(strings.ReplaceAll(strings.TrimPrefix(scanner.Text(), "Time:"), " ", "")) scanner.Scan() distances := lineToInts(strings.ReplaceAll(strings.TrimPrefix(scanner.Text(), "Distance:"), " ", "")) - fmt.Println(times, distances) margin := 1 diff --git a/2023/day07_camel_cards.go b/2023/day07_camel_cards.go new file mode 100644 index 0000000..49a7517 --- /dev/null +++ b/2023/day07_camel_cards.go @@ -0,0 +1,220 @@ +package _023 + +import ( + "bufio" + "fmt" + "io" + "slices" + "strconv" + "strings" +) + +const d07CardsP1 = "23456789TJQKA" +const d07CardsP2 = "J23456789TQKA" + +const ( + d07HandHigh = iota + d07HandPair + d07HandTwoPairs + d07HandThree + d07HandHouse + d07HandFour + d07HandFive +) + +type d07Hand struct { + hand string + bid int + value int +} + +func newD07Hand(hand string, bid int) d07Hand { + return d07Hand{ + hand: hand, + bid: bid, + value: d07HandValueP1(hand), + } +} + +func newD07HandP2(hand string, bid int) d07Hand { + return d07Hand{ + hand: hand, + bid: bid, + value: d07HandValueP2(hand), + } +} + +func Day07Part1(input io.Reader) (int, error) { + scanner := bufio.NewScanner(input) + + var hands []d07Hand + for scanner.Scan() { + line := strings.Split(scanner.Text(), " ") + hand, bidS := line[0], line[1] + bid, err := strconv.Atoi(bidS) + if err != nil { + return 0, fmt.Errorf("converting bid to int on line %v: %w", line, err) + } + hands = append(hands, newD07Hand(hand, bid)) + } + + slices.SortFunc(hands, d07CmpHands) + + sum := 0 + for i, hand := range hands { + sum += (i + 1) * hand.bid + } + + return sum, nil +} + +func d07CmpHands(a d07Hand, b d07Hand) int { + // cmp(a, b) should return a negative number when a < b, a positive number when + // a > b and zero when a == b. + if a.value < b.value { + return -1 + } + if a.value > b.value { + return 1 + } + + for i := 0; i < len(a.hand); i++ { + aValue := strings.Index(d07CardsP1, a.hand[i:i+1]) + bValue := strings.Index(d07CardsP1, b.hand[i:i+1]) + if aValue > bValue { + return 1 + } + if aValue < bValue { + return -1 + } + } + + return 0 +} + +func d07HandValueP1(hand string) int { + count := make(map[rune]byte) + var maxCount byte = 1 + var maxFor rune + var secondMax byte = 1 + for _, c := range hand { + v := count[c] + v++ + if v > maxCount { + maxCount = v + maxFor = c + } + count[c] = v + } + for c, v := range count { + if secondMax < v && c != maxFor { + secondMax = v + } + } + switch { + case maxCount == 5: + return d07HandFive + case maxCount == 4: + return d07HandFour + case maxCount == 3 && secondMax == 2: + return d07HandHouse + case maxCount == 3 && secondMax == 1: + return d07HandThree + case maxCount == 2 && secondMax == 2: + return d07HandTwoPairs + case maxCount == 2 && secondMax == 1: + return d07HandPair + default: + return d07HandHigh + } +} + +func Day07Part2(input io.Reader) (int, error) { + scanner := bufio.NewScanner(input) + + var hands []d07Hand + for scanner.Scan() { + line := strings.Split(scanner.Text(), " ") + hand, bidS := line[0], line[1] + bid, err := strconv.Atoi(bidS) + if err != nil { + return 0, fmt.Errorf("converting bid to int on line %v: %w", line, err) + } + hands = append(hands, newD07HandP2(hand, bid)) + } + + slices.SortFunc(hands, d07CmpHandsP2) + + sum := 0 + for i, hand := range hands { + sum += (i + 1) * hand.bid + } + + return sum, nil +} + +func d07HandValueP2(hand string) int { + count := make(map[rune]byte) + var maxCount byte = 1 + var maxFor rune + var secondMax byte = 1 + for _, c := range hand { + v := count[c] + v++ + if v > maxCount && c != 'J' { + maxCount = v + maxFor = c + } + count[c] = v + } + joker, ok := count['J'] + maxCount += joker + if ok { + delete(count, 'J') + } + for c, v := range count { + if secondMax < v && c != maxFor { + secondMax = v + } + } + switch { + case maxCount == 5: + return d07HandFive + case maxCount == 4: + return d07HandFour + case maxCount == 3 && secondMax == 2: + return d07HandHouse + case maxCount == 3 && secondMax == 1: + return d07HandThree + case maxCount == 2 && secondMax == 2: + return d07HandTwoPairs + case maxCount == 2 && secondMax == 1: + return d07HandPair + default: + return d07HandHigh + } +} + +func d07CmpHandsP2(a d07Hand, b d07Hand) int { + // cmp(a, b) should return a negative number when a < b, a positive number when + // a > b and zero when a == b. + if a.value < b.value { + return -1 + } + if a.value > b.value { + return 1 + } + + for i := 0; i < len(a.hand); i++ { + aValue := strings.Index(d07CardsP2, a.hand[i:i+1]) + bValue := strings.Index(d07CardsP2, b.hand[i:i+1]) + if aValue > bValue { + return 1 + } + if aValue < bValue { + return -1 + } + } + + return 0 +} diff --git a/2023/day07_camel_cards_test.go b/2023/day07_camel_cards_test.go new file mode 100644 index 0000000..60972c8 --- /dev/null +++ b/2023/day07_camel_cards_test.go @@ -0,0 +1,170 @@ +package _023 + +import ( + "fmt" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "os" + "testing" +) + +func TestDay07Part1(t *testing.T) { + tests := []testCase{ + {"inputs/day07_test1", 6440}, + {"inputs/day07", 246424613}, + } + for _, test := range tests { + t.Run(test.filename, check(test, Day07Part1)) + } +} + +func TestDay07Part2(t *testing.T) { + tests := []testCase{ + {"inputs/day07_test1", 5905}, + {"inputs/day07_test2", 5911}, + {"inputs/day07", 0}, // 247974245 is too low + } + for _, test := range tests { + t.Run(test.filename, check(test, Day07Part2)) + } + t.Run("247974245 is too low", func(t *testing.T) { + file, err := os.Open("inputs/day07") + require.NoError(t, err) + got, err := Day07Part2(file) + require.NoError(t, err) + assert.Greater(t, got, 247974245) + }) +} + +func TestDay07HandValueP1(t *testing.T) { + tests := []struct { + hand string + expected int + }{ + {"AAAAA", d07HandFive}, + {"AAAA2", d07HandFour}, + {"AA2AA", d07HandFour}, + {"3KKK3", d07HandHouse}, + {"3KKK4", d07HandThree}, + {"KKQQT", d07HandTwoPairs}, + {"KQTQK", d07HandTwoPairs}, + {"QQ567", d07HandPair}, + {"T6862", d07HandPair}, + {"A2345", d07HandHigh}, + } + for _, test := range tests { + t.Run(test.hand, func(t *testing.T) { + assert.Equal(t, test.expected, d07HandValueP1(test.hand)) + }) + } +} + +func TestDay07HandValueP2(t *testing.T) { + tests := []struct { + hand string + expected int + }{ + {"AAAAA", d07HandFive}, + {"AAJJJ", d07HandFive}, + {"AAAA2", d07HandFour}, + {"JJAJ2", d07HandFour}, + {"JKKK2", d07HandFour}, + {"QJJQ2", d07HandFour}, + {"AA2AA", d07HandFour}, + {"AJ2JA", d07HandFour}, + {"3KKK3", d07HandHouse}, + {"3KJK3", d07HandHouse}, + {"3KKK4", d07HandThree}, + {"3KKJ4", d07HandThree}, + {"KKQQT", d07HandTwoPairs}, + {"KQTQK", d07HandTwoPairs}, + {"QQ567", d07HandPair}, + {"JQ567", d07HandPair}, + {"T6862", d07HandPair}, + {"T68J2", d07HandPair}, + {"A2345", d07HandHigh}, + } + for _, test := range tests { + t.Run(test.hand, func(t *testing.T) { + assert.Equal(t, test.expected, d07HandValueP2(test.hand)) + }) + } +} + +func TestD07CmpHands(t *testing.T) { + type args struct { + a string + b string + } + tests := []struct { + name string + args args + want int + }{ + { + name: "five and four", + args: args{"AAAAA", "KAAAA"}, + want: 1, + }, + { + name: "four and four", + args: args{"2AAAA", "33332"}, + want: -1, + }, + { + name: "house and house", + args: args{"77888", "77788"}, + want: 1, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equalf(t, tt.want, d07CmpHands(newD07Hand(tt.args.a, 0), newD07Hand(tt.args.b, 0)), "d07CmpHands(%v, %v)", tt.args.a, tt.args.b) + }) + } +} + +func TestD07CmpHandsP2(t *testing.T) { + type args struct { + a string + b string + } + tests := []struct { + args args + want int + }{ + { + args: args{"T55J5", "KTJJT"}, + want: -1, + }, + { + args: args{"KTJJT", "QQQJA"}, + want: 1, + }, + { + args: args{"T55J5", "QQQJA"}, + want: -1, + }, + { + args: args{"J55T5", "JQQQA"}, + want: -1, + }, + { + args: args{"555T5", "JQQQA"}, + want: 1, + }, + { + args: args{"QQQQ2", "JKKK2"}, + want: 1, + }, + } + for _, tt := range tests { + char := "<" + if tt.want == 1 { + char = ">" + } + t.Run(fmt.Sprintf("%v%v%v", tt.args.a, char, tt.args.b), func(t *testing.T) { + assert.Equalf(t, tt.want, d07CmpHandsP2(newD07HandP2(tt.args.a, 0), newD07HandP2(tt.args.b, 0)), "d07CmpHandsP2(%v, %v)", tt.args.a, tt.args.b) + }) + } +} diff --git a/2023/inputs/day07 b/2023/inputs/day07 new file mode 100644 index 0000000..12bfd93 --- /dev/null +++ b/2023/inputs/day07 @@ -0,0 +1,1000 @@ +53AQ3 698 +555A5 490 +KQQ8K 338 +Q8J88 94 +T844J 329 +99A9A 918 +5846Q 753 +99TJT 175 +A3465 353 +J9K99 725 +6A9Q8 525 +5Q2K3 666 +88688 729 +4TA4J 398 +Q4JA9 769 +33937 941 +TTT4T 743 +95999 256 +597K7 401 +73Q79 258 +AAJKJ 419 +9TA77 7 +Q727K 810 +QQJQ4 977 +QA764 57 +4J694 116 +969TT 379 +AAA77 897 +84333 535 +2J444 694 +22TK2 313 +29244 557 +K77K8 231 +54995 916 +T24QK 700 +97543 325 +788A8 37 +T5858 872 +2TTT2 154 +JJ482 518 +24748 104 +272J2 25 +A7KJK 82 +7T5Q4 900 +33T23 577 +7JQAA 846 +3KKKK 61 +67396 644 +K99KK 328 +QKAKQ 435 +297A9 103 +AA5AA 428 +577TJ 536 +56393 460 +K8K8A 605 +ATTJQ 529 +A8T33 865 +29889 777 +9QAJK 310 +3A2AJ 866 +A8888 568 +9TAJ7 93 +46QQ6 508 +J62QK 341 +4Q4JK 522 +JAJ43 504 +J6K45 26 +TAT9A 784 +9A4Q7 531 +T4554 142 +828QQ 619 +J7K7J 985 +92296 695 +9J989 565 +27775 902 +4652Q 656 +QQQ6Q 701 +43K67 318 +7QT92 994 +T3366 757 +4AA77 511 +6859Q 312 +87222 875 +76749 429 +36KQQ 639 +66966 130 +88T8T 68 +3Q33J 521 +76T36 216 +44592 876 +9QJJ5 906 +382Q7 764 +555TT 407 +77977 888 +32J77 305 +K4KQK 73 +KQJ33 894 +94J3Q 242 +44Q46 90 +488JK 474 +5Q2K7 121 +47A56 38 +J393K 739 +9A933 691 +Q222A 15 +22422 177 +K8A27 471 +J744A 840 +TTTJT 219 +KK2K3 652 +4TT49 822 +7279Q 277 +JJ8JJ 623 +KJKKK 355 +7QQ37 164 +J3829 101 +487T7 514 +3T333 838 +K74Q9 126 +7K7KQ 625 +6J644 50 +2942J 651 +68868 742 +TJTT7 998 +44JAA 842 +96844 873 +T8TTK 27 +A9373 836 +2JQ25 238 +7Q66K 879 +5928J 996 +K524Q 109 +55AAA 861 +48437 58 +4J5K9 792 +Q6A54 606 +KQ7A4 352 +KKKTK 496 +83844 539 +K7KK7 158 +TQKQT 749 +A2AAA 186 +973A4 32 +Q9J6K 654 +83A3Q 40 +JKK3K 221 +KA5T2 844 +2J525 513 +94797 248 +35355 308 +JT4A3 787 +55J55 543 +3A982 687 +75758 400 +T94A5 115 +2K7K7 523 +ATJAA 871 +725A6 424 +TATTT 141 +26TK5 783 +6666J 272 +T9939 440 +8TT4T 234 +T98JT 67 +K22TT 117 +K6293 223 +5542K 378 +98779 629 +KKAAK 556 +JT666 71 +59AT3 937 +J83QQ 610 +7KK88 466 +Q7TKK 657 +44J74 889 +3J37J 79 +77J7T 685 +6692K 266 +TT2A9 554 +58A6J 963 +5TQ76 343 +QJ633 206 +39QQ4 563 +AA66A 333 +JKKJ3 575 +6TK6T 139 +45K7A 789 +8448K 704 +88J8J 645 +J8QQA 296 +6TA56 236 +TTJT2 83 +TKKK2 895 +73J7T 898 +3975J 632 +8T267 624 +4TT4T 251 +A44A4 456 +3J974 364 +345J3 956 +9T9J2 3 +9999K 145 +QQJ4A 371 +78594 638 +78T7J 699 +5455T 817 +A9J8J 947 +AA6AA 955 +8KAKA 828 +42KT5 229 +38373 171 +K7TKA 43 +92JJ3 49 +8Q7T5 939 +J79J9 112 +652K6 174 +999JA 516 +72J82 351 +QK6AQ 28 +TT7J6 436 +T8TTT 834 +T2338 307 +7Q77Q 858 +JQQJA 903 +66JKJ 143 +75JT8 870 +82TKA 781 +224Q8 395 +ATA7A 484 +4K33K 35 +45Q72 643 +Q88J3 847 +459J6 993 +QK8QT 259 +8888T 235 +K2J7A 733 +KT74Q 576 +AQQQQ 210 +5A967 786 +937J7 710 +6JT7K 54 +AJA58 59 +K754K 949 +T6K8Q 591 +T3444 185 +3J269 635 +JJ222 323 +66433 669 +T55JT 243 +787A7 984 +97969 294 +74777 10 +99T99 414 +3A3JA 770 +34A87 830 +AAKAK 264 +33322 848 +JJ547 153 +44Q43 620 +92777 826 +4K5K8 803 +66A66 982 +68666 285 +Q3Q53 215 +87455 17 +J58T4 616 +J79Q7 181 +TTKKT 87 +AQAAQ 630 +QQ65K 374 +J2J57 5 +25545 973 +AT6A6 373 +55656 199 +56755 807 +55552 358 +262J3 495 +TQ24T 102 +JK8K9 208 +68J42 314 +TJA8Q 752 +2542J 389 +8KK88 394 +94A29 196 +494TJ 755 +KAKK8 672 +J545J 157 +TQ7TQ 463 +64J98 622 +JA6A3 499 +QQQ4Q 18 +99994 944 +3722A 437 +33T3K 24 +K2225 122 +89896 726 +9TT9Q 8 +KJKQQ 369 +A44A6 72 +T853A 882 +A969A 372 +6665K 254 +25235 200 +3A84T 475 +6A5K6 298 +TK3T3 650 +KT6A4 642 +26A7J 991 +QQQQ8 23 +8888K 689 +T3AQ7 609 +A9TJA 581 +AAKTA 547 +AAAJQ 590 +3K5A8 194 +QQ8TQ 127 +45556 665 +AAA44 852 +63396 148 +J3333 144 +87T63 297 +3T33T 663 +K2AJA 64 +5J754 408 +7TTKK 135 +727J2 714 +6QA87 12 +K6K52 346 +828JQ 98 +266T6 11 +8AATA 488 +JKQJT 375 +AK5T5 267 +777AA 491 +83JQ7 597 +T5K6T 538 +4AQ63 51 +8K93Q 968 +227AA 220 +A5AJA 721 +75445 760 +TA9JJ 823 +88877 70 +TTT95 268 +8J67J 972 +223JA 534 +9494K 173 +95959 683 +43KT7 42 +5KKKK 279 +58553 6 +4K222 180 +2999Q 835 +Q4AJ4 716 +8TQQT 628 +9Q577 992 +T99TT 381 +2JK26 123 +77722 222 +QJJ83 442 +88TT3 487 +62222 473 +76766 226 +42J3T 920 +43K4A 507 +8AKQT 120 +63T33 131 +39TT3 183 +AATT5 804 +995Q7 709 +24343 604 +AKJ77 168 +44888 421 +TATQT 598 +4A244 271 +37J6J 533 +T2AJ3 860 +222KK 253 +QJ64T 544 +3Q883 746 +99779 365 +73773 340 +3488J 831 +A4TJ8 911 +A4628 877 +5J55J 922 +89383 217 +44265 227 +87822 360 +KKKJT 960 +J9TTQ 332 +J6668 202 +79377 53 +8363K 76 +77T77 56 +JQJTT 66 +Q5555 891 +QQTTT 517 +3Q3Q3 498 +37J88 416 +JK284 845 +9KA9K 349 +2T88Q 927 +3Q333 403 +KA739 284 +975JK 502 +JJ353 438 +QT4K6 454 +QQ272 1 +KKJJ4 60 +96842 829 +539T8 827 +7J979 573 +28ATT 686 +J77J7 931 +KK6KK 169 +TK236 524 +552Q7 724 +75555 423 +77JJJ 970 +7J337 224 +9J98Q 455 +JTT94 603 +84448 427 +QKQ7K 452 +JK5A8 445 +3J33J 631 +95595 415 +52552 147 +55AKK 477 +922J9 607 +79292 925 +65665 765 +4JJ74 330 +44494 204 +K5924 762 +45975 288 +4AA84 771 +66999 111 +66JK5 161 +23JKT 962 +8QJ86 658 +88Q22 48 +JJ3T8 837 +4T44T 634 +94323 1000 +K8A64 813 +2QJ33 558 +AK95A 680 +442KT 347 +KK7KK 727 +9A273 969 +77AJ3 451 +6333A 4 +A4AT2 797 +37673 551 +TT5QT 500 +22A6A 540 +JK2J6 928 +T3J72 893 +K8A6A 376 +QT7Q7 626 +336J6 304 +97374 667 +K49K4 703 +Q8555 756 +63333 682 +8A787 404 +92499 932 +43334 494 +6464Q 361 +848TT 387 +A352K 483 +Q4454 228 +AJT4T 320 +5A2A5 732 +56266 151 +KJT45 594 +Q43T2 383 +J363J 118 +TT326 192 +66Q66 952 +8J778 790 +AAA2J 849 +339JJ 798 +33593 512 +49J55 406 +44447 530 +3QQTA 615 +977JJ 300 +86966 503 +Q6QQ6 326 +55775 63 +33222 31 +759TQ 673 +TTTT6 883 +22727 492 +255K2 713 +6JK2K 887 +646K6 862 +76677 596 +QK4JJ 758 +573J2 478 +QQQJ5 195 +TJJTT 80 +355J2 350 +4J288 722 +8TAT8 741 +43888 541 +TQ428 485 +AA4T8 582 +T2KJJ 808 +3TJ69 317 +9T6T5 481 +7K9A9 904 +TT5K2 549 +5QQQQ 113 +9339K 146 +A23A2 29 +88824 647 +35335 546 +539J4 542 +QQ9Q9 868 +QQ7Q7 409 +85854 207 +27777 964 +58226 519 +KK936 166 +277JJ 816 +8Q4A5 246 +Q9QAA 773 +A9444 506 +52546 441 +83833 184 +T3J3T 945 +7J98A 399 +57553 981 +8Q6QQ 602 +AJAJA 528 +7878T 449 +33A33 356 +AQ7JJ 211 +28822 74 +4A6K9 265 +4Q499 493 +TT2QT 560 +66365 908 +A2TTA 917 +777TT 417 +95A32 824 +5588Q 41 +T4Q4T 467 +99777 815 +2K2JK 617 +K93KK 957 +AAAJA 179 +69695 592 +ATA9Q 240 +4999T 96 +KK55K 980 +445A5 377 +KKJAA 579 +86586 133 +6KQ65 299 +Q5525 319 +232J3 593 +Q6Q66 708 +5522A 979 +2A92K 282 +TAT4A 170 +97A5T 878 +9595K 426 +2QJQQ 670 +99355 331 +A2JQ9 905 +9J444 751 +6J4J4 867 +32A4K 457 +6K766 599 +4Q367 874 +79966 397 +79999 278 +62Q9Q 978 +Q2Q37 434 +4J7TJ 580 +TKTTQ 646 +7K7K7 555 +4354J 36 +7K9JJ 405 +A3476 198 +J74J7 303 +A7TK8 515 +936T8 571 +AAAJ3 550 +AAQAA 261 +66664 203 +44QTQ 613 +A5659 859 +T77A8 954 +AJ833 81 +KK4KK 182 +Q4JJ2 618 +K9TT9 548 +82K8K 820 +6KK57 344 +66TT9 738 +52Q7Q 247 +9999A 422 +AA33A 241 +5KAQA 929 +9AAAA 923 +4J6Q5 983 +699J9 160 +85J55 775 +83543 584 +3K636 884 +AT92Q 178 +45Q67 967 +J2JJ2 255 +88A7A 190 +99K98 384 +98999 819 +99476 167 +442JJ 561 +4T263 750 +K3J2K 239 +9K8A7 274 +K333K 260 +AQQAQ 269 +J783J 388 +9QJ32 9 +22Q22 453 +58644 411 +98799 674 +755K2 140 +52252 734 +8878J 832 +5AA56 191 +988JJ 833 +5QQQ5 800 +JTJTA 155 +48J4A 19 +AAKTT 857 +6A665 532 +K623K 767 +33AK3 110 +K642J 88 +J26T3 661 +45845 915 +29J44 309 +QQ82Q 785 +88848 718 +28828 315 +KK8TK 988 +QTQ4Q 156 +Q52J9 899 +Q3859 252 +6J83Q 612 +36366 913 +K27Q2 233 +2T7T3 614 +J3337 795 +KQKKK 761 +84K4J 402 +TAQ5K 129 +A3T8J 684 +5K555 509 +A98QA 189 +782Q7 856 +8234T 938 +K7J55 55 +T3KA2 779 +7J64K 946 +88632 587 +76JAJ 611 +KJ9JJ 896 +J8JQ8 909 +TQKK9 933 +5T663 262 +KJ698 311 +3T35T 134 +JJJJJ 901 +266Q8 446 +AJA77 237 +AA888 649 +KKKK9 270 +82832 855 +3883J 136 +2KJ86 728 +KJ5T3 778 +8J448 719 +39599 44 +656T5 95 +TT7TT 715 +569K8 971 +3JQQQ 863 +8887Q 286 +88K8J 851 +23622 197 +A8QQA 942 +T237A 578 +2TJT5 608 +7T533 640 +8A884 737 +43Q83 744 +A822J 809 +46464 336 +4Q94K 564 +5Q9Q6 586 +28888 34 +TTT88 959 +32QAT 337 +8T363 841 +A28AQ 583 +3J443 22 +27QTJ 881 +6KK3K 995 +5884Q 108 +J3T85 52 +QQ9K9 461 +35J35 391 +54483 176 +JQ59Q 759 +4552T 780 +7Q39K 601 +42A4J 748 +J6A6T 132 +5T4A5 433 +98KK9 165 +Q7777 720 +K44KK 850 +4447K 292 +33933 986 +A228A 187 +Q76TT 30 +775J9 763 +Q4877 958 +Q22QQ 462 +KKQ2A 418 +Q4Q44 677 +666T6 678 +3688K 690 +69KAA 766 +3J8K8 574 +TTA55 675 +A8AAA 62 +K39K9 641 +88989 172 +A3JK3 705 +9J999 105 +22A27 692 +3T49J 214 +AK749 600 +9TJK5 465 +73334 799 +AAA4A 774 +22292 212 +8K653 2 +3A72A 659 +TTT3T 637 +Q3673 124 +59563 636 +5KA89 45 +AAATA 412 +9K5K2 75 +Q944Q 910 +52583 225 +69629 16 +4A6AA 702 +3393J 999 +A492Q 892 +76JT7 468 +7KQ64 420 +TA93Q 33 +JQ694 209 +TK983 283 +383JK 965 +ATT99 805 +Q3QQQ 193 +QQQQ2 731 +99T4A 13 +QQQQJ 137 +KK22K 782 +JJ354 864 +JKTTK 367 +99K29 559 +4993J 585 +Q7727 291 +6373J 747 +2J2AJ 370 +3533A 106 +KT93Q 85 +9T4T2 814 +KK79K 276 +8T9A5 390 +8828J 335 +TT2TT 569 +K7747 20 +A4444 712 +44644 588 +444AQ 363 +AA3AA 450 +5KA99 754 +Q45J5 679 +J4443 444 +82A53 249 +7TT7J 432 +9439A 919 +A76A2 201 +QJ85A 537 +KKKJJ 470 +2T45A 545 +QJ3Q3 97 +8JTT8 431 +55563 943 +K849A 505 +444Q4 936 +677K6 966 +J4J44 489 +5585T 119 +AAT2A 688 +64646 334 +K4J8A 806 +56J3J 671 +A8T32 92 +9KQ52 321 +76367 393 +96J42 633 +8Q848 69 +2J777 380 +95TJQ 218 +4KAA9 89 +7TJ48 562 +35333 107 +9992T 295 +44448 885 +77877 281 +7AAA6 459 +577JK 595 +J8655 990 +T43J4 723 +88442 368 +A7T7T 745 +6Q5QQ 664 +29J2T 316 +444J4 150 +3Q354 653 +43KQ6 443 +895J3 232 +JA46T 472 +9AJ22 553 +4QQQ4 469 +Q7JKT 768 +TTT8J 801 +A33Q3 188 +3363J 989 +J95T4 425 +J4J49 890 +5K5K5 152 +JK4K4 14 +Q57Q7 940 +55544 706 +66K26 257 +7JQA7 921 +K969J 128 +7754Q 290 +KKKAK 357 +4849K 821 +49699 322 +8TTQT 162 +KJTJ9 552 +79K48 339 +55655 497 +AA555 385 +222J2 853 +66JA6 159 +9AQ77 662 +5TTJT 213 +27A77 572 +3J97T 306 +27329 413 +66333 696 +85AJ2 348 +KK2KA 510 +55J57 301 +AQT48 354 +K2834 869 +666J3 772 +32724 950 +74377 907 +Q7999 244 +38J33 570 +252J3 84 +98782 788 +499J8 934 +33888 386 +2JK4Q 987 +96JJ6 480 +4KQJK 125 +87965 791 +7383J 275 +Q5JQ5 65 +2A822 589 +75289 740 +37473 39 +6TK95 839 +2A726 293 +888J8 914 +98969 681 +QKK66 825 +TT77T 430 +5QQ24 245 +66J64 21 +QK4J5 396 +Q2JTK 886 +6923T 796 +5TTT5 100 +8K929 345 +22826 693 +4TJ53 458 +55855 302 +94959 520 +82A5A 912 +KT7K9 464 +55KJK 655 +Q76QK 77 +A75A9 263 +94888 924 +59578 289 +87TK8 648 +4464J 382 +K8887 621 +Q4QAQ 802 +J6AAA 149 +AA3AQ 47 +25257 976 +KQK22 818 +TQ6A2 250 +J7777 138 +4T3T4 717 +QQJJQ 676 +J7TT2 86 +4K95Q 482 +2KJKJ 953 +9JJ99 997 +22322 392 +T86J9 854 +QQQ88 359 +J84J8 707 +26226 660 +QTTTT 366 +33337 486 +J4844 501 +8Q668 793 +77294 951 +6J66J 527 +377J7 668 +9T548 843 +57757 627 +KKK85 566 +7TJ7Q 526 +A9A93 975 +72K86 114 +63AK3 447 +J823Q 961 +44669 439 +4784J 205 +9K799 794 +K3J3K 730 +25475 930 +A3783 163 +87A65 287 +36A85 99 +77497 476 +39493 948 +QT9QQ 935 +33A3A 78 +KKK8K 362 +74J47 926 +T633T 410 +3K355 448 +89367 736 +Q6556 811 +58788 697 +A2Q74 479 +TT53T 880 +7J3A6 342 +JK8KK 230 +597J6 46 +TTT49 324 +2222A 273 +T5223 91 +97QQJ 812 +37373 776 +KKKQJ 327 +77K9J 280 +TT3T3 711 +92999 567 +99993 974 +52T22 735 diff --git a/2023/inputs/day07_test1 b/2023/inputs/day07_test1 new file mode 100644 index 0000000..e3500c3 --- /dev/null +++ b/2023/inputs/day07_test1 @@ -0,0 +1,5 @@ +32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483 diff --git a/2023/inputs/day07_test2 b/2023/inputs/day07_test2 new file mode 100644 index 0000000..c4ccbd8 --- /dev/null +++ b/2023/inputs/day07_test2 @@ -0,0 +1,6 @@ +32T3K 765 +T55J5 684 +KK677 28 +KTJJT 220 +QQQJA 483 +JJJJA 1 diff --git a/2023/lib_test.go b/2023/lib_test.go index 3528836..6e68dce 100644 --- a/2023/lib_test.go +++ b/2023/lib_test.go @@ -7,6 +7,11 @@ import ( "testing" ) +type testCase struct { + filename string + want int +} + func check(test testCase, fn solveFunc) func(t *testing.T) { return func(t *testing.T) { file, err := os.Open(test.filename) diff --git a/2023/types.go b/2023/types.go index a7358f8..c0ba37e 100644 --- a/2023/types.go +++ b/2023/types.go @@ -2,9 +2,4 @@ package _023 import "io" -type testCase struct { - filename string - want int -} - type solveFunc func(reader io.Reader) (int, error)