From 147602a52f61ab13e8843973ed6539b01a31b64c Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Tue, 27 Dec 2022 14:27:31 -0600 Subject: [PATCH] 2022 day 25 complete --- 2022/day25/input | 124 +++++++++++++++++++++++++++++++++++++++++++ 2022/day25/main.go | 50 +++++++++++++++++ 2022/day25/testinput | 13 +++++ 3 files changed, 187 insertions(+) create mode 100644 2022/day25/input create mode 100644 2022/day25/main.go create mode 100644 2022/day25/testinput diff --git a/2022/day25/input b/2022/day25/input new file mode 100644 index 0000000..547e6b0 --- /dev/null +++ b/2022/day25/input @@ -0,0 +1,124 @@ +21-0==1=-0 +102211-220011----- +1=2=111=10=- +12-2=022=2 +1=--=11 +12-2211000=0011-0- +1=1- +2=0-10-=21-2 +1210- +2=1-= +1=0=12=2112--11= +2--211=200 +20-02-20 +12=12=0=0=1 +22===21=-0102-012= +1--=-121 +1=02=2-= +12-0-20 +2=---=0102--00=22 +1=2==0=2= +11-1112 +2--012 +12=12=--212-0-==-02 +1=220 +20===1 +2210-02=12-022-=1- +22--1-==1 +211-1=1=0-==1 +10 +1-1-02 +1=-2==-0=21 +1=102 +20121021 +1=2=22=001200-==1020 +10211-1-20--10-1= +1222==1--=1--11-= +11211211 +1=101-20= +1=1-11=0=000 +1=-=101 +2 +1000-2 +1==0=210=1=21222-=2 +1=1==2- +2--020=2=2===- +2- +2=0 +222101=22=-21=11 +2= +121201-0-20-2-=11= +10= +1212=20=2=-=-1--1 +2-20-=212=01 +1=1--00--0=12=-00 +22-- +22 +22===1=-0-22- +111-= +2-111=0021=2 +200=22-=12-2= +1==-=1=0 +1--=02-0002= +1=-=2-2=2- +2=2222220=2==001 +1=00==11=-20-=2-2 +1---0=-= +1-0==10-=22001 +1=02=02-1=0111 +1-=010-21-=21==02 +10200-2=-=20120-2 +1=- +10=122- +210-1=-=2011-0--1 +2==-1=20 +1=-=101-20=221-1 +210 +1-=-==-0-=02=--- +1-=1=-=12=0 +1-=0---12-0= +210-==1021=010=1 +1=-212 +11=1=-=2211=101222- +2=-==--=2 +1=11-200--= +1120- +11=-0=221=0101= +11-1=- +1-12-2=0 +1012-22=1- +20-122=-1= +1-100=0=101-0 +20-1=1=0 +1102= +21 +10=20=11 +1-=2001 +1-20=12-0221102-== +1-1--010100=-1= +221002==2102-2=1 +2012=121-22 +110222002=01 +212102-1=1=-211 +210-=12 +1=-1-0101=1-12 +12--21=1 +10=-12 +100-122211=--2= +101102001 +11011=- +211-0=-=0 +1-2=01-1= +1-022-=00000 +2==-0==2=--00= +10=--2000== +1---=--1-110-02 +11-012 +2==-2210-0 +212 +22-=-12111 +2--= +2=2=12-100 +10-12===0- +1==0=0=22012201 +211-1--22 diff --git a/2022/day25/main.go b/2022/day25/main.go new file mode 100644 index 0000000..28d9f7d --- /dev/null +++ b/2022/day25/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "math" + + h "git.bullercodeworks.com/brian/adventofcode/helpers" +) + +func main() { + inp := h.StdinToStringSlice() + part1(inp) +} + +func part1(inp []string) { + var v int + for i := range inp { + v = v + SNAFUToDec(inp[i]) + } + fmt.Println("# Part 1") + fmt.Println(DecToSNAFU(v)) +} + +func SNAFUToDec(inp string) int { + var res int + var place float64 + for i := len(inp) - 1; i >= 0; i-- { + var v int + if inp[i] == '-' { + v = -1 + } else if inp[i] == '=' { + v = -2 + } else { + v = int(inp[i] - '0') + } + v = v * int(math.Pow(5, place)) + place++ + res = res + v + } + return res +} + +func DecToSNAFU(v int) string { + var res string + for v > 0 { + res = string("=-012"[(v+2)%5]) + res + v = (v + 2) / 5 + } + return res +} diff --git a/2022/day25/testinput b/2022/day25/testinput new file mode 100644 index 0000000..027aeec --- /dev/null +++ b/2022/day25/testinput @@ -0,0 +1,13 @@ +1=-0-2 +12111 +2=0= +21 +2=01 +111 +20012 +112 +1=-1= +1-12 +12 +1= +122