From 2cda84790802f6b161caa9e0fc2f0ea5203f1286 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Mon, 9 Dec 2024 01:33:33 +0100 Subject: [PATCH] Day01 --- Day01/.gitignore | 170 ++++ Day01/go.mod | 3 + Day01/input.json | 2006 ++++++++++++++++++++++++++++++++++++++++++++ Day01/main.go | 18 + Day01/optimized.go | 59 ++ Day01/original.go | 58 ++ 6 files changed, 2314 insertions(+) create mode 100644 Day01/.gitignore create mode 100644 Day01/go.mod create mode 100644 Day01/input.json create mode 100644 Day01/main.go create mode 100644 Day01/optimized.go create mode 100644 Day01/original.go diff --git a/Day01/.gitignore b/Day01/.gitignore new file mode 100644 index 0000000..8a9eb7b --- /dev/null +++ b/Day01/.gitignore @@ -0,0 +1,170 @@ +# Created by https://www.toptal.com/developers/gitignore/api/go,goland+all,jetbrains+all +# Edit at https://www.toptal.com/developers/gitignore?templates=go,goland+all,jetbrains+all + +### 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 + +### GoLand+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### GoLand+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# AWS User-specific + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# SonarLint plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### JetBrains+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + + + +# End of https://www.toptal.com/developers/gitignore/api/go,goland+all,jetbrains+all diff --git a/Day01/go.mod b/Day01/go.mod new file mode 100644 index 0000000..e40b339 --- /dev/null +++ b/Day01/go.mod @@ -0,0 +1,3 @@ +module Day01 + +go 1.23 diff --git a/Day01/input.json b/Day01/input.json new file mode 100644 index 0000000..2046e94 --- /dev/null +++ b/Day01/input.json @@ -0,0 +1,2006 @@ +{ + "list_a": [ + 99006, + 38540, + 18133, + 70780, + 38316, + 61729, + 57462, + 91153, + 76573, + 76155, + 24171, + 10666, + 73383, + 86077, + 40710, + 58326, + 67654, + 64826, + 70235, + 66149, + 24077, + 46497, + 78959, + 49339, + 54141, + 96148, + 60258, + 23099, + 41307, + 65974, + 40769, + 65277, + 20836, + 12863, + 30718, + 65114, + 46146, + 14591, + 99705, + 64713, + 18767, + 50856, + 19757, + 89557, + 54062, + 69386, + 91224, + 68269, + 47118, + 49799, + 42535, + 69994, + 52436, + 24596, + 86843, + 96155, + 25680, + 10905, + 73049, + 35651, + 13185, + 47380, + 11526, + 22640, + 28081, + 91214, + 70299, + 69491, + 14166, + 44639, + 39531, + 29197, + 97941, + 89154, + 74726, + 42065, + 67812, + 17072, + 73245, + 11680, + 68304, + 98762, + 51469, + 93672, + 19665, + 16645, + 58364, + 92331, + 97903, + 86845, + 50676, + 75338, + 87166, + 89047, + 33371, + 90980, + 92511, + 47738, + 81003, + 87425, + 86444, + 24802, + 26115, + 89747, + 46823, + 70790, + 45381, + 71680, + 56603, + 20721, + 54715, + 70245, + 95000, + 61672, + 69277, + 18422, + 89751, + 82454, + 18812, + 12403, + 51380, + 70840, + 56957, + 80981, + 42793, + 40184, + 75791, + 54948, + 25442, + 88023, + 34476, + 73955, + 40956, + 59337, + 84175, + 61172, + 20032, + 11394, + 89416, + 58763, + 71522, + 41390, + 89374, + 45927, + 13265, + 19150, + 82687, + 44626, + 44561, + 97948, + 14766, + 38684, + 74001, + 75864, + 65366, + 53729, + 90293, + 37726, + 70804, + 10158, + 46905, + 71830, + 26957, + 62648, + 16278, + 72223, + 68493, + 63124, + 39953, + 46199, + 51574, + 56997, + 15042, + 29355, + 32667, + 91910, + 45361, + 57209, + 21891, + 69835, + 94443, + 55059, + 15688, + 32147, + 86293, + 34923, + 44962, + 82598, + 40003, + 13023, + 27866, + 67002, + 91012, + 66044, + 33331, + 83739, + 46420, + 94463, + 89002, + 11437, + 22418, + 21411, + 32217, + 88031, + 35905, + 35647, + 51955, + 74030, + 81468, + 43969, + 46194, + 85098, + 19106, + 39507, + 49298, + 46755, + 65761, + 77565, + 99407, + 71358, + 40988, + 15235, + 85560, + 22336, + 30214, + 33528, + 65883, + 28514, + 54235, + 40814, + 30738, + 23352, + 74158, + 74379, + 13703, + 65060, + 98105, + 63511, + 14335, + 95359, + 88133, + 95532, + 51153, + 14718, + 13804, + 91397, + 43643, + 76512, + 64507, + 56558, + 94652, + 80650, + 56524, + 97034, + 78284, + 63253, + 70398, + 20457, + 38983, + 80593, + 32158, + 15099, + 78903, + 62941, + 11803, + 49738, + 27243, + 93339, + 68583, + 46703, + 66461, + 50187, + 15890, + 52412, + 88293, + 44630, + 85179, + 52028, + 84567, + 19950, + 51147, + 34362, + 83960, + 17612, + 44656, + 33483, + 51670, + 96300, + 95240, + 21850, + 52441, + 32254, + 68525, + 74508, + 80323, + 65300, + 24288, + 66066, + 16209, + 29819, + 74036, + 62630, + 34134, + 46966, + 73363, + 95916, + 21327, + 37034, + 80617, + 24686, + 25133, + 93810, + 68870, + 38845, + 41953, + 76876, + 20112, + 91690, + 12865, + 35744, + 49085, + 86030, + 88533, + 43415, + 34986, + 99785, + 91725, + 30670, + 94247, + 96381, + 59252, + 17282, + 45938, + 79072, + 55769, + 78572, + 87331, + 60162, + 71125, + 40031, + 52638, + 44289, + 63865, + 18898, + 95301, + 22055, + 53205, + 28323, + 90363, + 89953, + 73798, + 45863, + 98470, + 71795, + 33778, + 98946, + 21994, + 30707, + 51523, + 71441, + 33909, + 10691, + 29496, + 42230, + 68830, + 79249, + 44218, + 79729, + 32224, + 30279, + 38608, + 45483, + 32047, + 70586, + 76474, + 32742, + 98317, + 42335, + 65316, + 81775, + 96023, + 12721, + 73700, + 79390, + 90694, + 91565, + 86422, + 92810, + 74624, + 68037, + 28396, + 89780, + 30962, + 23460, + 77012, + 21031, + 66950, + 65128, + 28012, + 57394, + 98281, + 77495, + 74936, + 91250, + 91241, + 91314, + 88290, + 20940, + 94073, + 27646, + 60072, + 24487, + 93468, + 34827, + 42629, + 72808, + 67231, + 47920, + 95716, + 14507, + 38335, + 59119, + 27496, + 49592, + 59259, + 14976, + 32138, + 49659, + 11006, + 27301, + 59332, + 91052, + 63614, + 13512, + 85275, + 19247, + 40663, + 92257, + 68520, + 87435, + 59634, + 48762, + 37318, + 49411, + 34658, + 35706, + 93123, + 17924, + 87196, + 57740, + 22830, + 51620, + 75848, + 14772, + 18592, + 66676, + 44102, + 47056, + 86148, + 40518, + 41596, + 78037, + 35795, + 18723, + 93797, + 97671, + 23699, + 97919, + 16785, + 62616, + 15930, + 82441, + 32656, + 77413, + 72752, + 25097, + 19543, + 75318, + 19415, + 20997, + 35202, + 72538, + 44842, + 28326, + 17462, + 42990, + 20421, + 17182, + 49471, + 31823, + 90999, + 52439, + 47746, + 50990, + 26573, + 38712, + 69067, + 36559, + 81690, + 52850, + 82635, + 76405, + 78056, + 77790, + 97566, + 91451, + 30371, + 31553, + 40103, + 96713, + 72241, + 21177, + 36285, + 60819, + 89533, + 52878, + 98899, + 21739, + 52895, + 24760, + 61257, + 59243, + 83626, + 73327, + 89469, + 38452, + 91111, + 19932, + 23814, + 11228, + 90008, + 71262, + 75116, + 21556, + 67613, + 18819, + 16596, + 60189, + 91775, + 82183, + 82671, + 27814, + 56740, + 23120, + 57467, + 46686, + 75851, + 43651, + 97125, + 49136, + 91337, + 94434, + 32403, + 41731, + 27543, + 74801, + 14902, + 99047, + 66749, + 76240, + 72198, + 95888, + 32500, + 86753, + 15649, + 56086, + 15311, + 37803, + 53060, + 51967, + 17354, + 10055, + 34244, + 21231, + 59489, + 13639, + 34062, + 83983, + 93647, + 53687, + 70194, + 98944, + 13991, + 87843, + 74448, + 52799, + 75944, + 42844, + 96272, + 17838, + 26081, + 45724, + 47237, + 21228, + 35856, + 93591, + 61212, + 61062, + 96064, + 75537, + 44059, + 81622, + 50667, + 97084, + 13169, + 57322, + 12130, + 82114, + 54596, + 47748, + 24302, + 39283, + 44310, + 82822, + 79286, + 78155, + 26900, + 97801, + 62797, + 80367, + 52103, + 43130, + 28888, + 73180, + 82035, + 25627, + 10869, + 37552, + 84907, + 34645, + 61338, + 83990, + 11269, + 79295, + 43221, + 86001, + 34108, + 95413, + 19964, + 82521, + 60781, + 57794, + 12298, + 84216, + 36509, + 82594, + 32516, + 50254, + 35816, + 60865, + 61952, + 53399, + 77087, + 96779, + 13853, + 22933, + 58086, + 21436, + 50170, + 86579, + 26267, + 77545, + 43670, + 21175, + 87781, + 52791, + 48617, + 96403, + 67474, + 98932, + 46899, + 79574, + 30104, + 76149, + 70412, + 33000, + 59971, + 88217, + 15130, + 56015, + 54238, + 35684, + 88659, + 40206, + 81346, + 35433, + 84398, + 64460, + 32488, + 77815, + 61406, + 93879, + 33472, + 86621, + 31585, + 92665, + 51965, + 99377, + 20257, + 79455, + 44861, + 94931, + 34821, + 34053, + 35378, + 99445, + 30344, + 68931, + 57795, + 51592, + 52107, + 44792, + 81960, + 93395, + 53268, + 30699, + 44246, + 71363, + 84318, + 50198, + 58232, + 76277, + 22162, + 77444, + 77344, + 84109, + 64076, + 56650, + 69278, + 78847, + 81571, + 44644, + 90621, + 59174, + 43079, + 46349, + 69355, + 67085, + 66194, + 91560, + 96434, + 57896, + 12385, + 13553, + 39494, + 33031, + 84179, + 76823, + 78648, + 49568, + 13913, + 13779, + 19801, + 53472, + 54951, + 78858, + 33043, + 66269, + 69674, + 56156, + 15052, + 74147, + 16337, + 57835, + 35937, + 79379, + 37535, + 48559, + 72941, + 13143, + 98319, + 21984, + 52205, + 37942, + 30925, + 85946, + 29975, + 16606, + 10354, + 43214, + 75801, + 85088, + 23246, + 14264, + 97821, + 90143, + 43233, + 19501, + 62214, + 70520, + 98507, + 57062, + 19520, + 45602, + 22321, + 58654, + 40844, + 99926, + 27878, + 92982, + 24451, + 24960, + 78368, + 73870, + 64409, + 68720, + 84679, + 85561, + 61418, + 23592, + 79447, + 79307, + 43133, + 67547, + 25054, + 18090, + 42348, + 53062, + 12477, + 32590, + 43150, + 90232, + 54157, + 10397, + 40228, + 10069, + 82220, + 51061, + 24569, + 92802, + 21675, + 55904, + 32060, + 99313, + 64724, + 41313, + 92841, + 48903, + 32705, + 29306, + 12758, + 92611, + 37798, + 72934, + 17322, + 31246, + 42506, + 91039, + 41966, + 37154, + 80080, + 25042, + 63465, + 51158, + 71697, + 68447, + 59005, + 72699, + 77876, + 32324, + 80836, + 79063, + 92346, + 98008, + 52358, + 61687, + 19947, + 57697, + 81721, + 46459, + 25740, + 78645, + 80369, + 33120, + 86551, + 79500, + 87802, + 96810, + 63959, + 36968, + 56795, + 12699, + 80955, + 54674, + 89734, + 56820, + 33215, + 51005, + 54487, + 40303, + 89364, + 99804, + 47249, + 13318, + 71579, + 42237, + 10936, + 94920, + 97531, + 55195, + 37609, + 32421, + 86247, + 75761, + 92502, + 24793, + 79928, + 61966, + 54823, + 12390, + 98087, + 28305, + 11694, + 25773, + 10237, + 53818, + 90140, + 16877, + 70440, + 20425, + 31119, + 64934, + 41053, + 59199, + 96208, + 47865, + 72676, + 36328, + 87171, + 33085, + 29549, + 16365, + 21309, + 78146, + 77480, + 33026, + 78593, + 51671, + 24897, + 66982, + 10601, + 90805, + 98801, + 69006, + 87117, + 51999, + 69463, + 79838, + 87352, + 70793, + 65518, + 63083, + 14321, + 71218, + 68794, + 61356, + 29130, + 50008, + 75342, + 22229, + 43553, + 56266, + 26755, + 43604, + 69206, + 83729, + 97816, + 74873, + 96518, + 26091, + 35139, + 77138, + 63035, + 90356, + 64708, + 68272, + 87370, + 81179, + 91200, + 68973, + 44889, + 56893, + 28208, + 16017, + 33656, + 95864, + 85836, + 94113, + 38652, + 59247, + 64534, + 83964, + 15724, + 55105, + 13237, + 34736, + 95583, + 34797, + 47199, + 20631 + ], + "list_b": [ + 28305, + 91683, + 49738, + 13081, + 55879, + 73383, + 59629, + 56589, + 52850, + 36285, + 76277, + 30707, + 93797, + 24033, + 50187, + 65150, + 30707, + 52850, + 11694, + 71125, + 19630, + 93335, + 47746, + 29442, + 95451, + 29849, + 88293, + 57809, + 66225, + 82114, + 84109, + 79459, + 39953, + 96208, + 30707, + 50745, + 36285, + 81775, + 90954, + 86029, + 78959, + 44136, + 47746, + 74726, + 80955, + 30707, + 49972, + 75801, + 94704, + 57324, + 91397, + 50187, + 94924, + 56660, + 95067, + 75541, + 75049, + 30636, + 91039, + 82698, + 61356, + 49738, + 78959, + 17601, + 24121, + 38947, + 56815, + 64519, + 11598, + 11827, + 65456, + 97770, + 39589, + 67313, + 62661, + 57417, + 40982, + 26967, + 20609, + 79249, + 94322, + 25205, + 55108, + 47746, + 81775, + 69048, + 31379, + 50187, + 65233, + 79249, + 93797, + 48071, + 34605, + 94911, + 43535, + 44540, + 54481, + 98087, + 30707, + 53074, + 36285, + 51147, + 76277, + 63773, + 81775, + 54357, + 40553, + 21755, + 12660, + 25637, + 73383, + 32502, + 47746, + 49279, + 80955, + 20285, + 24379, + 81055, + 71141, + 50187, + 52850, + 30006, + 80955, + 75183, + 45433, + 68802, + 61356, + 15120, + 67654, + 11694, + 29242, + 43439, + 31785, + 60125, + 16414, + 79249, + 96208, + 97531, + 73030, + 39442, + 96208, + 29669, + 91039, + 12473, + 75801, + 40228, + 11428, + 49738, + 79249, + 51147, + 15646, + 16481, + 52850, + 40844, + 71125, + 67654, + 52850, + 97531, + 85744, + 95339, + 21771, + 22746, + 30707, + 69687, + 15961, + 84109, + 27071, + 14353, + 61356, + 93853, + 11750, + 83594, + 93797, + 85961, + 81775, + 96117, + 90326, + 42508, + 82114, + 36285, + 91397, + 40228, + 87731, + 88293, + 69781, + 63879, + 23951, + 96035, + 76078, + 81775, + 11694, + 88124, + 77163, + 48243, + 56996, + 40228, + 37353, + 32287, + 11694, + 89879, + 47746, + 15950, + 84109, + 28305, + 13458, + 65548, + 40377, + 74726, + 75864, + 88293, + 82114, + 86085, + 76277, + 81364, + 88422, + 75801, + 78300, + 69583, + 22393, + 75801, + 49738, + 49799, + 82033, + 50187, + 76277, + 47746, + 73396, + 43873, + 49621, + 84109, + 61805, + 88293, + 76277, + 75470, + 24883, + 51147, + 12843, + 82603, + 55075, + 82342, + 61356, + 43253, + 75098, + 62422, + 98736, + 49738, + 47746, + 75864, + 68412, + 50187, + 62259, + 42322, + 75908, + 70538, + 49799, + 17703, + 91039, + 87050, + 60522, + 79249, + 98087, + 13939, + 12907, + 80063, + 11694, + 37998, + 61846, + 79646, + 81203, + 84109, + 76277, + 98087, + 71125, + 65472, + 89208, + 55747, + 97531, + 81775, + 52513, + 72857, + 65290, + 91039, + 35257, + 86932, + 11694, + 36285, + 49799, + 75864, + 36523, + 67295, + 81775, + 81390, + 52850, + 53968, + 67864, + 47746, + 44630, + 51308, + 83039, + 30707, + 70014, + 84109, + 28305, + 41389, + 76513, + 40844, + 76277, + 55019, + 75864, + 77305, + 61356, + 79249, + 14283, + 52268, + 30707, + 75801, + 68275, + 79249, + 26445, + 94812, + 75801, + 26757, + 76277, + 47935, + 87425, + 61356, + 49799, + 61818, + 22948, + 48072, + 26199, + 80898, + 10743, + 40844, + 75864, + 88293, + 83164, + 75801, + 75801, + 18205, + 38867, + 84251, + 49738, + 49799, + 88087, + 67584, + 56266, + 52850, + 14587, + 75864, + 75131, + 98591, + 18502, + 68172, + 62819, + 74323, + 95233, + 48095, + 42340, + 84109, + 93797, + 73087, + 95149, + 40844, + 80812, + 28305, + 37419, + 96842, + 75801, + 78959, + 56727, + 76277, + 40844, + 44630, + 40844, + 78959, + 11109, + 53918, + 70907, + 96208, + 23222, + 73383, + 12794, + 75864, + 98087, + 82137, + 53606, + 28630, + 59757, + 37599, + 33032, + 68219, + 99744, + 67654, + 93797, + 52028, + 55803, + 75335, + 11694, + 80955, + 46595, + 26699, + 37782, + 12721, + 77978, + 40844, + 91966, + 29130, + 32412, + 61356, + 84970, + 40228, + 98087, + 84109, + 54769, + 15123, + 70469, + 51377, + 77889, + 84109, + 71125, + 85683, + 30904, + 36285, + 92228, + 12721, + 60938, + 75876, + 51147, + 81810, + 11690, + 97587, + 74726, + 96191, + 75780, + 28305, + 71567, + 20940, + 34365, + 87425, + 73879, + 66787, + 77650, + 74726, + 71064, + 84109, + 61356, + 52329, + 66321, + 49146, + 53972, + 18748, + 28607, + 65350, + 91039, + 44630, + 82837, + 61356, + 93628, + 50135, + 40844, + 80873, + 71125, + 62486, + 67654, + 69144, + 43539, + 93556, + 82114, + 10568, + 25428, + 50369, + 84109, + 49738, + 93797, + 68790, + 50187, + 43459, + 84109, + 33697, + 23562, + 32387, + 47280, + 62911, + 40228, + 61356, + 52850, + 78955, + 43107, + 84109, + 49738, + 75864, + 51147, + 20026, + 61356, + 56479, + 80955, + 61356, + 17222, + 47746, + 51207, + 46009, + 97531, + 16534, + 28480, + 40844, + 97678, + 92823, + 96208, + 84654, + 20478, + 52850, + 49799, + 83899, + 96207, + 70318, + 79249, + 95321, + 32973, + 44578, + 84109, + 84109, + 49799, + 76277, + 30707, + 72499, + 70772, + 29213, + 67902, + 98087, + 84109, + 91481, + 76277, + 28310, + 87425, + 32653, + 47746, + 48086, + 74181, + 26300, + 22127, + 70386, + 51147, + 49799, + 97531, + 73630, + 28089, + 40228, + 95585, + 66827, + 50881, + 49799, + 76277, + 98603, + 78528, + 94830, + 39291, + 84044, + 79249, + 44630, + 92069, + 76277, + 11134, + 75864, + 40228, + 37007, + 76277, + 96208, + 91397, + 46791, + 75864, + 91996, + 51147, + 29851, + 85269, + 52850, + 76277, + 88634, + 71603, + 27829, + 63627, + 51147, + 69066, + 28757, + 18555, + 77670, + 81775, + 93797, + 49738, + 28305, + 59101, + 61356, + 93229, + 49378, + 48946, + 79249, + 48408, + 49738, + 67117, + 91039, + 71125, + 40844, + 78959, + 72682, + 50187, + 40844, + 79854, + 50187, + 37752, + 49738, + 70834, + 75801, + 49738, + 28305, + 11554, + 29272, + 79547, + 17772, + 75864, + 71125, + 31822, + 57967, + 68281, + 98087, + 44295, + 28305, + 98087, + 41211, + 80456, + 49738, + 18250, + 52028, + 79249, + 40228, + 28305, + 84109, + 96672, + 40228, + 95091, + 79249, + 52850, + 49515, + 52827, + 75356, + 47746, + 91039, + 34110, + 39055, + 98087, + 16648, + 46277, + 47746, + 63430, + 11694, + 62075, + 98087, + 11745, + 49186, + 49738, + 76496, + 11694, + 75864, + 81580, + 71125, + 88939, + 71941, + 97531, + 49799, + 86504, + 75864, + 15115, + 20872, + 28168, + 47235, + 85595, + 91039, + 27058, + 85302, + 21587, + 12678, + 84154, + 52890, + 73714, + 75864, + 69296, + 44675, + 98087, + 63562, + 47746, + 35044, + 76662, + 88293, + 39552, + 96208, + 68175, + 60399, + 89287, + 98087, + 42276, + 93460, + 63652, + 44752, + 16486, + 28305, + 45573, + 47746, + 62122, + 70443, + 16675, + 57833, + 56613, + 99154, + 56133, + 49357, + 60866, + 47746, + 50560, + 76277, + 85118, + 93797, + 93108, + 21865, + 48676, + 25800, + 77645, + 84109, + 88361, + 19091, + 39510, + 99948, + 76277, + 18403, + 79249, + 91039, + 96572, + 32815, + 75801, + 50187, + 84109, + 87467, + 67654, + 60828, + 56266, + 51324, + 81775, + 72416, + 75864, + 79249, + 30707, + 67654, + 52422, + 30707, + 51147, + 76175, + 79797, + 71125, + 42990, + 76277, + 52004, + 38942, + 93396, + 98425, + 77679, + 19068, + 65962, + 88101, + 42786, + 88293, + 42990, + 61959, + 42529, + 99125, + 59110, + 51147, + 80755, + 17365, + 80268, + 67285, + 87185, + 15806, + 71358, + 87425, + 66100, + 51147, + 80955, + 66978, + 85824, + 40704, + 18149, + 24430, + 11694, + 20525, + 81001, + 98999, + 95761, + 51363, + 25400, + 80955, + 52028, + 71125, + 96208, + 93240, + 88546, + 49349, + 90193, + 35981, + 18658, + 69254, + 25765, + 52028, + 53529, + 47756, + 52850, + 71095, + 99257, + 49799, + 55820, + 75425, + 51328, + 30707, + 85390, + 46509, + 70945, + 23863, + 92788, + 44941, + 79249, + 49799, + 52850, + 52028, + 45636, + 91120, + 61403, + 63921, + 32937, + 25655, + 52028, + 61356, + 49799, + 30225, + 69044, + 94265, + 11694, + 71883, + 91397, + 51147, + 74407, + 47746, + 74541, + 37237, + 21658, + 57210, + 40844, + 61785, + 40228, + 67654, + 11635, + 49799, + 47746, + 47746, + 30707, + 19530, + 15587, + 66426, + 23988, + 71358, + 96208, + 78728, + 72246, + 57550, + 54114, + 76394, + 31516, + 69506, + 79249, + 44630, + 36285, + 95657, + 52028, + 33686, + 50480, + 18338, + 87425, + 68560, + 52028, + 40844, + 40228, + 59999, + 93797, + 60286, + 90784, + 67654, + 98358, + 11694, + 47746, + 82114, + 52850, + 41396, + 27455, + 28885, + 76447, + 95865, + 11694, + 97060, + 36285, + 76277, + 55461, + 30707, + 96245, + 75864, + 51194, + 50041, + 30051, + 14953, + 72188, + 84109, + 57055, + 76277, + 91397, + 65269, + 96439, + 16064, + 43279, + 52850, + 55322, + 28549, + 99138, + 83521, + 87425, + 48785, + 11694, + 71358, + 32908, + 38186, + 87627, + 82946, + 18482, + 32396, + 14774, + 40844, + 56266, + 78349, + 75864, + 79249, + 90262, + 52850, + 56266, + 75864, + 21058, + 51826, + 42990, + 33412, + 51147, + 91039, + 49799, + 72502, + 30308, + 34275, + 36332, + 22962, + 91039, + 15695, + 40878, + 79587, + 14900, + 11694, + 40844, + 56266, + 96208, + 53663, + 75864, + 84834, + 67101, + 11694, + 90467, + 91039, + 11694, + 11694, + 91397, + 85476, + 52028, + 37615, + 66396, + 49735, + 40844, + 81775, + 40844, + 39592, + 40228, + 46979, + 71125, + 40228, + 56266, + 29130, + 28305, + 99523, + 12965, + 36285, + 88293, + 56266 + ] +} \ No newline at end of file diff --git a/Day01/main.go b/Day01/main.go new file mode 100644 index 0000000..b1e9a2f --- /dev/null +++ b/Day01/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" +) + +const DAY int = 01 + +func main() { + fmt.Println("||++++++++++++++++++++++++++++||") + fmt.Printf("|| AdventOfCode 2024 - Day %02d ||\n", DAY) + fmt.Println("||++++++++++++++++++++++++++++||\n") + + fmt.Println("Original Code") + original() + fmt.Println("\nOptimized Code by ChatGPT") + optimized() +} diff --git a/Day01/optimized.go b/Day01/optimized.go new file mode 100644 index 0000000..1c5b789 --- /dev/null +++ b/Day01/optimized.go @@ -0,0 +1,59 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" + "os" + "sort" +) + +func optimized() { + // Read the file in one step + content, err := os.ReadFile("./input.json") + if err != nil { + log.Fatalf("Error when opening input.json: %v", err) + } + + // Parse the JSON + var payload struct { + ListA []int `json:"list_a"` + ListB []int `json:"list_b"` + } + if err := json.Unmarshal(content, &payload); err != nil { + log.Fatalf("Error when unmarshalling input.json: %v", err) + } + + // Part 1: Calculate the sum of absolute differences between sorted lists + sort.Ints(payload.ListA) + sort.Ints(payload.ListB) + + sumPart1 := 0 + for i := range payload.ListA { + sumPart1 += abs(payload.ListA[i] - payload.ListB[i]) + } + fmt.Printf("Sum of Part 1: %d\n", sumPart1) + + // Part 2: Calculate weighted sum of common elements + sumPart2 := 0 + countMap := make(map[int]int) + for _, v := range payload.ListB { + countMap[v]++ + } + + for _, v := range payload.ListA { + if countMap[v] > 0 { + sumPart2 += v * countMap[v] + countMap[v] = 0 // Avoid double-counting + } + } + fmt.Printf("Sum of Part 2: %d\n", sumPart2) +} + +// Helper function for absolute value +func abs(x int) int { + if x < 0 { + return -x + } + return x +} diff --git a/Day01/original.go b/Day01/original.go new file mode 100644 index 0000000..63c691f --- /dev/null +++ b/Day01/original.go @@ -0,0 +1,58 @@ +package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "log" + "sort" +) + +func original() { + content, err := ioutil.ReadFile("./input.json") + if err != nil { + log.Fatal("Error when opening input.json: ", err) + } + + var payload map[string][]int + err = json.Unmarshal(content, &payload) + if err != nil { + log.Fatal("Error when unmarshalling input.json: ", err) + } + + // Part 1 + listA := payload["list_a"] + listB := payload["list_b"] + + sort.Ints(listA) + sort.Ints(listB) + + sumPart1 := 0 + for i := 0; i < len(listA); i++ { + if listA[i] > listB[i] { + sumPart1 += listA[i] - listB[i] + } else { + sumPart1 += listB[i] - listA[i] + } + } + + fmt.Println("Sum of Part 1: ", sumPart1) + + // Part 2 + listA = payload["list_a"] + listB = payload["list_b"] + + sumPart2 := 0 + + for _, v1 := range listA { + counter := 0 + for _, v2 := range listB { + if v1 == v2 { + counter++ + } + } + sumPart2 += counter * v1 + } + + fmt.Println("Sum of Part 2: ", sumPart2) +}