Add 2021 day 1

It's good to be back to AoC again :D

Signed-off-by: AKU <tom@tdpain.net>
This commit is contained in:
akp 2021-12-01 07:40:35 +00:00
parent 12ea75d380
commit 157f959bd8
No known key found for this signature in database
GPG key ID: AA5726202C8879B7
4 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,15 @@
# [Day 1: Sonar Sweep](https://adventofcode.com/2021/day/1)
```
➜ adventOfCode git:(master) go run github.com/codemicro/adventOfCode/runtime -y 2021
Selecting year 2021
Automatically selecting day 1 (Sonar Sweep)
? Which implementation do you want to use? Python
Running...
Test 1.0: pass in 0.0000 seconds
Test 2.0: pass in 0.0000 seconds
Part 1: <answer> in 0.0005 seconds
Part 2: <answer> in 0.0008 seconds
```

View file

@ -0,0 +1,17 @@
{
"inputFile": "input.txt",
"testCases": {
"one": [
{
"input": "199\n200\n208\n210\n200\n207\n240\n269\n260\n263",
"expected": "7"
}
],
"two": [
{
"input": "199\n200\n208\n210\n200\n207\n240\n269\n260\n263",
"expected": "5"
}
]
}
}

View file

@ -0,0 +1,28 @@
from typing import List, Any
from aocpy import BaseChallenge
def parse(instr: str) -> List[int]:
return [int(x) for x in instr.splitlines() if x != ""]
class Challenge(BaseChallenge):
@staticmethod
def one(instr: str) -> int:
data = parse(instr)
c = 0
for i in range(1, len(data)):
if data[i] > data[i-1]:
c += 1
return c
@staticmethod
def two(instr: str) -> int:
data = parse(instr)
c = 0
sums = [sum(data[i:i+3]) for i in range(len(data)-2)]
for i in range(1, len(sums)):
if sums[i] > sums[i-1]:
c += 1
return c

View file

@ -10,5 +10,6 @@ Solutions to the [2021 Advent of Code](https://adventofcode.com/2021).
| Day | | Python | Go | Notes |
| ----------------------------------- | ------------------ | ---------------------------------------- | ------------------------------------ | -------------------- |
| 01 - Sonar Sweep | Complete | [Link](01-sonarSweet/py) | | |
<!-- PARSE END -->