Created
December 2, 2024 23:30
-
-
Save Micrified/7511974a2587df5a19e26a0bd7165b0d to your computer and use it in GitHub Desktop.
Puzzle 1, part B
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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