package main import ( "aoc2024/helper" "fmt" "sort" ) type list struct { a []int b []int } func main() { list_a, list_b := helper.ReadLinesTwoIntSlices() list := list{a: list_a, b: list_b} // part 1 distance := list.distance() fmt.Printf("Distance: %v\n", distance) // part 2 similarity := list.similarity() fmt.Printf("Similarity: %v\n", similarity) } func (l list) distance() (dist int) { sort.Ints(l.a) sort.Ints(l.b) for i := range l.a { dist += helper.Abs(l.a[i] - l.b[i]) } return dist } func (l list) similarity() (sim int) { for _, val := range l.a { valcount := countIntInSlice(l.b, val) sim += valcount * val } return sim } func countIntInSlice(lst []int, i int) (count int) { for _, val := range lst { if val == i { count++ } } return count }