<commit_before>#!/usr/local/bin/python3

from collections import namedtuple

with open('../input/2015-03.txt') as f:
    instructions = f.read().rstrip()

Point = namedtuple('Point', ['x', 'y'])
location = Point(0, 0)
visited = {location}


def new_loc(current_loc, instruction):
    new_loc_table = {
        '^': (current_loc.x, current_loc.y + 1),
        'v': (current_loc.x, current_loc.y - 1),
        '>': (current_loc.x + 1, current_loc.y),
        '<': (current_loc.x - 1, current_loc.y)
        }
    return Point(*new_loc_table[instruction])


for char in instructions:
    location = new_loc(location, char)
    visited.add(location)

print('At least one present:', len(visited))


# Part two

santa_loc = Point(0, 0)
robo_loc = Point(0, 0)
visited = {santa_loc}

for idx, char in enumerate(instructions):
    if idx % 2 == 0:  # Santa
        santa_loc = new_loc(santa_loc, char)
        visited.add(santa_loc)
    else:  # robot
        robo_loc = new_loc(robo_loc, char)
        visited.add(robo_loc)

print('At least one present with santa and robot:', len(visited))<commit_msg>2015-03.py: Refactor into main function<commit_after>#!/usr/local/bin/python3

from collections import namedtuple
import pathlib


def main(puzzle_input):
    Point = namedtuple('Point', ['x', 'y'])
    location = Point(0, 0)
    visited = {location}

    def new_loc(current_loc, instruction):
        new_loc_table = {
            '^': (current_loc.x, current_loc.y + 1),
            'v': (current_loc.x, current_loc.y - 1),
            '>': (current_loc.x + 1, current_loc.y),
            '<': (current_loc.x - 1, current_loc.y)
            }
        return Point(*new_loc_table[instruction])

    for char in puzzle_input:
        location = new_loc(location, char)
        visited.add(location)

    print('At least one present:', len(visited))

    # Part two
    santa_loc = Point(0, 0)
    robo_loc = Point(0, 0)
    visited = {santa_loc}

    for idx, char in enumerate(puzzle_input):
        if idx % 2 == 0:  # Santa
            santa_loc = new_loc(santa_loc, char)
            visited.add(santa_loc)
        else:  # robot
            robo_loc = new_loc(robo_loc, char)
            visited.add(robo_loc)

    print('At least one present with santa and robot:', len(visited))


if __name__ == '__main__':
    puzzle_input = pathlib.Path('../input/2015-03.txt').read_text().rstrip()
    main(puzzle_input)
{'fraction_non_alphanumeric': 0.1398920713989207, 'fraction_numerical': 0.0182648401826484, 'mean_word_length': 2.807266982622433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3910975', 'n_tokens_mistral': 885, 'n_tokens_neox': 842, 'n_words': 189}