Power of Thor


For this puzzle, we want Thor to reach his light of power. All we have to do is compare Thor's coordinates with the position of its light of power and output the good direction.

C

#include <stdlib.h>
#include <stdio.h>

int main(int argc, char** argv) 
{
    // Coordinates of the light and Thor
    int lX, lY, tX, tY;
    scanf("%d%d%d%d", &lX, &lY, &tX, &tY);

    for (;;) {
        if (tY < lY) {
            printf("S");
            tY++;
        }
        else if (tY > lY) {
            printf("N");
            tY--;
        }

        if (tX < lX) {
            printf("E");
            tX++;
        }
        else if (tX > lX) {
            printf("W");
            tX--;
        }
        printf("\n");        
    }
    return EXIT_SUCCESS;
}
            

Java

import java.util.*;

class Player {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        /* We could store the coordinates of Thor and its target (4 vars)
           Or like here, store the difference target - Thor (2 vars)
           It is more efficient for comparisons and simpler*/
        int diffX = in.nextInt();
        int diffY = in.nextInt();
        diffX -= in.nextInt();
        diffY -= in.nextInt();

        while (true) {
            if (diffY > 0) {
                System.out.print("S");
                diffY--;
            }
            else if (diffY < 0) {
                System.out.print("N");
                diffY++;
            }

            if (diffX > 0) {
                System.out.print("E");
                diffX--;
            }
            else if (diffX < 0) {
                System.out.print("W");
                diffX++;
            }
            
            System.out.print("\n");
        }
    }
}
            

Python 3

# lX, lY: coordinates of the light of power
# tX, tY: Thor's coordinates
lX, lY, tX, tY = [int(i) for i in input().split()]

while (True):
    ch1 = ch2 = ""

    if tY < lY:
        ch1 = "S"
        tY+=1
    elif tY > lY:
        ch1 = "N"
        tY-=1

    if tX < lX:
        ch2 = "E"
        tX+=1
    elif tX > lX:
        ch2 = "W" 
        tX-=1
        
    print(ch1, ch2, sep="")