Something very similar was my first programming project in college! The easiest method that most of us did was to brute force it and see if the ends were in the same location and angled correctly. Apparently there was a O(n) method that uses discrete mathematics but I didn’t really
understand it at the time. It really is a great puzzle to solve.