Today’s problem has us calculating antinodes of cell towers.
As per use you can find the solutions discussed below on my github.
Part A
The Problem
There are a litany of cell towers in the north pole.
We must calculate and find all the antinodes.
Antinodes are points collinear to two towers that are one distance d away from either tower where d is the distance between the towers.
We need to return the number of spaces in the map covered by antinodes.
The Solution
The goal is to read, parse, process, and print.
It’s day 8; you know the drill.
In the map there is more than one kind of cell tower, so we can separate them for processing.
Then we need to process them.
We need to process every pair, but the processing is communitive so only once.
We can do that by processing like so:
The last part of the process is to project it.
I changed my major enough in college to have done some vector math.
So we project like so:
# an1 = t1 + c
*
*
*
o t1
/^
a / .
/ . c = a - b
/ .
+----o t2
b *
*
*
*
# an2 = t2 - c
The Full Solution
This comes together like so:
Part B
The Twist
The twist is that instead of two antinodes as above, the antinodes go on forever.
We are still to calc and count them.
How we Adapt
If you know Haskell, I’m sure there’s some cool lazy iterator solution for this that will return what you need.
I just increased the expansion from 1 to 50 on each side.
It worked like a charm and took my about 30 seconds to implement.
The best application you’ll write is the one that ships.