feat: P2 solution using pairwise comparison
This commit is contained in:
@@ -2,6 +2,7 @@ package daytwo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"advent-of-code/internal/registry"
|
"advent-of-code/internal/registry"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -47,3 +48,34 @@ func PartOne(data []string) int {
|
|||||||
|
|
||||||
return countWithTwo * countWithThree
|
return countWithTwo * countWithThree
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PartTwo(data []string) int {
|
||||||
|
for idx := range data {
|
||||||
|
for otherIdx := idx + 1; otherIdx < len(data); otherIdx++ {
|
||||||
|
if data[idx] == "" || data[otherIdx] == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
differenceCount := 0
|
||||||
|
differingPosition := -1
|
||||||
|
|
||||||
|
if len(data[idx]) != len(data[otherIdx]) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for position := 0; position < len(data[idx]); position++ {
|
||||||
|
if data[idx][position] != data[otherIdx][position] {
|
||||||
|
differenceCount++
|
||||||
|
differingPosition = position
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if differenceCount == 1 {
|
||||||
|
common := data[idx][:differingPosition] + data[idx][differingPosition+1:]
|
||||||
|
fmt.Println(common)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user