3rd: remove redundancy

This commit is contained in:
Daniel Aberger
2021-12-06 10:17:06 +01:00
parent 77ed7aeeb7
commit 2136bc59e4
+6 -20
View File
@@ -17,32 +17,18 @@ func Run() {
} }
func calcOxygen(values [][]int) int { func calcOxygen(values [][]int) int {
valueStore := make([][][]int, 0) return calcOxygenOrCO2(values, false)
valueStore = append(valueStore, values)
for i := 0; i < len(values[0]); i++ {
commonValues := getCommonValues(valueStore[i], false)
newValues := make([][]int, 0)
for _, v := range valueStore[i] {
if v[i] == commonValues[i] {
newValues = append(newValues, v)
}
}
valueStore = append(valueStore, newValues)
if len(newValues) == 1 {
break
}
}
return convertToDecimal(valueStore[len(valueStore)-1][0])
} }
func calcCO2(values [][]int) int { func calcCO2(values [][]int) int {
return calcOxygenOrCO2(values, true)
}
func calcOxygenOrCO2(values [][]int, getCO2 bool) int {
valueStore := make([][][]int, 0) valueStore := make([][][]int, 0)
valueStore = append(valueStore, values) valueStore = append(valueStore, values)
for i := 0; i < len(values[0]); i++ { for i := 0; i < len(values[0]); i++ {
commonValues := getCommonValues(valueStore[i], true) commonValues := getCommonValues(valueStore[i], getCO2)
newValues := make([][]int, 0) newValues := make([][]int, 0)
for _, v := range valueStore[i] { for _, v := range valueStore[i] {
if v[i] == commonValues[i] { if v[i] == commonValues[i] {