aboutsummaryrefslogtreecommitdiff
path: root/2019/06/puzzle-1.awk
blob: e694b4d2a4744cf98a0b07f068aafd605aa98e1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/awk -f

function norbits(o)
{
	if (o in memo)
		return memo[o]
	return memo[o] = 1 + norbits(orbits[o])
}

BEGIN {
	FS = ")"
	memo["COM"] = 0
}

{ orbits[$2] = $1 }

END {
	for (o in orbits)
		n += norbits(o)
	print n
}