diff --git a/2021/02/README.md b/2021/02/README.md new file mode 100644 index 0000000..64ef9e3 --- /dev/null +++ b/2021/02/README.md @@ -0,0 +1,11 @@ +# 02 + +Description + +
+ Solutions +
    +
  1. 1670340
  2. +
  3. 1954293920
  4. +
+
diff --git a/2021/02/input.txt b/2021/02/input.txt new file mode 100644 index 0000000..2e0b532 --- /dev/null +++ b/2021/02/input.txt @@ -0,0 +1,1001 @@ +forward 2 +down 7 +down 8 +forward 9 +down 8 +forward 9 +forward 8 +down 3 +forward 8 +forward 5 +up 2 +down 9 +down 4 +forward 4 +forward 3 +down 8 +down 9 +forward 5 +down 1 +up 1 +forward 4 +up 5 +forward 2 +down 6 +forward 9 +forward 3 +forward 7 +down 6 +down 1 +forward 8 +down 3 +forward 1 +up 6 +down 1 +down 2 +forward 9 +down 7 +down 1 +down 7 +down 7 +up 5 +down 8 +forward 6 +up 8 +up 2 +forward 6 +up 1 +down 9 +forward 8 +forward 4 +up 3 +forward 7 +down 2 +down 8 +forward 5 +down 9 +up 4 +forward 7 +forward 5 +down 5 +down 5 +forward 3 +forward 2 +down 2 +up 4 +up 7 +down 8 +up 8 +forward 1 +up 4 +forward 4 +down 2 +forward 5 +forward 7 +down 4 +forward 8 +down 2 +forward 5 +forward 9 +forward 6 +forward 5 +down 5 +forward 4 +forward 3 +down 7 +down 8 +forward 9 +forward 7 +down 3 +down 6 +forward 4 +down 7 +up 9 +down 8 +up 7 +up 3 +forward 6 +forward 9 +down 2 +down 3 +down 1 +down 3 +forward 8 +forward 3 +forward 9 +down 5 +up 1 +up 2 +down 9 +up 9 +down 5 +down 9 +forward 1 +down 3 +down 5 +down 1 +forward 7 +down 6 +forward 7 +forward 4 +up 2 +up 1 +forward 9 +down 2 +down 6 +down 5 +down 6 +forward 8 +down 5 +forward 1 +forward 2 +down 7 +down 5 +down 7 +up 9 +down 9 +up 4 +down 7 +up 8 +down 9 +forward 3 +down 6 +down 2 +forward 9 +down 4 +up 7 +forward 3 +down 5 +forward 8 +forward 9 +down 2 +up 5 +forward 2 +forward 9 +up 5 +down 2 +forward 8 +forward 6 +down 7 +down 3 +forward 4 +forward 3 +forward 9 +up 4 +up 4 +forward 7 +up 3 +forward 6 +down 7 +up 8 +forward 2 +up 1 +down 6 +forward 4 +up 6 +up 6 +up 3 +forward 4 +forward 2 +forward 5 +forward 8 +down 9 +down 4 +down 3 +down 1 +down 6 +down 4 +down 5 +down 7 +down 5 +up 4 +forward 3 +down 4 +down 7 +down 7 +down 2 +forward 2 +forward 9 +up 6 +down 3 +up 9 +forward 8 +down 9 +up 2 +up 2 +up 2 +up 1 +down 6 +forward 9 +forward 2 +forward 2 +forward 2 +forward 5 +up 3 +down 7 +down 6 +down 8 +up 3 +up 9 +down 3 +forward 1 +forward 7 +down 7 +down 1 +forward 3 +down 7 +down 9 +down 7 +down 3 +up 2 +down 6 +up 6 +down 1 +up 2 +forward 7 +up 2 +down 7 +up 2 +down 9 +down 3 +forward 6 +down 5 +down 1 +forward 5 +down 2 +down 6 +down 1 +down 3 +down 3 +down 5 +forward 2 +forward 4 +forward 8 +forward 6 +forward 4 +forward 9 +up 8 +down 5 +forward 1 +down 1 +forward 1 +forward 6 +up 1 +down 6 +down 3 +forward 9 +forward 5 +forward 4 +up 3 +up 7 +down 2 +up 4 +up 2 +down 1 +forward 6 +forward 9 +forward 4 +forward 2 +down 8 +forward 4 +forward 3 +up 5 +down 4 +forward 3 +down 8 +down 5 +down 5 +forward 1 +forward 6 +forward 4 +forward 5 +forward 9 +forward 5 +down 4 +forward 3 +forward 8 +down 8 +down 1 +up 4 +down 4 +up 7 +forward 2 +forward 6 +down 3 +down 5 +down 5 +down 8 +up 3 +down 2 +forward 4 +forward 2 +forward 4 +forward 9 +up 2 +down 7 +up 7 +down 2 +forward 4 +up 7 +forward 4 +down 2 +forward 7 +up 2 +down 3 +forward 5 +down 7 +down 2 +up 2 +up 1 +up 7 +up 9 +down 3 +forward 1 +forward 3 +down 2 +down 3 +forward 6 +down 7 +forward 9 +down 9 +forward 3 +forward 2 +down 1 +up 9 +down 4 +forward 4 +up 4 +forward 7 +up 3 +down 4 +down 9 +down 3 +forward 7 +down 6 +down 7 +down 6 +up 5 +forward 3 +forward 9 +up 2 +up 4 +up 9 +down 2 +forward 5 +up 1 +down 7 +down 5 +up 2 +forward 8 +down 8 +up 3 +forward 4 +down 9 +forward 6 +down 9 +down 5 +forward 6 +down 8 +up 6 +down 3 +forward 6 +forward 3 +down 3 +down 5 +down 7 +down 1 +down 5 +down 7 +down 5 +forward 3 +down 2 +forward 4 +up 4 +up 1 +up 7 +forward 1 +forward 5 +down 4 +down 8 +down 3 +forward 4 +down 3 +up 7 +down 6 +forward 9 +up 8 +forward 2 +forward 5 +down 6 +up 4 +forward 8 +forward 5 +down 6 +forward 2 +down 7 +forward 3 +forward 1 +forward 6 +down 9 +up 6 +down 4 +down 2 +up 8 +forward 4 +down 8 +forward 8 +up 9 +forward 7 +down 6 +up 9 +down 4 +up 6 +down 4 +down 3 +up 7 +up 4 +forward 5 +up 9 +down 9 +up 6 +down 3 +forward 8 +down 9 +forward 7 +up 3 +up 9 +forward 8 +down 3 +forward 3 +forward 5 +down 6 +forward 3 +down 4 +up 6 +forward 3 +forward 7 +down 1 +down 6 +down 4 +forward 6 +up 6 +down 5 +down 6 +down 4 +up 2 +down 7 +down 9 +down 2 +down 6 +forward 3 +forward 4 +down 5 +up 5 +down 5 +forward 3 +forward 6 +down 4 +down 7 +up 2 +forward 7 +down 7 +up 6 +up 3 +forward 9 +forward 8 +up 6 +forward 2 +down 2 +forward 8 +forward 4 +up 6 +forward 6 +down 8 +up 3 +up 5 +forward 6 +up 8 +down 1 +down 4 +up 9 +forward 6 +up 5 +down 6 +down 8 +down 9 +forward 5 +up 3 +down 7 +forward 3 +forward 6 +down 3 +down 1 +down 9 +up 9 +down 4 +down 7 +forward 2 +forward 4 +down 7 +forward 7 +up 5 +down 9 +up 7 +down 4 +forward 6 +down 5 +forward 4 +up 8 +down 4 +down 7 +forward 3 +down 6 +down 1 +forward 3 +down 4 +up 6 +up 5 +up 7 +forward 5 +down 4 +forward 7 +up 1 +down 4 +forward 4 +down 2 +down 6 +forward 1 +up 3 +up 8 +forward 6 +forward 6 +down 5 +forward 7 +down 6 +down 8 +forward 6 +down 6 +forward 3 +forward 5 +down 9 +down 5 +up 4 +down 5 +down 1 +forward 1 +forward 5 +down 2 +forward 5 +forward 2 +forward 5 +up 3 +forward 5 +up 8 +forward 9 +forward 3 +down 2 +up 2 +forward 7 +down 5 +up 1 +down 3 +down 7 +up 2 +forward 8 +forward 6 +forward 1 +forward 6 +forward 6 +down 5 +forward 4 +down 5 +forward 9 +forward 7 +down 7 +down 7 +down 9 +forward 4 +down 4 +forward 3 +down 6 +forward 5 +down 9 +forward 6 +up 7 +down 3 +up 4 +up 4 +down 1 +down 2 +up 5 +forward 6 +forward 2 +down 7 +up 6 +up 3 +down 8 +forward 1 +down 3 +up 9 +down 2 +forward 6 +forward 1 +forward 4 +up 1 +down 8 +down 2 +down 9 +down 5 +forward 3 +down 1 +down 6 +down 5 +down 3 +forward 1 +forward 9 +up 2 +down 3 +down 3 +down 9 +down 7 +forward 6 +forward 8 +forward 4 +up 7 +down 2 +forward 3 +forward 1 +up 4 +forward 8 +up 9 +forward 8 +forward 2 +down 5 +forward 2 +down 6 +down 6 +down 4 +forward 8 +down 6 +forward 2 +forward 8 +down 7 +down 6 +forward 2 +down 1 +down 8 +forward 2 +forward 9 +up 6 +forward 6 +down 3 +down 2 +up 5 +up 6 +down 6 +up 7 +forward 5 +forward 7 +down 1 +forward 7 +forward 9 +down 3 +forward 4 +forward 5 +down 1 +up 3 +forward 2 +up 5 +forward 2 +forward 1 +down 5 +down 4 +down 8 +up 8 +forward 3 +down 3 +forward 4 +down 6 +up 8 +down 5 +up 2 +down 1 +up 3 +forward 8 +up 6 +forward 9 +up 9 +down 5 +forward 2 +forward 9 +up 6 +forward 1 +down 2 +forward 4 +forward 4 +forward 1 +forward 5 +forward 1 +forward 4 +down 5 +down 1 +down 2 +down 2 +forward 7 +down 7 +down 7 +down 4 +down 7 +down 4 +down 3 +up 7 +up 1 +forward 2 +forward 3 +down 4 +down 5 +forward 9 +up 7 +forward 6 +down 1 +forward 6 +forward 6 +forward 8 +down 3 +forward 2 +down 6 +forward 9 +up 6 +up 6 +forward 7 +down 5 +down 6 +up 3 +down 5 +up 4 +forward 3 +down 7 +forward 9 +up 1 +down 1 +up 6 +down 3 +up 2 +down 5 +forward 3 +forward 6 +down 9 +down 4 +forward 7 +down 1 +up 1 +forward 3 +forward 5 +up 7 +down 3 +up 9 +up 9 +down 4 +up 4 +forward 8 +up 9 +down 8 +forward 6 +forward 4 +forward 9 +forward 8 +down 2 +forward 3 +forward 2 +down 3 +up 1 +forward 6 +down 3 +down 7 +down 3 +down 5 +down 9 +up 9 +forward 8 +forward 6 +down 8 +forward 3 +down 4 +down 2 +down 9 +forward 4 +forward 2 +up 4 +forward 1 +up 8 +up 1 +down 4 +up 2 +down 1 +up 7 +down 2 +down 4 +up 4 +forward 2 +down 3 +forward 2 +forward 3 +down 5 +forward 9 +forward 7 +down 1 +up 3 +down 3 +forward 3 +down 6 +forward 5 +up 3 +up 3 +up 1 +forward 7 +forward 1 +forward 2 +forward 2 +down 4 +up 7 +forward 1 +forward 1 +forward 6 +down 8 +up 8 +down 8 +down 4 +down 6 +forward 8 +forward 4 +forward 5 +down 2 +down 3 +forward 7 +down 6 +forward 4 +forward 1 +up 7 +up 5 +up 2 +forward 1 +forward 8 +forward 2 +up 9 +forward 4 +forward 5 +down 2 +forward 5 +forward 7 +down 3 +forward 1 +down 3 +up 5 +up 2 +up 2 +up 2 +forward 4 +forward 4 +forward 8 +forward 2 +down 3 +up 7 +down 4 +down 2 +down 7 +forward 2 +down 2 +forward 7 +up 9 +up 7 +forward 7 +forward 7 +down 3 +down 4 +up 4 +down 2 +down 8 +forward 4 +down 1 +up 6 +forward 4 +down 2 +up 8 +down 1 +down 8 +down 6 +up 9 +forward 4 +up 1 +down 2 +down 9 +down 7 +down 4 +down 8 +down 8 +up 1 +down 5 +up 5 +down 7 +up 7 +forward 5 +down 3 +forward 7 +up 5 +down 3 +forward 9 +up 5 +down 7 +forward 8 +forward 8 +down 2 +forward 7 +forward 8 +down 4 +up 7 +down 2 +up 7 +forward 5 +down 1 +down 3 +forward 9 +up 4 +forward 6 +forward 4 +down 5 +down 7 +forward 2 +forward 4 +down 2 +forward 1 +down 5 +up 2 +down 8 +down 1 +down 4 +down 8 +down 6 +forward 9 +forward 2 +forward 6 +forward 4 +down 1 +forward 8 +up 4 +forward 6 +down 4 +forward 4 +forward 3 +forward 6 +forward 9 +forward 8 +down 1 +forward 5 +down 8 +forward 7 +up 1 +down 3 +up 6 +forward 5 +forward 8 +forward 8 +forward 5 +forward 5 +forward 1 +up 9 +forward 7 +up 3 +down 2 +down 4 +forward 6 +up 2 +forward 5 +up 8 +forward 8 +forward 2 +forward 6 +forward 3 +up 4 +forward 3 +forward 6 + diff --git a/2021/02/python/main.py b/2021/02/python/main.py new file mode 100644 index 0000000..642ace6 --- /dev/null +++ b/2021/02/python/main.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +from os.path import join, dirname + +# Day 01 + +# Common + + +def read_input(filename): + data = join(dirname(__file__), '..', filename) + with open(data) as f: + return f.read() + + +# 1 + +class submarine: + def __init__(self, with_aim=False): + self.distance = 0 + self.depth = 0 + self.aim = 0 + self.with_aim = with_aim + + def execute(self, instruction: str): + op, x = instruction.split(' ') + x = int(x) + if op == 'forward': + if self.with_aim: + self.distance += x + self.depth += x * self.aim + else: + self.distance += x + elif op == 'up': + if self.with_aim: + self.aim -= x + else: + self.depth -= x + elif op == 'down': + if self.with_aim: + self.aim += x + else: + self.depth += x + + def execute_instructions(self, instructions: str): + for instruction in instructions.strip().split('\n'): + self.execute(instruction) + + def get_current_position(self): + return self.distance * self.depth + + +test = read_input('test.txt') +sub = submarine() +sub.execute_instructions(test) +print(f"Test: {sub.get_current_position()}") + +data = read_input('input.txt') +sub = submarine() +sub.execute_instructions(data) +print(f"Part 1: {sub.get_current_position()}") + +# 2 + + +sub = submarine(with_aim=True) +sub.execute_instructions(test) +print(f"Test: {sub.get_current_position()}") + +sub = submarine(with_aim=True) +sub.execute_instructions(data) +print(f"Part 2: {sub.get_current_position()}") diff --git a/2021/02/test.txt b/2021/02/test.txt new file mode 100644 index 0000000..b7172ac --- /dev/null +++ b/2021/02/test.txt @@ -0,0 +1,6 @@ +forward 5 +down 5 +forward 8 +up 3 +down 8 +forward 2