I want to find the minimum distance between any 2 values in a list. However, I need the minimum distance considering both 'clockwise' and 'anticlockwise' movement.
For example, I have the list [0, 4, 5, 6, 3, 1]. Say I want the distance between the pair (4,1)
Moving 'clockwise' the result is obviously 4 considering the difference in index. However, If one moves 'anti-clockwise' and considers the list connected, so 0 is a neighbour to 1. The distance would be 2, which is the result I want.
How can I achieve this?
I thought about joining the lists.
[0, 4, 5, 6, 3, 1, 0, 4, 5, 6, 3, 1]
However, then there are duplicates and I'm not sure how one would choose between these.
How can I achieve this?- Seems you have defined what you want to accomplish. Start by writing down in words discrete things you might need to do to accomplish it; then sit back, look at those things, and organize them in a logical sequence; attempt to translate each discrete step into code, sometimes it helps to make functions; run your first attempt step by step - either with pencil and paper pretending you are the interpreter or with a debugger (if you are not using an ide you should get one); assess your attempt; adjust; repeat.