From dc284b7f47c5eff0871e6a9ed6bc15fad4c00255 Mon Sep 17 00:00:00 2001 From: Allan Eising Date: Sun, 1 Dec 2024 17:41:25 +0100 Subject: [PATCH] Initial commit --- .gitignore | 60 +++ README.org | 2 + days/day1/README.org | 106 ++++ days/day1/day1.go | 142 ++++++ days/day1/day1_test.go | 65 +++ days/day1/example.txt | 6 + days/day1/test_input.txt | 1000 ++++++++++++++++++++++++++++++++++++++ go.mod | 3 + main.go | 35 ++ 9 files changed, 1419 insertions(+) create mode 100644 .gitignore create mode 100644 README.org create mode 100644 days/day1/README.org create mode 100644 days/day1/day1.go create mode 100644 days/day1/day1_test.go create mode 100644 days/day1/example.txt create mode 100644 days/day1/test_input.txt create mode 100644 go.mod create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e34a680 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Created by https://www.toptal.com/developers/gitignore/api/go,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=go,macos + +### Go ### +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +# End of https://www.toptal.com/developers/gitignore/api/go,macos diff --git a/README.org b/README.org new file mode 100644 index 0000000..e2bd495 --- /dev/null +++ b/README.org @@ -0,0 +1,2 @@ +#+title: Readme + diff --git a/days/day1/README.org b/days/day1/README.org new file mode 100644 index 0000000..e2a3ec8 --- /dev/null +++ b/days/day1/README.org @@ -0,0 +1,106 @@ +#+title: December First challenge - Historian Hysteria + +* Blurb +The *Chief Historian* is always present for the big Christmas sleigh launch, but +nobody has seen him in months! Last anyone heard, he was visiting locations that +are historically significant to the North Pole; a group of Senior Historians has +asked you to accompany them as they check the places they think he was most +likely to visit. + +As each location is checked, they will mark it on their list with a *star*. They +figure the Chief Historian must be in one of the first fifty places they'll +look, so in order to save Christmas, you need to help them get fifty stars on +their list before Santa takes off on December 25th. + +Collect stars by solving puzzles. Two puzzles will be made available on each day +in the Advent calendar; the second puzzle is unlocked when you complete the +first. Each puzzle grants one star. Good luck! + +You haven't even left yet and the group of Elvish Senior Historians has already +hit a problem: their list of locations to check is currently empty. Eventually, +someone decides that the best place to check first would be the Chief +Historian's office. + +Upon pouring into the office, everyone confirms that the Chief Historian is +indeed nowhere to be found. Instead, the Elves discover an assortment of notes +and lists of historically significant locations! This seems to be the planning +the Chief Historian was doing before he left. Perhaps these notes can be used to +determine which locations to search? + +Throughout the Chief's office, the historically significant locations are listed +not by name but by a unique number called the location ID. To make sure they +don't miss anything, The Historians split into two groups, each searching the +office and trying to create their own complete list of location IDs. + +There's just one problem: by holding the two lists up side by side (your puzzle +input), it quickly becomes clear that the lists aren't very similar. Maybe you +can help The Historians reconcile their lists? + +* Example + +#+begin_example +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 +#+end_example + +Maybe the lists are only off by a small amount! To find out, pair up the numbers +and measure how far apart they are. Pair up the *smallest number in the left list* +with *the smallest number in the right list*, then the *second-smallest left number* +with the *second-smallest right number*, and so on. + +Within each pair, figure out *how far apart* the two numbers are; you'll need to +*add up all of those distances*. For example, if you pair up a =3= from the left +list with a =7= from the right list, the distance apart is =4=; if you pair up a =9= +with a =3=, the distance apart is =6=. + +In the example list above, the pairs and distances would be as follows: + ++ The smallest number in the left list is 1, and the smallest number in the right list is 3. The distance between them is 2. ++ The second-smallest number in the left list is 2, and the second-smallest number in the right list is another 3. The distance between them is 1. ++ The third-smallest number in both lists is 3, so the distance between them is 0. ++ The next numbers to pair up are 3 and 4, a distance of 1. ++ The fifth-smallest numbers in each list are 3 and 5, a distance of 2. ++ Finally, the largest number in the left list is 4, while the largest number in the right list is 9; these are a distance 5 apart. ++ To find the total distance between the left list and the right list, add up + the distances between all of the pairs you found. In the example above, this + is 2 + 1 + 0 + 1 + 2 + 5, a total distance of 11! + +Your actual left and right lists contain many location IDs. What is the total distance between your lists? + + +* Part 2 + +Your analysis only confirmed what everyone feared: the two lists of location IDs are indeed very different. + +Or are they? + +The Historians can't agree on which group made the mistakes or how to read most of the Chief's handwriting, but in the commotion you notice an interesting detail: a lot of location IDs appear in both lists! Maybe the other numbers aren't location IDs at all but rather misinterpreted handwriting. + +This time, you'll need to figure out exactly how often each number from the left list appears in the right list. Calculate a total similarity score by adding up each number in the left list after multiplying it by the number of times that number appears in the right list. + +Here are the same example lists again: + + +#+begin_example +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 +#+end_example + +For these example lists, here is the process of finding the similarity score: + ++ The first number in the left list is 3. It appears in the right list three times, so the similarity score increases by 3 * 3 = 9. ++ The second number in the left list is 4. It appears in the right list once, so the similarity score increases by 4 * 1 = 4. ++ The third number in the left list is 2. It does not appear in the right list, so the similarity score does not increase (2 * 0 = 0). ++ The fourth number, 1, also does not appear in the right list. ++ The fifth number, 3, appears in the right list three times; the similarity score increases by 9. ++ The last number, 3, appears in the right list three times; the similarity score again increases by 9. + +So, for these example lists, the similarity score at the end of this process is 31 (9 + 4 + 0 + 0 + 9 + 9). diff --git a/days/day1/day1.go b/days/day1/day1.go new file mode 100644 index 0000000..ffac95d --- /dev/null +++ b/days/day1/day1.go @@ -0,0 +1,142 @@ +package day1 + +import ( + "bufio" + "fmt" + "os" + "slices" + "strconv" + "strings" +) + +func getDistance(x, y int) int { + // Take the distance between two numbers. + // The distance is the difference between the two numbers. + + if x > y { + return (x - y) + + } else { + return (y - x) + + } +} + +func processLine(line string) (int, int, error) { + // Split the line into fields. + fields := strings.Fields(line) + if len(fields) != 2 { + return 0, 0, fmt.Errorf("Expected 2 fields, got %d", len(fields)) + } + num1, err := strconv.Atoi(fields[0]) + if err != nil { + return 0, 0, fmt.Errorf("Failed to parse first number: %w", err) + } + + num2, err := strconv.Atoi(fields[1]) + if err != nil { + return 0, 0, fmt.Errorf("Failed to parse the second number: %w", err) + } + + return num1, num2, nil + +} + +func readDataSet(filename string) ([]int, []int, error) { + file, err := os.Open(filename) + if err != nil { + return nil, nil, err + } + defer file.Close() + + var firstSet, secondSet []int + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := scanner.Text() + num1, num2, err := processLine(line) + if err != nil { + return nil, nil, err + } + firstSet = append(firstSet, num1) + secondSet = append(secondSet, num2) + } + + return firstSet, secondSet, nil +} + +func numFreq(dataset []int) map[int]int { + // Take a slice of numbers and return an array of each number and the amount of times it occurs. + distribution := make(map[int]int) + for _, num := range dataset { + elem, ok := distribution[num] + if ok { + distribution[num] = elem + 1 + } else { + distribution[num] = 1 + } + } + return distribution +} + +func partTwo(filename string) (int, error) { + //Solve part two. + var similarities int + firstSet, secondSet, err := readDataSet(filename) + + if err != nil { + return 0, err + } + + secondDistribution := numFreq(secondSet) + + for _, num := range firstSet { + freq, ok := secondDistribution[num] + if ok { + similarity := num * freq + similarities = similarities + similarity + } + } + + return similarities, nil +} + +func partOne(filename string) (int, error) { + // Solve part one. + + firstSet, secondSet, err := readDataSet(filename) + + if err != nil { + return 0, err + } + slices.Sort(firstSet) + slices.Sort(secondSet) + if len(firstSet) != len(secondSet) { + return 0, fmt.Errorf("Error: Datasets are not the same size. %v != %v", len(firstSet), len(secondSet)) + } + var distances int + for i := 0; i < len(firstSet); i++ { + distance := getDistance(firstSet[i], secondSet[i]) + distances = distances + distance + } + + return distances, nil +} + +func Day1(filename string) { + distances, err := partOne(filename) + if err != nil { + fmt.Printf("Error: %v", err) + os.Exit(1) + } + fmt.Println("-------- PART 1 -------") + fmt.Printf("The total distance is %v\n", distances) + similarities, err := partTwo(filename) + if err != nil { + fmt.Printf("Error: %v", err) + os.Exit(1) + } + + fmt.Println("-------- PART 2 -------") + fmt.Printf("The similarities between the two sets: %v\n", similarities) +} diff --git a/days/day1/day1_test.go b/days/day1/day1_test.go new file mode 100644 index 0000000..0858136 --- /dev/null +++ b/days/day1/day1_test.go @@ -0,0 +1,65 @@ +package day1 + +import "testing" + +func Test_partTwo(t *testing.T) { + type args struct { + filename string + } + tests := []struct { + name string + args args + want int + wantErr bool + }{ + { + name: "Example Part 2", + args: args{filename: "example.txt"}, + want: 31, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := partTwo(tt.args.filename) + if (err != nil) != tt.wantErr { + t.Errorf("partTwo() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("partTwo() = %v, want %v", got, tt.want) + } + }) + } +} + +func Test_partOne(t *testing.T) { + type args struct { + filename string + } + tests := []struct { + name string + args args + want int + wantErr bool + }{ + { + name: "Example Part 1", + args: args{filename: "example.txt"}, + want: 11, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := partOne(tt.args.filename) + if (err != nil) != tt.wantErr { + t.Errorf("partOne() error = %v, wantErr %v", err, tt.wantErr) + return + } + if got != tt.want { + t.Errorf("partOne() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/days/day1/example.txt b/days/day1/example.txt new file mode 100644 index 0000000..b8af9ad --- /dev/null +++ b/days/day1/example.txt @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 diff --git a/days/day1/test_input.txt b/days/day1/test_input.txt new file mode 100644 index 0000000..fd6ff80 --- /dev/null +++ b/days/day1/test_input.txt @@ -0,0 +1,1000 @@ +17633 15737 +79440 47531 +44767 73309 +86871 26386 +66575 90774 +31637 38259 +89855 50198 +81829 20253 +95071 98569 +34163 43719 +28696 84802 +10975 89855 +48232 15737 +14078 99983 +40882 73431 +75659 94769 +85341 13345 +92610 16338 +18043 59463 +60606 24540 +22376 46760 +14535 24785 +26022 94769 +90745 76304 +94386 84190 +22699 50602 +48716 38259 +93599 63674 +24797 57698 +89866 94029 +13841 87991 +12612 31743 +22889 53500 +84705 43272 +50982 26386 +19312 68554 +43985 36005 +23864 99058 +71953 45509 +58611 64279 +15949 98297 +89181 99781 +57095 54781 +19462 82924 +13989 32724 +74037 81607 +98414 34699 +17793 73309 +77332 64279 +17360 75855 +88430 38259 +59633 52523 +93603 31051 +93215 57119 +89750 48853 +73983 31051 +95163 35142 +50441 65929 +66767 72254 +96947 78965 +62870 50159 +46395 76148 +25246 21955 +39127 18070 +69589 72254 +87118 77505 +89577 11697 +64365 17982 +89417 90211 +38259 91050 +14458 32457 +42775 20442 +58228 72254 +87729 30434 +63480 17982 +90234 31051 +19242 94087 +77553 64344 +42962 27509 +20746 70689 +42003 14840 +24751 72254 +98825 66551 +35667 48627 +86088 43388 +87433 12947 +42556 73309 +77443 26386 +85947 66440 +26239 23875 +51904 10613 +45935 55396 +93900 79692 +94769 26138 +89944 29196 +16924 31743 +29441 72254 +31685 52714 +28455 38856 +82408 89991 +50492 79692 +48587 27909 +52190 51936 +14432 26239 +40296 90211 +87571 15975 +68554 82924 +60909 77747 +90581 50216 +17874 89227 +77699 84802 +52227 95383 +81281 38845 +74510 77249 +34913 52738 +17927 11147 +38246 67042 +95559 90562 +97142 94769 +17388 43583 +45933 73309 +61625 92202 +92202 60021 +32609 42173 +10121 15737 +42108 52145 +99781 88040 +71839 52086 +31215 12281 +23028 11321 +45513 36187 +44989 92435 +21042 26664 +41686 53092 +49396 13345 +87383 24542 +57374 94769 +92305 94769 +90956 73220 +59298 60825 +71833 61968 +39322 15153 +90211 98328 +78524 76232 +56222 48717 +88896 42647 +24989 84802 +15618 57610 +40750 15330 +57787 59202 +66076 64279 +27005 46356 +12299 27983 +99606 96968 +78648 88145 +90191 82924 +40731 26599 +28572 32457 +29036 39980 +12210 26664 +72284 11697 +76661 90364 +90125 24914 +42239 14455 +11589 61336 +33000 72254 +10758 31712 +10172 21525 +39561 91482 +47405 95316 +44894 83948 +46926 43967 +59896 87826 +85512 65546 +58641 79692 +83574 57878 +98203 84802 +43633 10581 +47564 69216 +87287 82731 +43747 13345 +91297 79692 +76432 18598 +75790 26386 +93818 96480 +31051 38259 +47511 64279 +97907 22026 +87367 90211 +59976 50541 +52149 99781 +17942 67693 +99139 69460 +66216 49858 +29264 38259 +82924 51350 +66027 25520 +82954 73309 +12290 67322 +20683 93568 +85750 13345 +54662 52685 +79346 31641 +76068 84568 +39015 79773 +30045 19435 +82962 25655 +20148 42108 +67813 29679 +65066 26239 +84222 63931 +13345 59242 +90893 48967 +51707 83112 +42399 15737 +40546 66000 +19343 92202 +95420 14200 +81543 55348 +28417 13345 +57947 91893 +76560 24540 +25531 23044 +60453 50868 +48959 38856 +66180 16455 +16907 83845 +79677 32420 +69680 92202 +65677 32375 +58869 79692 +49481 19672 +81530 26664 +30968 18603 +40003 36218 +70770 89227 +51169 17982 +39585 99781 +41887 90211 +98401 68715 +66079 60199 +79686 17982 +95976 34064 +62505 24540 +66440 31743 +66353 26239 +37729 66440 +78716 84802 +87428 62768 +52512 89855 +86117 84802 +54387 68022 +13759 78689 +40476 66769 +44961 19623 +99372 68799 +89090 79636 +61709 42060 +66586 11972 +68112 33028 +56457 31743 +58500 37748 +49835 52835 +69526 95383 +81736 84802 +72397 80320 +28792 44785 +67973 74969 +28140 79692 +99229 95383 +37502 67333 +21071 32457 +98028 82116 +13892 64667 +64351 19859 +39347 86071 +73309 94769 +25904 31051 +50933 28770 +81957 97102 +53641 15737 +88814 42916 +92575 26239 +62255 54132 +81785 72088 +75349 50602 +83203 89855 +98080 81605 +93942 31743 +97798 57279 +45256 73898 +51544 93706 +25195 88904 +68947 68366 +91830 68022 +91524 54353 +76708 31564 +90123 40095 +86890 21718 +98282 26239 +41961 42868 +11039 12856 +55505 73643 +56720 73309 +50589 35243 +18316 57600 +89706 26386 +77270 26934 +16280 31743 +38856 31317 +38306 72254 +22621 31743 +52085 35952 +25990 17841 +47713 46814 +50171 26239 +68656 30746 +16833 96013 +31650 59611 +38239 93728 +90966 22779 +20522 65624 +74289 88356 +30878 15020 +99343 90211 +46494 46080 +40055 98186 +62089 79296 +27261 11480 +14641 89227 +62672 51003 +43731 67153 +13641 93818 +81157 15737 +38752 93975 +22481 16596 +56161 26876 +11821 15737 +21702 42699 +95781 99704 +96637 61893 +52222 25556 +56805 32457 +43568 31051 +62828 15737 +19567 40953 +49559 25373 +55482 42108 +44986 95412 +53062 52392 +57314 26664 +37016 14626 +63361 92202 +68680 79692 +18476 89101 +20199 21632 +77823 89855 +69738 96520 +67170 40198 +79546 82924 +85110 88431 +54119 46332 +86781 92202 +90311 90211 +57902 82924 +54606 12067 +75696 90211 +31498 77415 +63061 47498 +20426 30513 +77880 79692 +80653 46725 +12847 77929 +67482 73832 +41457 22015 +96070 37125 +26083 87259 +15571 17982 +64763 81999 +69049 22033 +37215 73309 +68721 84808 +41483 43032 +19623 21237 +80415 94769 +40289 47860 +29800 15737 +51573 87470 +95147 93818 +49768 43274 +57896 47996 +11698 31743 +18534 93345 +33315 66184 +93295 26435 +13998 14286 +37866 42108 +27311 91778 +88630 50602 +61311 65732 +58088 54659 +39038 92202 +21263 32457 +68733 26239 +56327 26386 +10831 84802 +41475 14140 +65191 84802 +65689 10408 +99405 76417 +60130 26296 +62835 15737 +43765 25627 +37857 74612 +75626 26698 +82299 39722 +59124 44751 +11662 59626 +13403 38259 +84021 71058 +46515 31743 +19274 99781 +42981 66150 +81200 96138 +28115 52538 +66036 73617 +46632 44785 +44785 45999 +93611 94769 +58202 27856 +83448 31743 +47387 99781 +56227 19962 +10056 90211 +47436 42592 +25614 38259 +91347 94837 +93293 87462 +54018 13345 +93975 24540 +88534 28661 +55107 36119 +90676 30422 +74207 72254 +53544 11697 +82027 50515 +28952 93818 +24039 73309 +51681 59383 +84784 33827 +57727 38856 +17375 79692 +84334 75729 +85913 61227 +34190 70516 +88405 93909 +57014 89855 +49572 51212 +96919 57120 +57074 84802 +97433 94600 +39316 19546 +23267 73309 +49617 62475 +45398 49944 +93789 84802 +80870 79692 +66592 89412 +84914 21538 +15737 58959 +85633 17470 +24299 89227 +50996 28076 +59760 37410 +19853 36303 +87172 63500 +73167 26239 +69533 58203 +10294 47085 +10068 84802 +71528 59133 +90074 48734 +85177 13345 +39240 19623 +46901 31230 +31573 14744 +40287 76713 +52063 31743 +15665 92202 +55652 57799 +94618 43492 +35516 17699 +99836 97684 +12266 93653 +49382 94769 +58480 27713 +30160 95383 +15895 82924 +99570 35771 +86138 29452 +50602 15240 +65863 72856 +14014 17313 +23202 73309 +52442 99781 +98402 62424 +99960 93818 +30587 37482 +27344 71566 +14901 18107 +50646 87619 +39894 82924 +76102 79692 +93553 41109 +95383 19459 +43523 34173 +93147 15737 +52736 86381 +73737 38856 +74670 89855 +70375 44671 +35660 27596 +68216 72680 +87067 46274 +74103 75792 +95109 17982 +17982 92202 +81693 14959 +72925 13345 +79007 26239 +56890 75332 +43163 94330 +89721 89227 +98999 88213 +24385 71775 +31463 68554 +86271 72254 +76927 43416 +82914 88520 +10672 42227 +37107 72254 +53415 65905 +57507 32457 +61956 80596 +53426 42108 +24147 73170 +42957 89855 +82795 66358 +36784 93211 +33334 18704 +81024 79692 +50757 87305 +11023 19777 +56827 91998 +63122 72254 +22187 93663 +45790 24392 +45455 25374 +18321 90211 +50449 42108 +88021 45580 +49799 13345 +87225 94769 +97435 26386 +83558 87182 +38550 95383 +33452 13345 +56025 17982 +67783 93390 +84187 48977 +39395 89716 +68418 38259 +52548 89161 +28163 72254 +84823 89227 +31206 15482 +64705 44785 +58401 31743 +95618 38856 +91709 93818 +48005 92202 +76020 82924 +23833 93782 +52831 50653 +85010 31743 +10664 99781 +22411 13783 +43979 31051 +61257 57691 +61520 15737 +48746 88134 +14279 44785 +47898 89855 +93422 88779 +68022 92202 +14459 96167 +89227 40096 +20824 33236 +75208 79692 +49845 41520 +51562 87703 +93302 64917 +92836 95935 +49142 35882 +50653 24538 +70201 17982 +13156 26664 +72511 68022 +25934 38856 +91338 47911 +75287 41621 +15292 17284 +61020 24851 +24871 93818 +69502 32804 +22107 32457 +11069 17982 +90501 32457 +79735 33307 +22407 40613 +56638 73309 +43995 97846 +24346 10698 +19332 64254 +98053 96741 +64279 95856 +35846 80488 +87249 15737 +26693 91433 +23953 37660 +36613 18796 +68547 42108 +29801 84802 +95876 20755 +96850 26239 +69173 21661 +15143 95829 +88911 12796 +85370 24540 +37936 55116 +27252 62202 +52765 68022 +85421 74199 +29524 26239 +50768 66440 +43558 86684 +51533 89797 +52414 88190 +69357 10930 +37499 82866 +51109 73091 +56299 68022 +35287 90211 +24335 31051 +66593 96407 +34510 24540 +59870 24540 +95114 93204 +25535 45844 +77617 36433 +90219 94315 +79862 38856 +23936 94769 +97001 31743 +80515 77665 +79565 73309 +26333 64279 +75467 90211 +76518 59553 +43602 20354 +36813 99477 +43716 27733 +65228 92202 +23719 94557 +27276 37673 +79341 13382 +92730 64279 +13327 26664 +74695 71838 +26891 51076 +27088 98880 +69958 38856 +91806 17982 +85215 82201 +87804 97407 +87074 38259 +91912 67024 +88017 73309 +37176 26386 +86262 52774 +79370 72254 +59531 72254 +87454 61531 +56438 90211 +69511 28232 +56851 38259 +65430 80706 +36077 17982 +25960 94769 +71485 38856 +54398 90211 +28265 28278 +78120 87123 +59446 34818 +26386 89227 +83452 48947 +37184 37978 +61882 68022 +85743 83130 +58108 93975 +88676 91673 +56709 31769 +60790 80223 +13675 30664 +26508 38856 +86384 45096 +11697 51693 +18506 84802 +64140 26386 +72254 73309 +32457 31743 +47880 57178 +28362 66440 +41762 94769 +52860 13501 +76072 37914 +28664 30385 +38694 83674 +77076 73416 +52304 15737 +48805 97201 +79691 84802 +60446 31743 +50527 13345 +57332 73119 +91969 69182 +24540 42108 +52000 10568 +60350 85617 +65954 75315 +77087 26664 +11673 21083 +86822 31308 +46369 94769 +72162 80387 +78984 15737 +86619 94893 +97668 19111 +98988 92336 +82635 29846 +13455 94769 +58975 80353 +25865 16923 +53039 10038 +30768 15737 +12014 14617 +46545 19623 +25611 38259 +68704 97611 +19940 47269 +86483 63673 +57437 51287 +61703 26386 +48018 51102 +67563 66460 +40899 62325 +39500 34475 +54669 11697 +58288 88743 +74372 50602 +78876 81743 +44932 34577 +63464 81249 +83883 68022 +52588 82924 +32785 67603 +50300 78946 +43503 50602 +64904 84802 +76135 68022 +35611 93677 +64841 34132 +10588 30349 +63814 48233 +19013 17210 +80561 64619 +88208 26239 +10576 10445 +99430 92202 +38695 90117 +32677 30805 +28960 72254 +76150 37024 +27997 66440 +25216 38259 +75079 95383 +19640 32457 +87142 24540 +29691 73136 +43608 60367 +37613 29457 +11187 86291 +14208 97616 +85169 89855 +12976 24540 +64222 52066 +10454 14324 +26231 19580 +94650 15737 +58941 89855 +79692 27316 +54692 10285 +63161 69466 +89688 14267 +88077 93568 +81434 41368 +30007 84802 +93568 72254 +38883 73016 +69231 94769 +14633 72555 +22196 79692 +48676 84802 +87546 84802 +87523 24540 +95107 73309 +79211 15737 +55870 89227 +10953 36166 +11083 73309 +21863 36153 +38429 62600 +61106 92358 +97986 93975 +88704 38856 +93825 66535 +29839 40913 +24546 21464 +74178 15737 +42883 94769 +40996 38622 +42992 26664 +71684 42730 +57251 23426 +26664 31743 +68948 73753 +97206 68022 +57843 33400 +49113 13345 +60920 50511 +22678 89227 +72961 78397 +19802 38490 +86087 90211 +89652 66440 +49821 24540 +50537 79692 +73536 24540 +53929 98400 +60918 79692 +99061 49678 +37062 38238 +20934 72875 +67200 34807 +71415 94769 +99026 96883 +31743 14721 +59957 93818 +68759 76158 +41938 17982 +97993 69305 +80420 85851 +46816 93742 +28271 71400 +87923 32457 +67736 36498 +47677 92202 +56483 84724 +90236 79692 +64649 86922 +55425 46497 +12465 17982 +20096 82924 +60707 96546 +60329 73309 +17905 31743 +11135 17982 +29543 94769 +86447 79692 +77740 97091 +94482 84802 +93699 69588 +26097 13450 +98119 79692 +85496 14796 +86244 73309 +96663 59923 +15846 82924 +85935 72254 +27121 75478 +85411 84131 +30273 32457 +20039 82924 +78703 20706 +41844 64465 +68394 44785 +23329 90139 +58675 96125 +71413 93818 +73282 14167 +50904 89227 +85583 65246 +20025 17289 +47996 18160 +29785 31743 +95739 47118 +79616 92202 +88013 76315 +58837 91798 +78955 92642 +70336 26239 +24170 33987 +78256 24257 +10398 26386 +46571 93031 +93997 79692 +10668 45223 +86866 90211 +49014 53649 +69991 92202 +36977 90623 +92324 79031 +95872 13345 +84633 26386 +30462 24540 +32209 85790 +45036 80196 +17978 68976 +87590 50253 +84802 72481 +39492 68554 +35134 63205 +26840 17894 +75937 10487 +20865 70581 +22548 26386 +73301 56010 +55824 85167 +33501 38259 +97678 30745 +89755 41648 +59158 81505 +51201 66440 +31408 92202 +91451 90800 +70921 29799 +19367 13325 +77381 31051 +91572 89049 +77233 26502 +86139 70861 +60708 35871 +78193 26239 +24930 31852 +14024 82528 +64480 82924 +15775 26239 +75694 94769 +85608 73391 +81409 19623 +57211 26386 +94296 59256 +79582 21822 +59998 38856 +68629 13345 +17800 26239 +37775 44785 +70250 28657 +30006 39357 +80597 35930 +22013 93975 +78422 26239 +38548 24540 +86266 72254 +97848 26386 +84347 56506 +81988 28292 +17114 26660 +11319 73380 +41857 13345 +59624 18015 +75476 33080 +19083 13949 +58992 58123 +60891 32063 +30704 28458 +81706 98995 +65022 87326 +80970 46974 +78758 79469 diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..7126c9d --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.eising.cloud/Eising/aoc2024 + +go 1.23.1 diff --git a/main.go b/main.go new file mode 100644 index 0000000..72fa9cb --- /dev/null +++ b/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "flag" + "fmt" + "os" + + "git.eising.cloud/Eising/aoc2024/days/day1" +) + +func main() { + day := flag.Int("day", 1, "Day of the challenge to run (1-24)") + useExample := flag.Bool("exampledata", false, "Load example data instead of actual challenge data.") + + flag.Parse() + + filename := fmt.Sprintf("days/day%d/test_input.txt", *day) + + if *useExample { + filename = fmt.Sprintf("days/day%d/example.txt", *day) + } + + if *day < 1 || *day > 24 { + fmt.Println("That's not very Christmas.") + os.Exit(1) + } + + switch *day { + case 1: + day1.Day1(filename) + default: + fmt.Printf("Solution for day %d is not ready yet.\n", *day) + } + +}