Tried to code this in my sophomore and freshman year, gave up because it was difficult.