diff --git a/2020/day14.go b/2020/day14.go new file mode 100644 index 0000000..694d834 --- /dev/null +++ b/2020/day14.go @@ -0,0 +1,160 @@ +package main + +import ( + "fmt" + "log" + "os" + "regexp" + "strconv" + + "git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils" +) + +type Instruction struct { + Op string + Value0 int64 // address for mem, zeromask for mask + Value1 int64 // value for mem, onemask for mask +} + +func makeMask(input string, maskType byte) int64 { + var mask int64 + for i := 0; i < len(input); i++ { + index := len(input) - 1 - i + if input[index] == maskType { + mask = mask | (int64(1) << i) + } + } + + return mask & 0xfffffffff +} + +func applyFloatMask(address int64, mask int64) []int64 { + results := make([]int64, 0) + results = append(results, address) + + for i := 0; i < 36; i++ { + if mask&(1<