From 007f208601063307550eda2858257c52036de7ad Mon Sep 17 00:00:00 2001 From: geraldb88 Date: Sun, 28 Dec 2025 13:53:08 -0600 Subject: [PATCH 1/2] starting fresh for part 2 --- 2025/day_1/main.go | 2 +- 2025/day_2/main.go | 2 +- 2025/day_6/go.mod | 3 - .../{ => part_1}/expression/expression.go | 0 .../expression/expression_test.go | 0 2025/day_6/{ => part_1}/expression/operand.go | 0 .../expression/operand_builder.go | 0 .../day_6/{ => part_1}/expression/operator.go | 0 2025/day_6/part_1/go.mod | 11 + 2025/day_6/part_1/go.sum | 10 + 2025/day_6/{ => part_1}/input.txt | 0 2025/day_6/{ => part_1}/main.go | 8 +- 2025/day_6/{ => part_1}/state/state.go | 2 +- 2025/day_6/part_2/go.mod | 3 + 2025/day_6/part_2/input.txt | 5 + 2025/day_6/part_2/main.go | 27 ++ 2025/day_6/part_2/state/state.go | 8 + 2025/go.work | 3 +- 2025/shared/character.go | 17 ++ 2025/shared/shared.go | 262 +++++++++--------- 2025/shared/stream_process.go | 131 +++++++++ 21 files changed, 352 insertions(+), 142 deletions(-) delete mode 100644 2025/day_6/go.mod rename 2025/day_6/{ => part_1}/expression/expression.go (100%) rename 2025/day_6/{ => part_1}/expression/expression_test.go (100%) rename 2025/day_6/{ => part_1}/expression/operand.go (100%) rename 2025/day_6/{ => part_1}/expression/operand_builder.go (100%) rename 2025/day_6/{ => part_1}/expression/operator.go (100%) create mode 100644 2025/day_6/part_1/go.mod create mode 100644 2025/day_6/part_1/go.sum rename 2025/day_6/{ => part_1}/input.txt (100%) rename 2025/day_6/{ => part_1}/main.go (88%) rename 2025/day_6/{ => part_1}/state/state.go (95%) create mode 100644 2025/day_6/part_2/go.mod create mode 100644 2025/day_6/part_2/input.txt create mode 100644 2025/day_6/part_2/main.go create mode 100644 2025/day_6/part_2/state/state.go create mode 100644 2025/shared/character.go create mode 100644 2025/shared/stream_process.go diff --git a/2025/day_1/main.go b/2025/day_1/main.go index fa08fbc..0ca046d 100644 --- a/2025/day_1/main.go +++ b/2025/day_1/main.go @@ -38,7 +38,7 @@ func main() { d.Turn(d.getAmount()) d.Reset() default: - d.amount = append(d.amount, si.R) + d.amount = append(d.amount, si.R.Rune()) } }) diff --git a/2025/day_2/main.go b/2025/day_2/main.go index 26b83e5..f5eab37 100644 --- a/2025/day_2/main.go +++ b/2025/day_2/main.go @@ -31,7 +31,7 @@ func main() { s.Pairs = append(s.Pairs, *s.CurrentPair) s.Reset() default: - s.Value = append(s.Value, si.R) + s.Value = append(s.Value, si.R.Rune()) } }) log.Printf("answer: %d", s.Result) diff --git a/2025/day_6/go.mod b/2025/day_6/go.mod deleted file mode 100644 index fe8635a..0000000 --- a/2025/day_6/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module day_6_aoc_2025 - -go 1.25.1 diff --git a/2025/day_6/expression/expression.go b/2025/day_6/part_1/expression/expression.go similarity index 100% rename from 2025/day_6/expression/expression.go rename to 2025/day_6/part_1/expression/expression.go diff --git a/2025/day_6/expression/expression_test.go b/2025/day_6/part_1/expression/expression_test.go similarity index 100% rename from 2025/day_6/expression/expression_test.go rename to 2025/day_6/part_1/expression/expression_test.go diff --git a/2025/day_6/expression/operand.go b/2025/day_6/part_1/expression/operand.go similarity index 100% rename from 2025/day_6/expression/operand.go rename to 2025/day_6/part_1/expression/operand.go diff --git a/2025/day_6/expression/operand_builder.go b/2025/day_6/part_1/expression/operand_builder.go similarity index 100% rename from 2025/day_6/expression/operand_builder.go rename to 2025/day_6/part_1/expression/operand_builder.go diff --git a/2025/day_6/expression/operator.go b/2025/day_6/part_1/expression/operator.go similarity index 100% rename from 2025/day_6/expression/operator.go rename to 2025/day_6/part_1/expression/operator.go diff --git a/2025/day_6/part_1/go.mod b/2025/day_6/part_1/go.mod new file mode 100644 index 0000000..92991de --- /dev/null +++ b/2025/day_6/part_1/go.mod @@ -0,0 +1,11 @@ +module day_6_part_1_aoc_2025 + +go 1.25.1 + +require github.com/stretchr/testify v1.11.1 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/2025/day_6/part_1/go.sum b/2025/day_6/part_1/go.sum new file mode 100644 index 0000000..c4c1710 --- /dev/null +++ b/2025/day_6/part_1/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/2025/day_6/input.txt b/2025/day_6/part_1/input.txt similarity index 100% rename from 2025/day_6/input.txt rename to 2025/day_6/part_1/input.txt diff --git a/2025/day_6/main.go b/2025/day_6/part_1/main.go similarity index 88% rename from 2025/day_6/main.go rename to 2025/day_6/part_1/main.go index 280154c..3204d36 100644 --- a/2025/day_6/main.go +++ b/2025/day_6/part_1/main.go @@ -1,8 +1,8 @@ package main import ( - "day_6_aoc_2025/expression" - "day_6_aoc_2025/state" + "day_6_part_1_aoc_2025/expression" + "day_6_part_1_aoc_2025/state" "log" shared "shared_aoc_2025" ) @@ -27,7 +27,7 @@ func main() { total += exp.Evaluate() } log.Printf("total: %d", total) - }), shared.WithNewlineCallback(func() { + }), shared.WithNewlineCallback(func(si shared.StreamInfo) { if !s.CurrentOperand().IsEmpty() { log.Println("not empty") } @@ -42,7 +42,7 @@ func AddToExpression(s *state.State, si shared.StreamInfo) { if currentOperand.IsEmpty() { return } - if si.Line == 1 { + if si.LineNumber == 1 { exp := expression.NewExpression() op := currentOperand.Build() exp.AppendOperand(op) diff --git a/2025/day_6/state/state.go b/2025/day_6/part_1/state/state.go similarity index 95% rename from 2025/day_6/state/state.go rename to 2025/day_6/part_1/state/state.go index c60ec45..edd57f5 100644 --- a/2025/day_6/state/state.go +++ b/2025/day_6/part_1/state/state.go @@ -1,6 +1,6 @@ package state -import "day_6_aoc_2025/expression" +import "day_6_part_1_aoc_2025/expression" type State struct { expressions []*expression.Expression diff --git a/2025/day_6/part_2/go.mod b/2025/day_6/part_2/go.mod new file mode 100644 index 0000000..dcaec0c --- /dev/null +++ b/2025/day_6/part_2/go.mod @@ -0,0 +1,3 @@ +module day_6_part_2_aoc_2025 + +go 1.25.1 diff --git a/2025/day_6/part_2/input.txt b/2025/day_6/part_2/input.txt new file mode 100644 index 0000000..e1fc635 --- /dev/null +++ b/2025/day_6/part_2/input.txt @@ -0,0 +1,5 @@ +8 626 55 6 83 532 29 19 4 878 6 684 97 33 72 858 9 9 97 6 91 67 41 129 992 81 19 7 693 621 413 63 5918 4 838 1 2 65 521 78 52 5 547 792 87 44 1 98 2176 8865 9 29 185 74 7 64 32 96 5 27 6221 989 398 16 86 53 76 789 363 58 17 56 287 25 9 275 67 43 89 4 4 711 83 4 786 6 68 53 594 24 82 84 597 34 43 3 83 489 41 2 532 68 963 16 74 59 78 95 91 73 63 4 773 29 761 69 527 237 3 554 967 8 9 46 14 79 192 88 49 7 727 8 9153 8 989 83 88 33 7657 5 56 479 8 886 954 47 592 9 691 86 14 63 34 89 7 8 6 19 625 66 1 92 132 151 12 59 657 51 3726 33 1417 2 38 7 57 238 729 39 39 38 34 23 21 69 949 49 89 28 552 98 435 655 86 6 5 82 41 416 97 2244 19 36 93 15 33 57 26 3 27 2758 11 1 17 1391 1 611 57 88 21 64 63 17 5 261 633 22 14 127 4 62 8 133 592 7138 34 732 46 1 37 43 5 84 71 29 4 35 32 5 96 5 685 48 99 4 36 92 84 94 928 1 31 1 5 35 23 578 8 3 7331 53 3 22 856 91 5 958 79 34 42 1 39 96 47 73 2736 85 9 4 78 82 798 864 91 85 9 988 15 662 44 7 7 93 41 396 4 56 73 231 2 54 18 51 25 46 2 82 16 724 7269 72 97 57 45 792 2 51 45 35 783 9572 4178 98 83 51 7 674 9 95 74 33 735 17 6 82 8268 32 14 388 6 8 4 27 329 3815 982 78 74 861 56 9969 895 9 78 161 5 55 24 676 687 239 93 93 214 63 8325 89 37 1 21 4 594 6 1 658 22 7 371 7593 753 13 212 361 93 461 63 1 73 53 646 9 6 71 3443 851 79 94 42 19 659 34 327 98 368 9 537 6 435 84 8791 437 26 55 74 416 378 67 1686 49 1 3 38 19 57 9 87 229 3 546 36 2234 148 45 444 64 9 4393 45 72 57 53 1 11 869 85 1 99 27 955 4797 3447 82 64 67 319 666 2542 16 11 163 74 38 21 517 34 93 89 852 6521 1 71 477 11 5832 2 377 9865 1917 69 125 5 9 761 9 8 4 827 333 8 93 37 37 1 79 347 4 386 1 56 8 4 747 3 4924 599 57 3 89 2 59 34 629 525 4 3 7 954 13 3 865 342 84 94 84 81 349 893 67 1 865 677 245 91 9999 1 252 5671 98 351 8 7 69 97 9 9199 15 32 815 212 586 97 668 67 827 41 4 2 68 54 185 3 61 3 9 14 568 43 4 635 75 243 45 7555 7 5 6 97 61 47 138 881 22 7 6 82 29 79 371 467 775 1 6 65 26 99 13 1 1973 894 5 4 3 344 13 282 38 41 549 6863 21 67 33 27 823 7 543 95 83 6 42 95 19 3474 7397 5 44 67 86 89 4 69 38 88 51 872 51 782 185 2 268 171 41 6677 1 881 883 72 4291 6 42 57 87 67 649 789 617 1 962 68 96 881 46 5181 767 11 36 34 6 34 93 25 987 45 93 25 4683 312 3 14 52 15 68 94 7 1 4 1 76 333 37 51 547 742 993 51 77 692 3 62 5 52 5559 4178 941 99 47 18 6 1 26 47 2 99 66 264 97 51 87 4 2 99 74 799 715 1974 8 5 44 7 63 7 15 7 2358 263 85 83 228 3 75 7 153 23 6 22 611 547 73 7 9 16 86 63 765 626 7 22 598 165 27 632 72 82 16 85 7686 29 124 1 8146 1 9 253 2 353 6 837 488 491 222 245 59 1 688 451 82 4 486 78 19 4 89 334 494 189 983 31 6 76 58 6 88 24 94 36 7965 863 62 392 19 74 4 9917 487 3 139 9 94 544 68 25 98 3 9 2 13 45 38 677 73 648 633 58 5 4 35 71 6136 64 1646 82 732 1 73 1 429 53 779 7 248 48 351 3 55 97 2 8 643 993 34 67 538 4115 48 7 9 44 21 742 1 976 1 6 3847 18 94 1 447 47 4674 75 63 236 86 741 14 26 84 8 74 54 12 78 11 715 71 17 45 3 451 986 364 649 68 83 57 757 3 4 928 95 72 92 27 6 9 29 17 2863 877 323 428 188 1975 27 69 1 25 8 89 7 22 62 4 8 484 639 729 76 373 7 4 2 654 75 55 83 91 123 46 454 293 6 486 311 53 273 11 25 71 981 6 196 31 9 78 7 2 755 58 55 33 883 7 12 9 7677 5658 88 38 88 67 22 446 2 68 1 8 6 8621 4 +752 333 21 2 753 233 88 141 2124 619 4 946 367 17 93 795 77 646 625 3 9 94 38 435 53 1637 39 3 81 434 318 73 6556 667 112 26 5 528 788 88 32 3 798 317 37 82 6 81 5486 8221 12 5694 18 22 15 72 6 49 88 96 4553 992 984 99 91 84 21 429 911 558 19 67 7 886 56 748 88 43 65 95 1 653 97 67 578 8 49 632 225 49 41 22 7296 7329 36 8 279 679 37 2 686 44 822 17 25 535 68 348 47 29 287 14 712 36 367 843 862 6837 42 673 74 7 945 11 99 2 811 53 74 544 439 614 1393 53 9826 59 721 57 4987 1 99 461 7 54 947 84 553 4 251 91 21 976 95 75 82 4 49 47 251 41 96 53 556 281 95 24 626 294 9898 93 721 449 94 7 88 314 842 64 569 38 55 33 46 557 224 71 58 255 985 15 399 32 12 12 6 24 124 727 32 5816 51 24 58 328 11 57 1 6 12 8482 51 5 43 9663 5 875 46 98 58 54 27 3646 4 434 534 82 3 442 86 11 72 8482 733 7782 75 693 56 78 42 482 54 91 12 71 189 57 282 79 96 3 637 634 9 362 82 89 91 215 896 8 3595 2 798 87 28 397 9 7 8689 7193 6 41 736 72 27 78 421 726 22 9 66 35 98 89 3633 95 94 5 646 89 985 889 45 915 12 973 938 243 96 24 8 2221 25 565 268 66 258 441 33 983 12 28 27 58 6 49 37 528 2422 25 422 74 21 925 7 278 48 68 514 9438 395 44 52 417 14 594 27 99 34 44 576 92 78 84 618 42 41 448 66 3 1 417 233 3582 47 584 44 133 861 8127 792 4 91 518 3 73 489 927 839 326 81 93 271 65 7632 258 35 33 94 195 617 3 54 528 93 5 941 231 454 42 7 884 72 669 16 7195 947 51 429 1 89 64 973 874 34 217 21 995 533 584 736 64 27 4 642 3 747 28 1778 142 43 296 222 817 618 24 692 53 6 2 38 54 74 7 889 225 45 422 44 5138 172 49 7237 32 54 891 41 49 965 87 8 81 193 9 28 56 37 539 7528 275 92 94 43 823 351 2965 19 852 183 965 38 89 9198 87 64 2 867 6936 7 45 434 29 875 415 3852 7896 39 25 83 648 28 692 926 4112 5 743 432 8 77 477 3399 9 62 127 486 216 5 38 4 688 781 77 2282 2422 62 165 44 4 39 29 475 875 8 1 7 379 13 937 653 995 86 13 56 51 228 991 37 85 11 897 898 92 3153 13 518 8736 8 284 443 14 42 94 63 516 55 187 665 595 881 61 918 51 53 269 1 777 62 9 778 18 98 68 1 42 782 471 13 973 31 113 73 7525 294 4 384 437 64 77 386 522 95 9 43 23 58 56 292 456 483 76 67 89 43 23 48 3 3168 19 78 5 2 733 38 987 52 412 823 5168 21 18 35 43 944 974 239 71 793 127 84 55 79 8552 8568 887 78 58 51 789 54 169 13 45 91 73 89 141 229 21 855 123 351 245 8 998 421 43 766 32 24 28 78 94 684 318 966 3 57 264 44 991 886 4524 933 63 46 88 47 49 64 32 274 518 21 62 2374 5553 13 33 82 94 87 57 9 1 11 56 54 645 45 53 371 273 184 56 92 731 5 68 5 3573 7491 2353 856 33 86 161 8 57 31 99 3 34 72 561 44 94 13 64 89 21 39 381 891 6483 36 96 313 1 38 78 122 8 4928 221 77 37 945 25 895 86 519 86 86 19 543 635 729 4 52 189 361 54 163 637 78 32 851 738 63 211 492 39 85 97 8585 311 249 77 8621 51 74 49 693 181 313 844 947 431 995 368 774 46 895 7848 91 159 94 83 44 45 47 363 717 769 884 38 1 31 85 7 89 51 79 37 8425 87 49 98 43 14 33 943 237 25 241 465 54 475 921 98 69 48 47 15 18 64 294 599 48 892 725 35 776 6 28 24 7373 74 1331 5 294 9 75 39 491 8 956 39 76 46 343 17 66 71 16 1 782 137 958 84 725 5841 43 54 955 161 81 475 13 345 6 15 3169 99 245 7 69 45 8466 13 96 944 96 986 68 57 73 9 14 38 17 53 74 195 353 388 785 56 374 311 721 856 98 53 484 433 827 94 261 83 484 39 669 854 6836 23 786 58 274 469 833 314 646 295 42 25 61 1417 78 97 884 68 11 12 284 777 616 26 317 3 88 99 825 15 991 93 669 855 87 287 312 212 78 841 78 9 143 44 29 723 6 699 12 8 2 81 57 893 52 19 87 393 42 22 353 2244 5313 73 61 25 6691 89 817 81 11 511 7 58 3732 242 +682 83 3 163 521 989 68 564 5337 356 82 238 242 88 495 775 96 868 753 67 9 4 43 2881 1 1952 76 13 11 29 644 36 323 367 64 69 82 349 629 88 23 3 545 363 22 92 1 97 739 3795 651 6252 11 47 52 89 2 84 48 21 416 54 393 22 546 627 77 315 868 661 92 26 7 179 97 832 45 5 582 21 948 441 76 499 771 26 28 852 219 13 98 22 4796 9858 86 52 614 234 96 56 824 556 889 812 74 384 34 456 56 43 848 62 547 39 716 835 134 5527 34 883 74 9 448 58 17 5 23 92 49 3342 656 973 8632 83 8266 95 471 76 572 1 64 314 94 27 817 52 339 48 537 99 76 8434 42 11 42 64 75 28 135 19 325 6 158 56 72 29 87 4168 397 73 13 585 835 27 45 84 778 55 115 93 65 27 18 214 289 355 67 996 33 17 42 2 3 28 57 44 643 415 226 1611 13 17 27 955 22 18 9 17 39 6283 89 87 61 8221 63 421 79 8 15 35 57 8428 29 98 83 77 8 967 839 15 81 6784 552 6143 38 69 56 77 64 242 733 58 6 82 856 28 155 45 29 17 711 431 8 346 19 611 13 922 41 27 5859 67 316 8 4 447 41 82 8498 4343 34 25 58 98 334 93 349 7572 81 2 74 98 51 78 1883 2 23 54 2944 11 4 142 13 9534 48 6223 557 95 68 84 296 8954 13 15 457 59 6455 67 53 172 96 58 993 63 484 62 91 4 3648 3 792 95 79 582 5 512 35 53 545 2256 13 89 18 165 58 965 266 83 1 515 373 83 25 67 258 82 6 612 571 6 73 6168 82 9899 34 283 71 71 162 981 31 69 56 146 539 94 914 246 868 778 54 1 9 66 5628 453 72 82 53 8349 725 132 18 95 54 41 12 145 868 88 3 51 7 77 8 4523 962 37 413 84 43 22 783 954 44 728 46 395 87 476 7475 36 15 6 451 8 443 3 5798 32 15 193 267 466 17 2 47 84 89 74 833 63 234 69 123 471 21 937 94 5465 692 98 4216 32 35 255 59 27 959 46 88 3 835 9 53 49 26 255 8279 63 55 5 47 29 256 887 1 867 62 843 31 11 3681 49 58 6 935 963 36 57 436 31 785 2953 2424 7126 6 26 52 8759 68 245 559 2744 32 418 86 56 48 651 8913 1 941 173 531 9 89 8 64 183 195 78 4341 8133 12 634 17 46 3 72 946 499 32 979 21 726 76 462 592 34 57 37 73 2 394 851 93 46 35 847 174 52 7222 52 93 3524 2 624 9224 55 53 459 71 338 48 7282 22 275 29 91 23 1 4 831 49 7413 91 6 235 964 23 75 5 24 998 594 58 867 89 94 47 85 629 6 593 725 92 94 77 565 9 8 479 72 57 8 62 757 25 72 671 96 27 15 21 75 1369 35 636 52 1 17 13 59 52 621 47 857 98 89 77 44 343 282 6895 16 596 957 38 35 46 2834 1394 695 87 28 39 234 9858 784 55 47 73 2 63 55 159 41 333 564 471 299 37 23 46 96 169 43 82 41 29 92 977 114 496 17 3 7355 817 49 2137 741 73 21 33 5 23 15 38 1 736 888 65 4 52 3973 28 953 22 52 871 36 98 96 724 551 821 832 5991 89 246 95 16 43 13 43 5155 37 74 3853 5519 5137 675 5 55 432 54 25 91 43 841 833 85 396 81 6 855 81 634 75 98 159 3947 89 36 72 921 34 51 6224 885 354 117 637 38 16 729 86 724 1986 735 57 39 12 154 839 458 4 31 899 931 7 537 884 98 265 229 612 16 473 959 85 21 38 196 713 85 269 836 22 374 28 315 2 782 492 249 394 9 821 496 9767 793 4962 25 928 29 36 3 43 75 455 746 73 691 19 7 92 94 916 76 56 89 66 1155 6 471 17 924 97 69 247 271 36 537 554 3 8634 876 3 68 73 39 15 24 78 427 594 25 36 252 28 273 9 13 431 55 11 8656 8 895 49 45 51 372 8 826 296 43 13 91 83 98 8 158 3 848 421 885 46 761 2842 35 538 343 149 76 889 82 744 94 91 4675 65 381 66 94 28 9836 26 899 848 41 74 58 379 15 9 64 46 531 3 69 76 9153 827 327 57 44 776 831 948 88 89 931 415 827 58 579 41 469 29 511 154 4678 4 568 28 912 64 24 134 714 837 69 14 99 6314 73 22 358 1 43 411 2593 646 471 31 997 6 81 64 73 74 6261 39 414 376 73 42 35 4849 34 4 55 8 279 28 61 423 8 95 6 82 3 58 211 473 29 97 78 438 424 53 483 376 2115 54 97 87 4985 31 318 11 814 977 614 44 346 8515 +776 13 9 7747 591 8353 319 916 5431 847 54 89 754 47 392 511 16 995 391 78 3 6 46 5423 1 4332 6 32 52 59 922 6 785 326 61 36 17 687 16 9 8 845 9 84 9 99 57 7 361 6692 922 9617 4 82 67 2 5 27 714 49 1 39 679 27 592 913 23 766 638 589 9 19 2 798 99 243 35 7 456 61 442 53 61 528 164 86 41 482 57 32 62 35 7791 2839 9 27 774 765 7 36 98 741 323 276 6 664 77 239 94 28 423 96 5 27 31 284 49 3723 424 73 5 42 266 2 2 1 46 9 13 8636 46 288 6761 43 5184 26 929 94 1 86 7 24 84 62 29 82 568 86 183 66 424 9761 5 82 92 56 72 27 316 12 832 4 664 2 69 89 69 3493 81 86 47 941 888 27 48 82 4 81 666 2 26 11 76 462 217 383 76 666 11 18 2 3 5 73 58 3 385 78 914 9177 25 49 23 512 35 45 9 21 844 127 42 97 7 3257 74 83 87 7 29 35 6 4613 684 9 16 77 1 39 695 17 66 3166 354 623 92 1 5 76 72 998 369 9 2 19 548 46 481 76 78 49 215 165 7 777 78 768 91 626 61 62 9394 79 377 6 5 684 53 27 82 4664 87 85 1 7 593 2 199 8551 38 84 87 4 71 6 9996 6 13 71 7122 79 2 712 3 7241 64 8991 767 15 43 755 6224 3451 91 62 877 3 4311 63 23 229 8 34 378 2 158 38 24 5 652 4 625 474 26 978 73 837 7 88 854 8376 38 92 3 862 17 744 351 285 9 564 169 813 48 818 41 33 7 643 296 17 591 4955 71 5873 61 9823 98 72 971 98 8 99 3 74 613 96 154 71 842 896 52 5 9 57 7158 656 5 91 39 9858 39 739 57 5 69 48 8 45 858 69 1 6 3 74 2 3514 162 72 817 64 34 49 12 69 9 256 5 414 27 352 1446 89 47 67 5668 96 657 9 947 72 24 547 368 645 2 7 1 136 53 21 772 6 233 11 433 75 23 16 87 8 8 74 5594 29 64 6 13 82 646 3 37 4 389 2 73 91 84 17 7418 15 67 1 41 1 24 223 8 522 21 521 4 54 1251 9 38 3 99 643 538 68 783 55 3 2367 6626 482 3 913 17 6258 714 286 583 7753 56 194 18 68 92 432 2248 96 746 46 9812 3 18 9 95 772 13 71 3992 6683 86 691 19 22 1 2 7577 9 78 817 57 2 257 361 12 6 5 44 4 4 238 766 59 49 52 48 4 84 7964 28 2 463 7 852 1426 31 9 535 22 9 31 4835 5 263 61 96 12 2 6 283 682 1257 1 9 3 495 9 33 87 23 825 4797 22 696 4 32 3 81 431 18 6144 734 24 293 7 273 3 18 7712 64 19 2 9 387 72 492 484 11 55 74 21 21 326 68 441 27 25 1 94 67 31 462 28 6 6 53 6 6 691 162 2422 38 848 755 2 45 9 98 3376 815 1 63 21 432 1449 978 5 55 9 4 2 29 888 52 936 67 411 118 52 6 1 4 5 13 75 19 3 51 8 121 82 32 3 9355 411 11 8696 83 22 1 47 7 841 8 42 9 982 114 5 3 6 6465 66 281 1 23 986 73 86 77 359 674 131 335 3343 33 21 3 6 7 53 98 8234 336 47 6279 5884 43 112 1 63 696 75 56 15 82 623 361 93 185 5 4 955 61 789 2 84 73 3217 5 62 13 187 81 3 3663 354 367 494 521 45 34 411 44 869 3541 77 43 44 49 95 931 528 88 69 293 899 4 226 775 63 552 622 6 11 97 299 9 39 77 94 118 5 745 631 93 226 41 499 9 479 8 53 257 2 779 196 5133 86 2446 94 325 6 1 1 73 19 876 94 22 657 753 23 58 79 592 9 36 48 55 92 8 627 29 281 52 51 47 365 15 81 968 9 8157 232 4 13 43 19 54 6 94 148 393 3 5 99 23 513 283 99 6851 92 69 498 7 56 28 9 91 61 4 187 432 71 73 84 79 73 8 323 78 556 825 363 94 8742 4619 41 746 761 916 77 376 44 113 99 64 288 44 116 56 9 8 46 5 355 219 97 96 83 3317 65 71 63 1 741 4 64 68 1453 716 982 61 92 5165 58 955 54 46 359 921 453 98 41 2 487 87 546 553 9771 4 314 9 284 47 4 78 343 684 97 69 8 2577 5 21 216 1 54 693 9598 82 89 72 75 81 55 82 1 31 3337 32 135 626 48 2 3 5793 6 7 49 3 612 53 4 4 37 12 2 44 7 16 992 3 1 7 21 327 193 1 683 7 174 47 2 43 9837 63 5614 25 851 594 695 14 797 9136 ++ * * + * + + * + * + + * * + * * * * * + + * + * + + * + + * + + * * * + + * * * * * + * + * * + + * + + * * * * + + * + + * * + * * * * * + * * * * * * * * * + + + * + * * * + * * * + + * * * * * * + * * + * + * + * * + * * * + * * + * + * * + + * + * * * + * * + * + * + + + + + * * * + * + * * * + + + * + + * * * * + + + + + * * + + + + + * * * * + * + * * * * * * + + * * + * + * * + * * * + + * + + + * * * * * + + * * + * * + + * * + + * * * * + + * * + + * + * * * * + * * * * + + * * * * + + + + + * + * + + * + * * + * * * + + + + * * * * + * + * + * * + * + + * + + + * * + + * + * * * * + + * + + + + * * * + * + * + * * * + + + + * + + * + * * + + * + * * + + * + * + * * * + * + * + + * + * + + + * + * + + * * * * + + + * * + + * * + * * * + + * * * * * * * + * * * * + + * + * + + + * + + + + * * * * * + * * * + * * + + * + + + * + * + + * * * * + * + * * * * + + * + + * + * + * + * * * * * * + + + + + * + + * + + * * + * + + * + * + + + + * * + + + + + * + + * * * + * * * * * + + * + + + * + + * * + * + + * * * * * * + * * * * * * * + * * + + * * * * * * + * + + + * + + + + * * * * + * + + + + + * * + + + + * * + * * * + + * + * * * * * + * * + + + * * + * * + * + * * + * + * * + + * * + * * * + * * + + * + + * * + * * + + * * * + + * + + + + + * + + * + * + * * + * + * * * + * + * + + * * + + * * * + * + + * * + + * * * * * * * + * * * + + + + + * + + * * + * + * + + + * * + + + * + + * + + + + * * + + * * + + + * * + * + + * + * * + + + * + + + + * * + + * * + * + + * * + + * * * + * + * + + + + * * + * + * * * + + * * + + * + * * * + + * * + * * + + + * * + + + + + * * + + * * * + * * + * * + * * * + * * + + + * + * + * * + + + * + * * + * * + * * * + + + * + * * * + + * + * * + * * * * * * * * * * + + + * * * * + * * * * * + * * * * * + * * * * * + + * * * * + * * + + * * * * + + * * * * * * * * * * * * + + * * + * * + + + * * * * + * * * + * * + + * + + * + * * * + + + * * * * + * + * + * * * + + * + * * * * * + * * * * + * + + + * * + * + * + * * * + + diff --git a/2025/day_6/part_2/main.go b/2025/day_6/part_2/main.go new file mode 100644 index 0000000..444ed2d --- /dev/null +++ b/2025/day_6/part_2/main.go @@ -0,0 +1,27 @@ +package main + +import ( + //"day_6_part_2_aoc_2025/state" + "log" + shared "shared_aoc_2025" +) + +func main() { + //s := state.New() + shared.StreamProcess("test.txt", func(si shared.StreamInfo) { + switch si.R { + case '+', '-', '*', '/': + case ' ': + default: + } + }, shared.WithEOFCallback(func() { + total := 0 + log.Printf("total: %d", total) + }), shared.WithNewlineCallback(func(si shared.StreamInfo) { + + }), shared.WithCRCallback(func(si shared.StreamInfo) { + + })) +} + +// 7098065460541 -- correct diff --git a/2025/day_6/part_2/state/state.go b/2025/day_6/part_2/state/state.go new file mode 100644 index 0000000..424f506 --- /dev/null +++ b/2025/day_6/part_2/state/state.go @@ -0,0 +1,8 @@ +package state + +type State struct { +} + +func New() State { + return State{} +} diff --git a/2025/go.work b/2025/go.work index 570cb6a..b0ec8b1 100644 --- a/2025/go.work +++ b/2025/go.work @@ -6,6 +6,7 @@ use ( ./day_3 ./day_4 ./day_5 - ./day_6 + ./day_6/part_1 + ./day_6/part_2 ./shared ) diff --git a/2025/shared/character.go b/2025/shared/character.go new file mode 100644 index 0000000..a351055 --- /dev/null +++ b/2025/shared/character.go @@ -0,0 +1,17 @@ +package shared + +type Character rune + +const ( + Newline rune = '\n' + CarriageReturn rune = '\r' + Space rune = ' ' +) + +func (c Character) String() string { + return string(c) +} + +func (c Character) Rune() rune { + return rune(c) +} diff --git a/2025/shared/shared.go b/2025/shared/shared.go index 83ac5bb..f908a08 100644 --- a/2025/shared/shared.go +++ b/2025/shared/shared.go @@ -1,133 +1,133 @@ package shared -import ( - "bufio" - "log" - "os" -) - -type Character rune - -func (c Character) String() string { - return string(c) -} - -func (c Character) Rune() rune { - return rune(c) -} - -type StreamInfo struct { - R Character - Line int - LineIndex int - GlobalIndex int - LineRuneArr []rune -} - -func NewEmptyStreamInfo() StreamInfo { - return StreamInfo{} -} - -func NewStreamInfo(r rune, line, lineIndex, globalIndex int) StreamInfo { - return StreamInfo{ - R: Character(r), - Line: line, - LineIndex: lineIndex, - GlobalIndex: globalIndex, - } -} - -func (s StreamInfo) GetLine() string { - return string(s.LineRuneArr) -} - -type StreamProcessConfig struct { - EOFCallback func() // end of file callback - NewlineCallback func() // new line callback - CRCallback func(sctx StreamInfo) // carriage return callback -} - -func NewStreamProcessConfig(opts ...StreamProcessOption) StreamProcessConfig { - cfg := StreamProcessConfig{} - for _, opt := range opts { - opt(&cfg) - } - return cfg -} - -type StreamProcessOption func(*StreamProcessConfig) - -func WithEOFCallback(f func()) StreamProcessOption { - return func(o *StreamProcessConfig) { - o.EOFCallback = f - } -} - -func WithNewlineCallback(f func()) StreamProcessOption { - return func(o *StreamProcessConfig) { - o.NewlineCallback = f - } -} - -func WithCRCallback(f func(sctx StreamInfo)) StreamProcessOption { - return func(o *StreamProcessConfig) { - o.CRCallback = f - } -} - -func StreamProcess(path string, fn func(sctx StreamInfo), opts ...StreamProcessOption) { - if fn == nil { - log.Fatalf("fn cannot be nil") - } - - cfg := NewStreamProcessConfig(opts...) - - file, err := os.Open(path) - if err != nil { - log.Fatalf("failed to open file: %s", err) - } - defer file.Close() - reader := bufio.NewReader(file) - - c := 0 - g := 0 - l := 1 - - sctx := NewEmptyStreamInfo() - - for { - r, _, err := reader.ReadRune() - if err != nil { - if cfg.EOFCallback != nil { - cfg.EOFCallback() - } - break - } - sctx.R = Character(r) - sctx.Line = l - sctx.LineIndex = c - sctx.GlobalIndex = g - if r != '\n' && r != '\r' { - sctx.LineRuneArr = append(sctx.LineRuneArr, r) - } - fn(sctx) - if r == '\r' { - if cfg.CRCallback != nil { - cfg.CRCallback(sctx) - } - } - if r == '\n' { - if cfg.NewlineCallback != nil { - cfg.NewlineCallback() - } - l++ - g++ - c = 0 - sctx.LineRuneArr = []rune{} - continue - } else { - c++ - g++ - } - } -} +// import ( +// "bufio" +// "log" +// "os" +// ) + +// type Character rune + +// func (c Character) String() string { +// return string(c) +// } + +// func (c Character) Rune() rune { +// return rune(c) +// } + +// type StreamInfo struct { +// R Character +// Line int +// LineIndex int +// GlobalIndex int +// LineRuneArr []rune +// } + +// func NewEmptyStreamInfo() StreamInfo { +// return StreamInfo{} +// } + +// func NewStreamInfo(r rune, line, lineIndex, globalIndex int) StreamInfo { +// return StreamInfo{ +// R: Character(r), +// Line: line, +// LineIndex: lineIndex, +// GlobalIndex: globalIndex, +// } +// } + +// func (s StreamInfo) GetLine() string { +// return string(s.LineRuneArr) +// } + +// type StreamProcessConfig struct { +// EOFCallback func() // end of file callback +// NewlineCallback func() // new line callback +// CRCallback func(sctx StreamInfo) // carriage return callback +// } + +// func NewStreamProcessConfig(opts ...StreamProcessOption) StreamProcessConfig { +// cfg := StreamProcessConfig{} +// for _, opt := range opts { +// opt(&cfg) +// } +// return cfg +// } + +// type StreamProcessOption func(*StreamProcessConfig) + +// func WithEOFCallback(f func()) StreamProcessOption { +// return func(o *StreamProcessConfig) { +// o.EOFCallback = f +// } +// } + +// func WithNewlineCallback(f func()) StreamProcessOption { +// return func(o *StreamProcessConfig) { +// o.NewlineCallback = f +// } +// } + +// func WithCRCallback(f func(sctx StreamInfo)) StreamProcessOption { +// return func(o *StreamProcessConfig) { +// o.CRCallback = f +// } +// } + +// func StreamProcess(path string, fn func(sctx StreamInfo), opts ...StreamProcessOption) { +// if fn == nil { +// log.Fatalf("fn cannot be nil") +// } + +// cfg := NewStreamProcessConfig(opts...) + +// file, err := os.Open(path) +// if err != nil { +// log.Fatalf("failed to open file: %s", err) +// } +// defer file.Close() +// reader := bufio.NewReader(file) + +// c := 0 +// g := 0 +// l := 1 + +// sctx := NewEmptyStreamInfo() + +// for { +// r, _, err := reader.ReadRune() +// if err != nil { +// if cfg.EOFCallback != nil { +// cfg.EOFCallback() +// } +// break +// } +// sctx.R = Character(r) +// sctx.Line = l +// sctx.LineIndex = c +// sctx.GlobalIndex = g +// if r != '\n' && r != '\r' { +// sctx.LineRuneArr = append(sctx.LineRuneArr, r) +// } +// fn(sctx) +// if r == '\r' { +// if cfg.CRCallback != nil { +// cfg.CRCallback(sctx) +// } +// } +// if r == '\n' { +// if cfg.NewlineCallback != nil { +// cfg.NewlineCallback() +// } +// l++ +// g++ +// c = 0 +// sctx.LineRuneArr = []rune{} +// continue +// } else { +// c++ +// g++ +// } +// } +// } diff --git a/2025/shared/stream_process.go b/2025/shared/stream_process.go new file mode 100644 index 0000000..7ea2947 --- /dev/null +++ b/2025/shared/stream_process.go @@ -0,0 +1,131 @@ +package shared + +import ( + "bufio" + "log" + "os" +) + +type StreamInfo struct { + R Character + LineNumber int // 1-based line number + LineIndex int // 0-based column in line (excluding newline) + GlobalIndex int // 0-based position in file + LineRuneArr []rune +} + +// GetLine returns the current lines text, as it has been read so-far, as a string. +func (s StreamInfo) GetLine() string { + return string(s.LineRuneArr) +} + +// StreamProcessConfig holds configuration options for StreamProcess. +type StreamProcessConfig struct { + EOFCallback func() + NewlineCallback func(si StreamInfo) + CRCallback func(sctx StreamInfo) +} + +// StreamProcessOption defines a functional option for configuring StreamProcess. +type StreamProcessOption func(*StreamProcessConfig) + +// WithEOFCallback sets a callback function to be called when EOF is reached. +func WithEOFCallback(f func()) StreamProcessOption { + return func(c *StreamProcessConfig) { c.EOFCallback = f } +} + +// WithNewlineCallback sets a callback function to be called when a newline is encountered. +func WithNewlineCallback(f func(si StreamInfo)) StreamProcessOption { + return func(c *StreamProcessConfig) { c.NewlineCallback = f } +} + +// WithCRCallback sets a callback function to be called when a carriage return is encountered. +func WithCRCallback(f func(sctx StreamInfo)) StreamProcessOption { + return func(c *StreamProcessConfig) { c.CRCallback = f } +} + +// StreamProcess reads a file at the given path and processes it character by character, +func StreamProcess(path string, fn func(StreamInfo), opts ...StreamProcessOption) error { + if fn == nil { + log.Fatal("fn cannot be nil") + } + + cfg := StreamProcessConfig{} + for _, opt := range opts { + opt(&cfg) + } + + file, err := os.Open(path) + if err != nil { + return err + } + defer file.Close() + + reader := bufio.NewReader(file) + + line := 1 + col := 0 + globalIdx := 0 + var lineRunes []rune + + for { + r, _, err := reader.ReadRune() + if err != nil { + if err == bufio.ErrBufferFull { + continue + } + if cfg.EOFCallback != nil { + cfg.EOFCallback() + } + if err.Error() == "EOF" { + return nil + } + return err + } + + sctx := StreamInfo{ + R: Character(r), + LineNumber: line, + LineIndex: col, + GlobalIndex: globalIdx, + LineRuneArr: append([]rune(nil), lineRunes...), + } + + if r != CarriageReturn && r != Newline { + fn(sctx) + } + + if r == CarriageReturn { + if cfg.CRCallback != nil { + cfg.CRCallback(sctx) + } + if next, err := reader.Peek(1); err == nil && len(next) == 1 && next[0] == byte(Newline) { + reader.ReadRune() + globalIdx++ + } + if cfg.NewlineCallback != nil { + cfg.NewlineCallback(sctx) + } + line++ + col = 0 + lineRunes = lineRunes[:0] + globalIdx++ + continue + } + + if r == Newline { + if cfg.NewlineCallback != nil { + cfg.NewlineCallback(sctx) + } + line++ + col = 0 + lineRunes = lineRunes[:0] + globalIdx++ + continue + } + + lineRunes = append(lineRunes, r) + col++ + globalIdx++ + } +} From 2ac8b0aa75648cbca8a7f8b3e173292a3ba2394a Mon Sep 17 00:00:00 2001 From: geraldb88 Date: Sun, 28 Dec 2025 22:49:23 -0600 Subject: [PATCH 2/2] trying another approach --- .vscode/launch.json | 10 ++++++- 2025/day_6/part_2/main.go | 50 +++++++++++++++++++++++++++++++++-- 2025/day_6/part_2/operator.go | 43 ++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 2025/day_6/part_2/operator.go diff --git a/.vscode/launch.json b/.vscode/launch.json index 05b5423..5bf0322 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,13 +42,21 @@ "program": "${workspaceFolder}/2025/day_5", }, { - "name": "2025 Day 6", + "name": "2025 Day 6 (part 1)", "type": "go", "request": "launch", "mode": "auto", "cwd": "${workspaceFolder}/2025/day_6", "program": "${workspaceFolder}/2025/day_6", }, + { + "name": "2025 Day 6 (part 2)", + "type": "go", + "request": "launch", + "mode": "auto", + "cwd": "${workspaceFolder}/2025/day_6/part_2", + "program": "${workspaceFolder}/2025/day_6/part_2", + }, { "type": "node", "request": "launch", diff --git a/2025/day_6/part_2/main.go b/2025/day_6/part_2/main.go index 444ed2d..b57b062 100644 --- a/2025/day_6/part_2/main.go +++ b/2025/day_6/part_2/main.go @@ -1,18 +1,64 @@ package main import ( - //"day_6_part_2_aoc_2025/state" "log" shared "shared_aoc_2025" + "strconv" + "strings" +) + +type value struct { + strVal string +} + +// Int converts the value to an integer. +func (v value) Int() int { + strings.TrimSpace(v.strVal) + intVal, err := strconv.Atoi(v.strVal) + if err != nil { + panic(err) + } + return intVal +} + +// IsEmpty checks if the string value is empty. +func (v value) IsEmpty() bool { + return len(strings.Trim(v.strVal, " ")) == 0 +} + +type column struct { + values []value + operation Operator +} + +var ( + columns []column ) func main() { - //s := state.New() + cv := value{} + colIdx := 0 shared.StreamProcess("test.txt", func(si shared.StreamInfo) { switch si.R { case '+', '-', '*', '/': + case '\n', '\r': + cv = value{} + colIdx++ + if colIdx >= len(columns) { + colIdx = 0 + } case ' ': + //cv.strVal += si.R.String() + if si.LineNumber == 1 { + //if !cv.IsEmpty() { + columns = append(columns, column{ + values: []value{cv}, + }) + //} + } + cv = value{} default: + cv.strVal += si.R.String() } }, shared.WithEOFCallback(func() { total := 0 diff --git a/2025/day_6/part_2/operator.go b/2025/day_6/part_2/operator.go new file mode 100644 index 0000000..576dc33 --- /dev/null +++ b/2025/day_6/part_2/operator.go @@ -0,0 +1,43 @@ +package main + +import "fmt" + +type Operator int + +const ( + None Operator = iota + Add + Subtract + Multiply + Divide +) + +func OperatorFromRune(r rune) Operator { + switch r { + case '+': + return Add + case '-': + return Subtract + case '*': + return Multiply + case '/': + return Divide + default: + panic(fmt.Sprintf("operator not supported: %c", r)) + } +} + +func (o Operator) String() string { + switch o { + case Add: + return "+" + case Subtract: + return "-" + case Multiply: + return "x" + case Divide: + return "/" + default: + return "None" + } +}