commit 8a6f4ba6b0d16eaf15bba5a203b0df82a42a1d18 Author: Bas Dado Date: Sat Dec 2 20:16:27 2023 +0100 [TASK] Solved part 1 diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..bedeaff --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,86 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml + +# 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 \ No newline at end of file diff --git a/.idea/advent-of-code-2023-go.iml b/.idea/advent-of-code-2023-go.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/advent-of-code-2023-go.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..c4119fd --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/day01/day01.go b/day01/day01.go new file mode 100644 index 0000000..b2f2099 --- /dev/null +++ b/day01/day01.go @@ -0,0 +1,79 @@ +package day01 + +import ( + "strings" + "unicode" +) + +func Part1(input string) uint { + lines := strings.Split(input, "\n") + sum := uint(0) + for i := 0; i < len(lines); i++ { + line := lines[i] + for j := 0; j < len(line); j++ { + if unicode.IsNumber(rune(line[j])) { + sum = sum + uint(line[j]-'0')*10 + break + } + } + for j := len(line) - 1; j >= 0; j-- { + if unicode.IsNumber(rune(line[j])) { + sum = sum + uint(line[j]-'0') + break + } + } + } + + return sum +} + +func Part2(input string) uint { + lines := strings.Split(input, "\n") + sum := uint(0) + for i := 0; i < len(lines); i++ { + line := lines[i] + for j := 0; j < len(line); j++ { + n, found := writtenNumberAt(line, j) + if found { + sum = sum + n*10 + break + } + } + for j := len(line) - 1; j >= 0; j-- { + n, found := writtenNumberAt(line, j) + if found { + sum = sum + n + break + } + } + } + + return sum +} + +func writtenNumberAt(line string, i int) (n uint, found bool) { + + if unicode.IsNumber(rune(line[i])) { + return uint(line[i] - '0'), true + } else if strings.HasPrefix(line[i:], "one") { + return 1, true + } else if strings.HasPrefix(line[i:], "two") { + return 2, true + } else if strings.HasPrefix(line[i:], "three") { + return 3, true + } else if strings.HasPrefix(line[i:], "four") { + return 4, true + } else if strings.HasPrefix(line[i:], "five") { + return 5, true + } else if strings.HasPrefix(line[i:], "six") { + return 6, true + } else if strings.HasPrefix(line[i:], "seven") { + return 7, true + } else if strings.HasPrefix(line[i:], "eight") { + return 8, true + } else if strings.HasPrefix(line[i:], "nine") { + return 9, true + } else { + return 0, false + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..73d217b --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module advent-of-code-2023-go + +go 1.21 diff --git a/input/day01.txt b/input/day01.txt new file mode 100644 index 0000000..5484788 --- /dev/null +++ b/input/day01.txt @@ -0,0 +1,1000 @@ +99lbqpxzzlbtvkmfrvrnmcxttseven +q7cnfslbtpkvseven +6threezlljtzcr1sdjkthree4cx +21xfxfourmzmqbqp1 +lkdbjd5 +8three27 +21three +3lqrzdq16 +49threenjdgrmgfnfhcgz +fourmsmjqfmbjvtwosevendcljsdcstl3one +four98 +4sevenfddxgcvdgx +dffmkvmhhdbzjcgrjc5132 +eight4one31nxlnrzvtfvrkfvgbbqmvff +mdmvbhqjt5rkfpcnfvzhkkfbjvh8three9 +four32 +seven6pljhqnineeightjjsvnqblk8eight +6glzfour77fiveone +ntvhxqzsixxcrfpgstwo915onevxz +81four8xkttczb2vj +six8flfzdzl72eightnine +sevensevenzsztgvh4sixbzltzl +2fivehgrszcrgc9 +four53ninedrjllgffrfrtjgggvknine +nineonecxpzzqsptc7nv9pck +sixrqqfkcjrqkppvqthree1 +1five72cxh3fivefive +75349sixnhxjpgtnhqlf +9963onefourthree6oneightq +51fp +foursix2lt7one1sevenone +fourddcmgbvkm8fivethreeksqghch65ztdtsdmpvk +35jxmgctsevennine +mbbkjxfthreetwoqlcrjnlvkrgnine41vkjknnmtv +three7sixtwohpghsdxleightthreetwo5 +twocbtbkxhhcdrctkc14hlmdh +4sevensix3ninedss8 +snqhqmffonettwofourgdkjmbjvjpgxxxpzkm8zfpfcgj +3xmpfmnlz9fourthree9pdnzdlcsix +66fourone1 +bdkfdqvkmmstkhdsbbl5 +48nfive +twothreesixthreecvsskxq3threefoureight +1vkseveneight +gskgpsix4lhrtwo88threernhqnnfqdf +nskfvvncxfourninehkrbxpgdsk4 +vlm3qszxqnnzz1ptcvdxnf +xrppvsfourfive3sixthreebvbdkpckgheight +pckngkbfour3nineninepqcxvsqspbthmhzrp +pbtndgpfkhpflpj39zkpjcnine +954fourvrmftt +2xjrkdb8mzcfkvbdcx6 +plt462 +mcmzfzcdones2seven4 +8chnpnqmbx946eightkdjvhkkbtthree +6zgvqslsixnine4fivethreegqqpjz +9twosixseven4 +7seven75 +four7sevenmdj8 +6r219sevenpcvfpmfxxl +dvxjblhdjqttxdfourhhrgdpmvvone83 +one3sdnfone1ddjlzhgninethreenine +nine3sbj5msppfonetwo +14tgmqlnh +seven5xjncjmggjppmnsx7fourdzxrsck +j1hphv +61threejjlccdzvsevenjqpbjsphdq +pjmsphdtwo5x6vjzmvtkfhk43hknqc +xfpbzdl6 +twosix3fournlddsqmfbpslstnfiveonezfgoneighthtl +828fivethreetwo2 +fmrgz5sxrrd +one88cjcvxddjmczjznhpnvsix +two9six7pkgttqdnsbgfdcdsixmskjgfvvlvqvdx +six7eighteightq68eight +seven4bsrfpxb6threesevenmgxfmfive +gf74fourjdflkdtrvmljskxsix5three +xsvrhh25 +2sixtwofivez813four +kbkclv3onelmf4ntxhxbrppsixsix +8nine9hstninezzbflnjfxrndcpzknk +1hjlnsszbmtjtwo +2one146 +9jdpnzgqrf +1qfbhl83threezxcrdfzcbbqv +p4lcmztns33 +xmcsevenseven21jjfphz7sevengxlvfrrj +jfkmdmrfhv8 +73spzlbvnxsqsvgpbkl +kkeightlrnj4three +4qxzfxjdmrddlhxfive173eight +jhmvxpbeight681gj6seven +mqpsxqpxj3nine9ss +fourdjqll2vbqbtwo +28fivesix6one +pgblvrqlnjfdtvngfbzpl5njsmvshn5tc +eightvvh43nine +dpxc5oneonebdbkheight +pveightwothree2kfzpkks3ljxnbp +vknl4xptptjjp +4twotfour +182eight +ninesixqkfbhgtwo3 +twoseventwo4fivethree3one +sevenoneeightnine4sgkckjszmp +six4svkqftsrdzk +bhnbm96fivenineszx8sevenoneightkdk +rjldcxl8cxkpsdsdpgbngqeightnine9 +5two6bdrksqgd +threestrhsdtmnc998xfdtfg66 +bknkttsjf6gonesixeight +nine6one9jnqf1 +qkrpkv95bd11two8 +dksqfpmb6ttt5twothree5 +xxhrnpjsvcq7nineonexjkcsrbxr6one +hsmdgfvbsk76four1sixhfn +ninefiveeightrflsdc4one9 +four73915seventhfmjjqgxjzsnxvmnl +seven9phpseven9ftwo +59121fivep4 +gg3eightgdngqf +4zbthb7 +rxrhprtfb4ljdzqfmhgbzqzmrvvj1eight +zkvmsrvtk3two4 +ckbk8nine +tbbkxr844lpkgjvmsix +onetwo8kbxqgvsevenmrhqndt +ptvgfn6rnpfkxcc52 +three1vd +fivefiveeightdrljdrljxc9bjpbqseven8 +fourx7mlksevendjtr1lb4 +6ndfqts3two88 +qh976eightvfch7 +five9xdthree1seventhreeseven2 +xvfmccmmjcjjsm5 +ffiveeight579 +97hcfbrhkfive39lzhgjddsx6 +388eightkrmdktwopjdlpfmfivetwoneql +eightonenine4 +bqzpzbzkbs7nprbdmbqseven8kzr1pflnine +9eightfourthree5four +cclc6 +13one8tkfrmvcjfq4sixjlxj +dtrtwo9foursflc +3six4two3nine +7vkztxh6 +xthtrhfz83six +twofive56 +nineeight5 +one5qmhmvrkktjmvhgxx +4four1 +8one2dljjrvkthreehjdsbpqgtbjm +foursevennine51s +1nine8ddhdnbheightseven1 +nine5five2375lhphjk +ftdrpmmzhvrxcz3vfqnhjqlqxdcrxeighteightspmj9 +qbczvsdl449six1 +seventwohpknrrjtvfhpxpzb3sevenn2 +jnpxrqrtwogqsk4 +three9fouronejjlrzqdrxkcqnd +ql871three1rbhtszd +xfbrnkzshqtwo43twohhfqdddc8j +ninedgj6 +two3three6ninethreefourseven +4bfsl1shdzeight3 +96mcdgv1 +4fivefour4 +sixfivetwo4pjbkcg +4onetwotrnqlgxgtxxrgxpgsevenddjfd +three19 +jbnrs5bgmsixeightxzjznzkhpvsix5twoneb +7sixpzhsbnhrrmonetwosrjbt1jcxflk +74onetdh7 +5one4cmmcmjnl9eightkvhrnkgqjstxnpt +seven9xttdmzsix9tbnjfgmsgfoureight +32five4 +7five41lpscgz +48three +hddfhppseven2 +5ninecbtfxkfrtccfdzplndjpseventfhqkmcm5 +65ninesqgeightjt7 +four3csxzztgbrninesbfzf +2bcnlphn +xsfmhnbdrj31828 +ninezrvbf717six +7hlbhqxseven +2jrvfr5lbqzfjgpdgfourthree7srmq +6sixfive8nine +eight29one +onefour5ddgcrninedgdkzh1threesmcjmntnhh +gdg18ntxdpvvxcn7zk74 +5onesixfnppbf2vxxbntdqvv +kmclhrb2five49sevennine3eight +6jdddgdjbgdqmkktf +26jhvtscmrjthreenine53mldd8 +mkdcpnbsevencjfm21twotwo +3bqzmtnjhlbdszlrvpmvcgclbgfzljk74 +8gfbmnnlltjcmjkmmvnfsgph +eightpcggqtqns2 +ztzrvxglv7three5cmhnbt1five1chfk +9eight8cfzrsixthreevvvfour +3nine824ninefour +nmrjjp2fourd +twoonemgdm67 +foursdmljtklzldsevenvbqpthree917 +3ddzjxlsg69nine2eighttwoseven +6btlmdone8eight +7qhmpdeight +dxlb1 +zp9bqm4176seven +5krrrsix6 +9seven4ninexsgrqs6 +9zzfj98fourpjzqtk9 +svsrlmggeightpgmprpkpj486twot +sevenfourtwo8sevensix7 +zqspkktb831xjlhvfourtbtvpzmlbbt +2gfffoursix5 +8ccqxqm4tsdpvvxpdpcrlmktmg +5fivesix +7fourone55two7fivenine +9twothreethreeoneone +xtzc64fourzkpcqjg7twobslssjln +38fivetwo716 +hkxrxtdjzdzqnrzxfzsix3three +onetwo8 +ppbrqlhvqpcfx2 +rhlbtdddqggnmfour74zcmrkdthree +threesix3seven1one +nine6six9eight +mzmhvmrmtvsk5 +2qgbkrrgeightfzflbhpxctdpg39 +61two6 +2rzbdfmbczxcgphmonexmntkcmdxxpg6 +b6threetwosix791 +sevenmzlmcqxdbfmfj8ckchpkgxgmtmnzcninethree +jvrpkltm9n9p +two3bhlrgqjxbc6crzbvzmz9nqfdtztvqbhcrjptdvm +jdjchvpkcrfive67fivegltkrflqsbktkc +sevennine99jpkqljhfztbqrzm2twoctrgm +rcmlkj5 +lltwo4ninestwoseven1l +65threerzpkhjtzxl3jx +ninesixninebdlfckbp2 +fourdqqklkgcsbtwobj5 +threesix44six2tctgp +9zczcltwo +vr6bmpl +7fivelpfnzgct +ninethreesix1twocqfpchfour9 +1jcj81tkklgrhhjt +pntwonetwotnpnbmonennfblctcv91nqr +jnsfspcg45xkc +8eightqbhmrqc +five5threerhxffonemkbnine +16hqlvzjc +3mzjkkr +kcsrxhsnmqkz3two +9ftxzstqrdjcqddvzdxljz6sixsbxlztnqgthree +threeninesxt965six +4threenine2417qcljfive +4mqzxsnt3hqbhjj +r9ctkhvtl51 +47kmgznjvcg5eight +one5rv9ztvpt1 +2one3htxp3three +74six4bkqsjfgtdt +two2onenine9fourfdqqrmx4one +rvltwo9grrhsvgzr6pmnvrnlxb +ninefourrzgfgcfcvv8two8oneone +1zg5seven3 +six91xgqcs28 +5threemxxntrml +3hjltzgdgcmfmstvgfivenxfour5eight +five1dl8six8 +96lkghnglthree +7sevenvggnkkjvzmjbbjgjhmtx53 +9onetwo +6tmltdjvsevenfourfive +ghqkskqmbnhnone7dphgvqjzbq834 +nllxconethree1 +fivez5lxtfpjxpfdtwo6twosevenkhtmqbm +eightone4lnhlq3639np +8cqcjfxvclskqqnbgq8 +qvsixgxlfsevensixhqtgmnmvk6 +twopfccg6nine4gdhrzdqrbm +1hg72five +kqrr96jhsfxgddncone4 +55xsfk4nqzqvthck4onerldsjx +ninesbcqfdlvl1sixeighthdnhsh3eighteight +rrspvpclvl7eightthreeqtfive +twobfjrmffive6three9kqmqmmps4lrjzjqt +fivefivejjxcmczlsdeighthdxbltgvjgthree8mp +one46mhghdxldbfiveckljksxm +c7fiveonesix +sixnineseven8xqb48eight +2mqxkvdmhgbnx +sixkrknqflbz6 +6four9twogonesix +cbxrknrrddnfour73ninexqdhlql +rjtdxkjfs628eight +xchpj2 +fhteightsdzsjqvhgceight43threefive +426jqvrxqflhch9 +sevenmj3fiverfqzhhpvtbkrqglqzp +2nine8fnz3five7xjzrp +twofiveeightfivedcnpv74 +7fiverkzrthree +gfctwonesevenhhcsvjqfourpfxjmthbcm5mttmfrb +fourjc9threethreetwosixpffp +sf9eight5fivenrlxfkjgq9 +hd48bq +five21sixone +vgkgfvnblrdbeight245nlfnnhfx +3fsdrdmvrqptwothree +ntcx82fivesevencvdkk5 +6gdmmvxcvp5sixthreecjtfkgnpmnthree4three +xpkthreethreeeightxzkdv7mgrbzxhfive +one98 +5foureightmqstc +twothreejrhffour9twosxcj +twoseven5five4ptz34 +1phdclsix +3chbfpvfzj51tbhpvqhninefschztfbdm +113tqmjkzjlgr +kjdrfrnzhvone6bhv8zlllc2 +four1nine +3pkxz8 +four1oneseventcspbzninenineqdg +one9lsmfghl6pxhbmmzxpjjthree +szlqptvcvskkcgxxtfrfivefive28pccjhzz +7sixjhhzhgh +onerxgnxcvprphgpzsixphrkdd97two +twodhqbmrz11lg +5ninectctwo2ninenc8 +hntt5 +chkjc4twokc +threecsix62one8tgnsqxxvpjsix +fhtjrljsevenfchxccpckl8 +nine61sixrqktdm9 +threepkzmnmnmmngxrcq7 +4dtfivehdvcknmkj4sevend3tx +njcvzpmp8gmgvtoneninecnhgj3five +4pvqncghvr4pmlone +2eight4596bs6 +twosix93fclbgfive9fourxnqdhkg +8onektghncz3dcklzvbdtwovsnlrcclpc +221threegtmppngzseven +jrhvplk55five7keight +4eightktndbfzfmskcjlm1 +fskbxxvvsmsevenrzqrcgninemscc8vnvzseven +kbtsf6sixczlbqzrjfm9oneightmqg +vvn3threefour6sixseven2 +6jfourzkhlllkseven +2twodxxhhns4gdjqmztnine +sevensfxztmfive7twofourqbzlzkjc +vqcblfvrgfourfiveseven7 +6nineseven4 +bnfivevbjgfzcctrhncmmnpfzmcdt4six +two8onesevenonecmtddxnfbjeight7 +4sixfourdgmstmsj +7eight97kzxxdbdonejtsjqgjcdlssix +vtvdone2cjzcjltcj6six +ztwobmrvcbfsnine4one +jjblshvzsevenfoursix1ndqlgphrbbfkkcmstlsoneightfjm +5seventwofive +onebk4 +61bgcdfjsevenhhcjjgdqhr +6kdvfpsevensevendg3 +61gslvnlcjlsfgdsflqp1rnqdgktfseveneightwom +rvcmkdtqqglcvsxkntfour32bdptgseventhree +zvsbhkftlpgntvfgfxpcztm9fournmvxjnine +four91nptdgzk8rnmqc +tqmtfsixbcxspjscnine2 +1kvmreighthnine2qxvrckqvgd5 +dcpvrl8two1fivec698 +xqg91snbsslnrptwoeightdzq +gsnvsix4vdmszmjfourfnrnine +9nineeightthree51gl2 +7sixffvf9two +bbgqpxghsb45seven312eightworg +fournineeight45five4fivebrznpkz +dhrsrghxfivejdrqfgkdlxzb869 +8nzxvsmrrcz1one5four +3mmlzvzqptttbbmtgthfive1nine +one9eightpzsmjvnptwonemkf +fivejkgrclbthree5 +5fourtxxxvfthreelxcmghhtkqnrqzvts +1tlhcscbd +99six +53sixthreetwoninedjsvdfourone +fivefour7pbponectstmp +six5tnl164htsv +fivekbkjtjkxfszcqvppqqxdtwo29 +42threexpdfive +9892 +lvlkqlzvsix7gbxhpxrdfh2zcgccjvblhpvxqshmbbjkpgpd +two7sevenfourblphfkgoneone3 +7onenine6535 +59zv +347threeeight +8five49 +73four +heightwosix99 +1foureight +soneight1xzmfs8six7vpxcfq +nine91 +pvxtkphg3gzgvqlfk9vhjvqmgszfivegd +seventwo9six2 +2sqp +3twoeight3 +8slnsxtteight429seven +qfjtthmthree3twothree +txrdqsp4oneqsprgjnnsc +7kqgv3five1 +fourninegrfz2 +seventbbfrvjqlkvm47 +8pkqtpxfxrgpq1 +kqvseven4n5ksixdphmjk +17j +1m3 +ninefivefour6 +jrdmvztnncnhnp8onefourfive88 +kbvninetworblsd3fivesixhvhtxvgt +4ninesevenkpfgcddkninetnhg +9rdzsixsixtfbgzmhsgconethreedfxqqvv4twonem +kvbeightsdtqrhsscpone6 +7fivezhxkkxlsonenine +sevenone7threeddmjmsjrhprn +eightsix5 +4bjmfskbtc37seven3eight +grxbdmppllthreeeight53 +one8jnhgjpdbseven8bc5fivenine +jvlmsfive43gqmpzseventhree +jqj9twosix +eightseven9 +fourninexdzbnqsvkdvbbkb6 +pttwone2nbone7gnpbllbhp8 +sxpkrnshj8fivefive9kfvgjpv +4threepkvz2shljdn9hgrmznine +6seven29gnhtvshpks77fourstkdf +bmnfthree2threetwofive +51 +jghxzhndrkfourtwo1 +jspckbhzfcqsbone26mfhkmqztnine +5fgzbmgfivefive +six18sxvchr +rv7fivebdrtdl5twojt4cx +twofourthreetwo5onejfm6 +threesixeight2 +9jrmdmzvlgnine6cjlphdnine7 +9fivembvhfrlnzbsevenngp73ninefour +sixxtcgjvssevenmfiveseven15l +threeseven6 +cknkdqrnxrjfbn818vstmprqbts +4zfmxjxlkv7rdqhjfourfoureightcgvrpxfnrn +ghzmpsgzrkztp8s4zl +ninefour78rhtjfrqvh4 +one9qzkjtsix13 +sixfk72jjnrninertbzheight +rxhvxzcp366one +24eightthree +teightwofprzdscnts4nv88 +eighteightshqcbqzxmbktwo54fourpdkf +sixfhvgkfourfoursjxnstgqnjh2 +6two1vtnqbrhqjbnkm7six9six +66threeeight +lbdkggsncthree315 +8gqsrmseven3gvvxq99 +sltgzbgbmg1 +9twov6 +shhbqkcc71threecmkl +cgqtpsjkglzszffcnineninesgvj1 +fourhqnlhrrsbrsevenkrgffivefour6eight4 +twojdccnhk6fivelddgrppkldtdlt +4dlkn5x +12sfdtvcqztxmtvvkds +44one6jxjdbsjxpg +7sixfmbbfxnjjhj5qkqfvfntonegdktrfl +eightfourzkdxgqn8 +1fourthreetbvtpphj4rmrhlcbxbrqfdxszfour +eight42onehpvrlbkglq +9five2five5 +bnzbccq26mblqtjxlsbtdvm +nineninelnknxhbfk4xssrlsdmsixoneltjseightwofzf +8mleight7zhfsmsmpdthree +mjcsr5tsktfpzc2nine7 +tmlxbkh79four7 +fiverzrfvlcdnmkn46onennxbbvn +threefournine9 +snz6bcgqlhx +4ninevqjlbfklgz +8fsvsfiveone9fvdfiveg5 +eight5dhcgxjts +ljldjmfmgtzclfhthkdtdthree4 +qrlmdjmkvvtwopdphfpmdd6fourxkblfqcx5 +62glckjgdvnpfourzlkphvrjffive +nltxkzk2zhmqhfqq +95six8xflfzhf3 +zsfvrpjx67 +two4vfivehglclslddsix +gssccpnhjx5128foursxpgrgztdfour +87fourpqdrxmvqdmxfrtzthree +one85fmkj +5rtjzsevenfive1thpzqxxm5 +bone78 +4three83947 +sixffkfmhzfkksevennllffhjvkxqhpjjtfl1 +foursixxvfst6twosbvjfvcb2t +fgzthreekkpffive5four +685jfttdmjq +t4 +xqeightwojhbrrrqgdtbcqlhthreesixsreight7rxxgqntqdqlbnm +stbmgqjdvqfour4 +dfour11gfcvx4nine5 +eight4fourseven5five +six3seveneight +four2sevenltvckjxjhjfslsvgpzxffivefive +27one5vdtkjt4 +fourzpr1gxgone +gtfive5hbqktbfour5g2tk +nine2pqhqgprxrg9hgjj4 +twovcjkcsqznsix557psh2 +1fkpjccjffr7nine3gxzk +5threezzbbvtcbvj4 +8nkbdhct +8eight2 +six17ninetworpc4 +qljgkvq23eightfourfour +onebblhxbnlhztgrkchlbtwo5 +sixthreevmngjjgpfourrrblxqvcl22 +mcnksthree81xrzrrrvnvdvbzfzlrgseven +chjxhjjxthree3 +mrmxzpbxnh4sixrxskzvnjtlkjddnrpkbjhslbxjbkq8fsix +2kgfmzeight +plvslqzpbk7 +xsfq49ljfts +seven2x9hpzbhqzpffoursix8 +5999one1mbnxmrqcxv9 +eight52prffgvvgznineseven +l8onehqzcf +sixkzxvqdgnbbmdtrvhzfouronekmklkjp34v +98144threethreebvcjpllggz +nine7twofive9sevenszvdrq +jnvcprvbgtfourthreed9pm3 +tszbl9one5dfmsmkmlvfrlf +537tmcrdxp +sfcqfrrcqj26 +8fourfoursevensixmlmqzggmrfive +kbmbxz1onelqtdxxk3 +45mxksixfour +7zncmh2 +hzoneightsixfourzzlkmrnzptllthree2tpdjtsszxnjdhkgv +ztpqbd68814five +92gnzsvldmvhhzb8 +ninefour2sixseven1seven4vcnkgklh +sevenfsjrdhclm7six8nlrhdpplbjg +sevenlgd86 +pg75sixtwozk +734eightone5gssxhffscq +5sevendrxvkmfsjkgg5twocqpqlhksrp +seven1cktfl +mrs7 +2foursevenninelpzxthreetwojmbvfzs +2rdsjl1three1 +xrkztslbkgdzgjjtst5six5fourthree +twosixfhlldtwo2sevenfourknbfgnnjs +nine699two9pp1 +9kdlfour8kzfm57two +hlmscnhk1cqqzqbsxqglf9jgpjnfrjczeightspkkzrdqjd +72six7mjsxfxtz5 +3sixonebkfgp +fivefourvslvn2six +19pshkt +739bzfpltmtsevenfour27 +fvps6pprtjlq5foureightworm +qds3zdsgzxvthreethreeeightdqjbtrfjbbj +nine3148oneeight +nineggvmffthree1fivefbkmmfvjkpcgsxrfzg +7vlff9msmx3njb76 +hsthree4jfpvhxnceightkfseventhree +hx3seventwonineklbq7six +38zeightjlxj +jdbqgmsix8 +seven8njthzbdrtninexkplhnrfourone +tnhhzhjccjdtpleight3onegsevenxkqbmqzx +4679scb2 +twos334fourfivefourfour +sixseventwo356 +xnmsevennlr78jlfrbgb +four7krmgzcclgf6dteighteight +94mzfhdk +7two43threecthree +lztbgnscq7ggeightsevengtjpseven +nbcrvpljfive1threefive5seven +fc895 +eightlqzzlgrxv9gdfcrpkxkhzgbjtpcgncppm +8cfjbngnd6371threedczkfqmptxtrqt +6jblvpxskcnine +onexvkxthreebcvnnrctsix1oneightsrd +two66fourfourdnccpl +3fourbqznm +eight9lbz3eightfourmonethree +2qpvlbbb +threeoneone1mjhqfive +2threenine +two6qvxnnqj91eightfourkqxvhq +rtsftmvb14 +kvzptdxdfsrm5four5three +sixkfjjbccbeight3eight +kjskjrnbfs29seven6 +68qxpjrz +eight4cnmx9four9eightvbsvvsix +6xvsptbqcsxlcdzcnzrninehhrjqjsixkk +seven7vknjphhfbs +rjmhjgmpzk22fjmtmtc7spgkfkqgcn +three8ftxlktggjn2rfljxmlg9 +9threehlvtmftzfiveqghnvmtbseventwo21 +pceightwopbpbj3two2eightfive7 +lsdbf6five3nddpcnnine5xvqx +2sevenseven86lldmhf +8rqhnhsrcjnfzgpcclrmnlvbphrtgchpls9 +kxeightwoxsrvcbzhhbpdlrt22fhqfivefptwo +bdseven2hnqccjqgxjvjk86xvbhddlbx6 +zszz4kqtsqjfpqmcxbndmbdseventhreeeight +fourfiveoneseven83twotzblfpldfq4 +tgbxlthreezdfspjsnhrmrqxqj6cplcczt2pgsbfczn +jzdkc6xfmhpqstvzzmvxk431 +7eightqbxcnsgxm +5sixeight +6sixvjstz +4trxhdlkzqvjpzgpvfp1 +sixqhghvddcdn7blhptxp5htcf3 +nineksjvmvc2 +41krm9 +nine42sevenfive2 +zfivepkfqrgpkmxbmjbq6tgktpvnjvdjzsd +gssrnnqmm7sixfivelklmggxgkdtlmlzqp +64qsevenftmjzgs +6nctkfbskghpqr7 +8nine3 +hkjoneight6seventhree9 +11nineeight9nine +845fouronetwothree +pfhb14v +three21kdgcplbzzbeighteight +4cszltd7ninerrmhjqmtrprtccpjnjgdbdtwo4 +five96 +2lkfbsnq64three +srltvpbgnxvlksmfzpj2 +four9tpjvhhpsctclzpnsr1fourcttqvng +gpjxncqsbp46vb9tqgnninetwo +four1four +6dtklvddhlprphffpnkrksfseventwonek +eight4seveneight2onezfbnvjplvl97 +7ndvfp8qstcjdgzcfcninebj +9beightbsbphgrnq1ninesixsvthrx +bpxthreezkhjleightsbxmsdeightseven4 +fivemlfsninesix1nine6six +4fivethree3qtqsbscnc +four7dsix3kfhrrgbbnlzdfbgxsix +hqckztqxgxeightkfmvvjg6tp4nine8 +tmgfmcl2twonedg +fmvvcsix8nineninepqdrcmhdzsixtwohcnrss +nine258foursevensix8eight +8q +pqjqrxnine2one +9sixpbxr43sflnine3 +4onethreeonefoursixonefour +1vnscdrnnfpkrj8mndxbqdrckzgdpnfdone +threeseven7six8three3six2 +jvt24pjtnxdcpsthree +7nxfpnfzrssvqqcnrjnine47 +cflhgfournine368 +62srjsxgr +mnsix6fivefourjdnqfgjvp99two +8five6fdvgctwoeightcsmspmxmbgjqzjhlhb +seventgcdvchsfivefour9nine4seven +bbzvxfvmxhqv26rp5 +2psmsflpgqmb +eightnine4threekgfjmhbkhtxgr4threekxnmspvbfs +seven9two84phzrrvftgpt +xgpfkphfchzptzvconetxcp3qdmdn +five2fddc8hdzrzgcgdtonesix +one24sixtwo +mxfltrcltqjmmtj4psbf +jbrskjdtthvksk9mhfxjgdjt +four96njn +five8tqltpdxrklninednqkmgstlptpjhqvklnjhrvpzvpfr3 +onecsktmkt9 +seveneight1 +nineeighttwo1txhjjkqzqtnine +37onegfcf253 +4ninethreepndgnfqpvqzxbxkpgp4eightwozg +tfxnx999864three +sixthree19 +3nineonefive +rpht1onetztgngmeight +9928two4six5sp +gmhtwooneclqfdqvfivefour5 +two3dkkfive +7four6pklfxjqhgbvnpxmndsixthreetwoeight +5eightthreeseven9 +9fourseven5pmtcdpfvhjj +24fhbms2sixtrjtm +seventwob99 +3mffcdvdqsixgxtbrxqddkrzclz92 +5fivenkmtgbsnsixeight +3seven9hcbmcnjvqfour7 +bvspr4jhjlnddp3eighttwosixfour +kdvh5 +seven7hvcmdfkfour5nine +1ksqzfnmhfqjjlklptmmpvxnine6 +fxp7hljzvndnd2mpqm8 +86qxntjqmljdqpdbftqfrfiveninefcxzdqctbjppc +one62 +two23fivesgtsqpjrkvlbrfknjgcjbt +29gkcpcfdlm3 +ninehzvhg2one +ljv73tpfjvbhlxnpxqxhfivefivezxtzhlfsc +three7637 +rnmkzqgtjpfbn3nine8nine9ttcsdbr +jqtwo7fourone7dclxtnlnthree1 +872fivemjghskxcxmninexljstpvb +9hdjtfkqsb8skkvpfpgqlctvlz +nqnltrnsevenfbsixmnxrv87ffsjn5 +fkxzbxsbbfour17fivenine424 +ccbrxlskjzmrclgchlxlcpkck2 +one9sevenjgxrk33twonepjs +5eightthreefivethreetwor +zxqdnhnk51 +two39xctxpvsmfivenbtsmpcg3eight +three52threevgj8 +1twom52 +3pthscht +8ninegx3f8 +lzjvthree96jgfhfvsbv7qfour9 +threenineeight722ltvvxhdczjfivedcxbst +fourgvlbxrone8btblnlbkmx51 +one5nine93fzxthreebzchcqjbrxxct +3sjbbtbpkr1onectngpqpdfp +5xdgpgpm +nine9onev952 +fxc9seven +fiveggdqqlspfoursevenfour5three +7ninekhxpdgfive +3fmkhhbztk +737 +3kx2sixgrgslpfvvlfourfive7gbk +1rqjxnfmzkvxxsixt +fiveszkkmrtrctjgqvcfbg5r5 +6onefoursixntbbrjxfrfournpjbgcx +sixgpbbbkhxdj4skfrvnnlmmhxcpfnxfive +two37hjdklhtvtwonzhcqrbfv +eightsix7 +four9253njcqvvhtgs +fourfive3bxnvck +ninelsrbgctxvn59six +3jzqb7six69eightonenine +73nine6tkrqsc3kthjdmdtmsixspvvr +8691twothreeeighteight +8ninetwo7nine21qpkbml +3lttttwonemh +8eight9onefpscrm5 +qgl38onevqjbfldcg +dbcxgcfsf23jbb6eight671 +18pzgfqjsfourthree4bvqtxsh +fiveseven7mdgmsbdphthreefivedpzjbjc +7onemmspfpbfbftcpgvxhmh944cvdvlp +96hpgcqlp8six +two5jrrsix4dktmzkqgvb +two93fourninekfkkgdxbvk +93onesdnxqtwo +jxmfmmvlxzseventhree5sfconeeightkrzdcvnhpvmfnz +86gkxpqspnxs +seven9pblxnnkkjffournjlkgqmonedxqseven6 +jtddqv7nzpsixseven +vgjkbfnc29gskmmjmgsrbvghgrbtsbrdglszsix6gm +gjglfour8three7five +seven8ninetc4foursevenxfxlvmt +sevenone21nine +9onefouronevqrsthmlone +8threemsrbrchmk22fivepjdxprpvplt +rsqkrlnfpsixfive3three77 +twoeightseven2threejzgzmzzgqdrcmf +three8lsctcbnhgkpr3 +4ktrtzn +vqhvfxrxhpdgqhcrrczjlmhdnlzseventvtrrktd9twonenqn +twonineeight7 +67sixeighthvfkjhtj5 +644 +onezdfz6 +6qmcd9ninenineninetwo8 +four7nine7 +4hjnndn +1fqfqdqqxdnvhmqcp8 +rrhndnbpjjzhclhv9ppvlbtxklzfivejhxzcbpmd +six7526 +8ninefkhszlp2 +fivesix34twocg14 +3sixfive +2nine3 +2hv4rrfh3two8lr +sevenrqbzmkmcn22 +56vrglvbcdtxxrnjrlhpffr +mfddxflkqd4six +bfsfnkqxc76rtpgss3pkqkksrcxnine +83fivemnjdfnk85zqmssgfffourvgqjbn +822 +dvxgqrbjpnqvpsfthkz6 +4fdlzcxeight8crmrztfdmthree7eightfive +two9threefourtwo8vj2 +nine1jxpclfhj +jrgfxlgblzqnr9mnfrcsixone +5t3nine5 +twogxssevenoneseventdc3 +rvzcbtwofour4sixgfzk +six22eight81ninepnscnlv +eightfiveeightsevendxx1gh +7nzlpbx864g5 +hxgdrrnnsix1sevennvmsvdvccpmfive +1threevz9 +36eight4xvnrghgjf996 +nine8mmtqkffkthree8xpmsbksix +1fivejrgqrjjnql2dvmcqdbjbsix +15fiveseven1td3 +kmfmbhcmf62five +36dxfoneninefivehrr6 +four54sixfzhq26 +1427qjseventhreefiveqhv +eightghnnlddqdpm1 +9jbcfdjzjxreightlcpmdddts +6ninesrdgkrfivefoursckkrfrpqqhgzeightwoj +xmqsnjgskfour8eight +9l8one +four9jghzbrsix7seveneight4 +9tgsvk +sxgkkbnlsbnbbc2ckqhzgdlsbhp +6ktwohsvbeighttwo +xgfrrnrlkgdqfxdtwo9fvthree +5hqdvsdnrvr81sixsqjmbdls +kkghseightsevenmtbtvplcjnqtscx6 +rveightwobhqtmjhsrptpzkbv3ninem +3qpgbd2fourqdsnnbgmnsqgdb4 +mfive12 +52xqhpfdjgmeight13tcn3four +6lkgjdj +rvsvpt144lrtvrtpvd +8fourfive8 +28dhzrtfcjlgchxbthree +vvsixtwodxfz5six +seven7rcp7 +threethree136gts9threenine +9477 +seveneight8gmhthree8 +nn633sixzxcxthree +two95rfcffourtwo3 +76nine +cvhlpzsbmknkqpgsevenlkzvm7hnznjsbszgvxrmdnn4 +pnlqmxlmvkkpdgktwo1four41one +4hgnhzkbmlvkqpqqptd93two +lfsnfs7eightvdnghthree +shpndlkr7five1three6 +sevenfourfivesckjjlzgv27four +xhtpxlqssd3eight6two6 +48ckzhkk84seven1ggsffz +33rqthree6jvqlbzllz +4jfourthree6 +jkhflbhqhtmpmhmonebfbmcmczbspj9sttmnvnvgfivekz +eighttwodk25sevenninenine2 +oneqqxfkffivesevenzqhvjtgjlrninenine1 +2nineseven82fivethreezzqfjm +mh4 +3tjfmrtnff498 +five7three7three52eight +jgrndnjckvc1 +9sixgvv +six3rfpxrl9three1chczskrxthree +6bjqqzfqcxvnxbkpq +922 +loneightnznrcpd6cpfsmclp +7five7qncxmfhleight +bhsgbsdnsixnine4msnfmonerjbpvkqf6five +4xrcrrllzh9two6zgcftpfqj47 +six31two5fourthreeeight +gqhckrzrpltwo72znb4oneeight +trsxcpls3pmqqrskpmfivehdqrptvdtq +six3four87one +46two3 +9fiveseven57vhmq +jkrbkfsevencnvzp89vhmsdcfcthreetwonedrl +9cvzvqfboneffive6jmnpjkvrjz +82xrqjdqchdbvhxpninefourdhb +3bqsrf +fourtwosixsevensix9threesixthree +3fourkgjbxbpsrtgsmgrjthree +ndeightsevenfourtwo943 +471pn6 +bpstsix84four32 +gjkcq89ninegkckjpkz +eightkgvmxlzlhrnrdpttdqbthree117 +vtdnlkqcg65 +btwone727onesevensixkhbnkvtlthfjfive +twozspnzkssqseven413 +7nttlqthreenspcdrhdpn563 +six3nine +4twodkrlmssknsgfourkcfrxskpntnine +qgtgfxhfjj3pslzsttxpfive +fivethree9ct55sevensix +8twooneonesixjlszd1hlhbcgjf +fivetwosixsevenmrzjqjtfourmrk7two +pfnine6sevenone +3threex94znone96 +79two2sixeightqmnbxcxf8 +oneeight5 +763lsdvlz24threed +four9oneeighthdcrzqlnvxj6ninex +7552twojhv4 +3rzxhddcfxone553one9 +sixsix8 +7seven26k +86onethreenine1vlnmvghn +sevenglrmsnngpf3mfblll3seven +npdrbsxxpcpc3jzlpljsnlsrvdmvtr6one +6894one +rjzxs7 +7mllptmtwoqxrpgprvqrstmvvvvm +sixone12 +225 +dcjzmcnbpptwothreedzqctmhm4seven3qhnbn +oneone2six56jsmdjqcznjtwolcjvmpkxlj +2sevenseven +7cpnpkcqsstfourjthreenbzvrdgeightsevenhfnztth +4phcrvcgseven4njn4 +three9fiveninefdv +63ll +9sevenx7 +9fivehvtfdckjnpvk +gpkhmlrxs5two39 +kfvqv5oneonefiveonethree5five +2mrjctkmlks4z +8eightkrzkdxvrrjvtwo2 +fiveninesix9 +rhtnxkvthkpbqn4mtgtdnmmxmvmmzmcbt1 +mtwonexdljqqgbbnineqrgbqnqx7eight +fiveeight8sfvzbpkeights4 +8threesix8two8hszvhcbonefour +tpjtvpjgtnine2rbbfd +zrxjftfg4b6three37four +th5kktbzgmvkxhhcsqcrvtldnldml7seven +4txnqnplsixzptgszd +gzt5threefiveninetwoeightsevennine +jtfrlffv17268 +qfour9six +49vrbpqkkzct6 +14two +nine2drdcd7sixpfvsblcxqsjshhg +5onehfivefour8mnine +5qlthree6hbkktrpbmgninepqtxq +three8four +ftm67qrmsix +seightwoplhzgbvb7275 +qnqtbdmqd4 +onefive2lcrdjrzbheightthreegvc4three +87eight4fiveninefiveeight +1seven7eightfivezqcndfj5cmblgczd +seven6rkxsvbs529fbgbtclkjhcljpkjbgmvz +1twojxpxrgvvzq14ldngl9eight +qkg2fivemrlzlhxxzcmfive +one85four9six8eight +7sixbgvdf4841 +hktntngtlfflzrdpfourninevlzpdrngvchg2 +6two115 +fiveninesevenqxgjrnk3two +eightthree988nrclmr +2one6 +6737jfive +8four3 +4fivesvntkxfpnqhone94three +7six1twothsd86 +98pczqhlqbzjlvfnine68 +xtqtwoneeightlvcjqfourckfour2nine +9sixllhhqhfivemmoneeight9 +4czj3 +ggdlxrrxjl1jnndbgbdninesbcfhd2five3 +kszvbdfninethree5onevflrqffxmdonefour2 +1nkpmvbf75 +lnbgnkkfhseven5zfive2qcr +seven75xcx +2eightbzsp2pfg7eightv7 +fourone29 +4two5two9xcpkkjqxcfivessqqvhbbt +ncnqg1sixt9ninedlfgsqhnxx6 +xrlsktwodnbcbonefvxxqgbrsdthree3seven +klvsv73 +onezvbhrblrkzcrsevensix96jnpxjone +nine6chd4 +bdvkqlrh9eight6eightninehq7 +fivexpx1vsrreightkp7dph +3eightlrrlgck967 +xcntwone4633sixmkm1nine \ No newline at end of file diff --git a/input/day01_example.txt b/input/day01_example.txt new file mode 100644 index 0000000..1ba8437 --- /dev/null +++ b/input/day01_example.txt @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet \ No newline at end of file diff --git a/input/day01_example2.txt b/input/day01_example2.txt new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/input/day01_example2.txt @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen diff --git a/main.go b/main.go new file mode 100644 index 0000000..7b0d010 --- /dev/null +++ b/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "advent-of-code-2023-go/day01" + "advent-of-code-2023-go/utils" + "os" +) + +func main() { + + d := day() + input := utils.Readfile(d, false) + switch d { + case 1: + println("Day 1, part 1: ", day01.Part1(input)) + println("Day 1, part 1: ", day01.Part2(input)) + } +} + +func day() int { + latest := 1 + if len(os.Args) == 1 { + return latest + } + day := utils.MustAtoi(os.Args[1]) + return day +} diff --git a/utils/utils.go b/utils/utils.go new file mode 100644 index 0000000..5ca6a60 --- /dev/null +++ b/utils/utils.go @@ -0,0 +1,38 @@ +package utils + +import ( + "bufio" + "fmt" + "io" + "os" + "strconv" + "strings" +) + +func PanicOnErr(err error) { + if err != nil { + panic(err) + } +} + +func MustAtoi(s string) int { + v, err := strconv.Atoi(s) + PanicOnErr(err) + return v +} + +func Readfile(day int, example bool) string { + filename := fmt.Sprintf("input/day%02d.txt", day) + if example { + filename = fmt.Sprintf("input/day%02d_example.txt", day) + } + file, err := os.Open(filename) + PanicOnErr(err) + defer file.Close() + + reader := bufio.NewReader(file) + contents, err := io.ReadAll(reader) + PanicOnErr(err) + + return strings.TrimSuffix(string(contents), "\n") +}