-1

I am trying to make a program that determines if something is the clockwise direction or counterclockwise direction based on string input that only contains north south east west (n s e w) for example, if I had the string "NESSWN" I know it is clockwise because of drawing it out but I can't figure out a definitive solution applicable to every case for it no matter how hard I think. Below is all the code I've tried so far.

n=int(input())

for i in range(n):
    path=input()
    finds=path.find("S")
    findn=path.find("N")
    findw=path.find("W")
    finde=path.find("E")
    rfindw=path.rfind("W")
    rfinde=path.rfind("E")
    
    
        
    if finde<findw and rfindw>rfinde:
        print("CCW")
    if finde<findw and rfinde>rfindw:
        print("CW")
    if findw<finde and rfinde>rfindw:
        print("CW")
    if findw<finde and rfindw>rfinde:
        print("CCW")

2EP
  • 1
  • 1
  • 1
    Please share the code that you have tried so far. – Rima Feb 28 '21 at 01:22
  • 1
    What about `NESSWNE`? That's still clockwise. So is `NESSWNW` for that matter, if the `NW` transition is 270 degrees clockwise rather than 90 counter-clockwise. – paxdiablo Feb 28 '21 at 01:33

1 Answers1

0

Pay attention to the first direction you go in, and then the second direction. You can use if statements to code separate scenarios for each first direction.

If North is first:

If west is next: Counterclockwise Else Clockwise

If east is first:

If north is next: Clockwose Else counterclockwise

You get the idea