<commit_before>__author__ = 'boltz_j'

directions = "NESW"

def parse_input_file(filename):
    # Open the input file
    file = open(filename)

    # Read the first line and get the size of the board
    line = file.readline()
    x, y = map(int, line.split(' '))

    line = file.readline()
    while line:

        # Get the Robot position
        x_, y_, direction = line.split()
        print(int(x_), int(y_), directions.find(direction))

        line = file.readline()

        if line:
            # Add commands to robot
            print("robot commands : ", line)

            robot = Robot(int(x_), int(y_), directions.find(direction), line)
            robot.action()
        line = file.readline()


class Robot:
    def __init__(self, x, y, direction, command):
        self.x = x
        self.y = y
        self.direction = direction
        self.command = command
        self.cmd_index = 0

    def action(self):
        # Get command
        cmd = self.command[self.cmd_index]
        self.cmd_index += 1

        print(cmd)



directions = "NESW"

parse_input_file('test_input.txt')<commit_msg>Question2 v1<commit_after>__author__ = 'boltz_j'

directions = "NESW"

def parse_input_file(filename):
    # Open the input file
    file = open(filename)

    # Read the first line and get the size of the board
    line = file.readline()
    x, y = map(int, line.split(' '))

    line = file.readline()
    while line:

        # Get the Robot position
        x_, y_, direction = line.split()
        robot = Robot(int(x_), int(y_), directions.find(direction))

        # Read commands
        line = file.readline()
        if line:
            # Give commands to the robot
            robot.action(line)

        line = file.readline()


class Robot:
    def __init__(self, x, y, direction):
        self.x = x
        self.y = y
        self.direction = direction

    def action(self, command):
        # Iterate on every char
        for cmd in command:
            if cmd == "L":
                self.left()

            elif cmd == "R":
                self.right()

            elif cmd == "M":
                self.move()

        print(self.x, self.y, directions[self.direction])

    def left(self):
        self.direction = (self.direction + 3) % 4

    def right(self):
        self.direction = (self.direction + 1) % 4

    def move(self):
        # North
        if self.direction == 0:
            self.y += 1
        # East
        elif self.direction == 1:
            self.x += 1
        # South
        elif self.direction == 2:
            self.y -= 1
        # West
        elif self.direction == 3:
            self.x -= 1


parse_input_file('test_input.txt')
{'fraction_non_alphanumeric': 0.11378799110452187, 'fraction_numerical': 0.005930318754633061, 'mean_word_length': 1.773895169578623, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3051820', 'n_tokens_mistral': 853, 'n_tokens_neox': 814, 'n_words': 230}