Skip to content

Instantly share code, notes, and snippets.

@Micrified
Created December 2, 2024 23:30
Show Gist options
  • Save Micrified/7511974a2587df5a19e26a0bd7165b0d to your computer and use it in GitHub Desktop.
Save Micrified/7511974a2587df5a19e26a0bd7165b0d to your computer and use it in GitHub Desktop.
Puzzle 1, part B
package main
import (
"bufio"
"os"
"fmt"
)
func main() {
var i, j, sum int
ns, m, s := []int{}, map[int]int{}, bufio.NewScanner(os.Stdin)
for s.Scan() {
if n, _ := fmt.Sscanf(s.Text(), "%d %d", &i, &j); 2 == n {
ns = append(ns, i)
m[j]++
}
}
for _, n := range(ns) {
sum += n * m[n]
}
fmt.Printf("%d\n", sum)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment