day1: python
This commit is contained in:
parent
669879932e
commit
f5eb38de9c
12
01/README.md
Normal file
12
01/README.md
Normal file
@ -0,0 +1,12 @@
|
||||
# [Day X](https://adventofcode.com/2022/day/X)
|
||||
:gift:
|
||||
|
||||
Today's language: **Python**
|
||||
|
||||
Both tasks are solved in one hell of a oneliner each:
|
||||
- Task 1: 153 characters / line
|
||||
- Task 2: 363 characters / line
|
||||
|
||||
```shell
|
||||
p day01.py
|
||||
```
|
6
01/day01.py
Normal file
6
01/day01.py
Normal file
@ -0,0 +1,6 @@
|
||||
import re
|
||||
# part 1
|
||||
with open("input.txt", "r") as file: print("Part 1:", sum([int(match[0]+match[-1]) for match in [re.findall(r"\d", line) for line in file.readlines()]]))
|
||||
|
||||
# part 2 use lookahead in findall to get two matches one, two for "twone"
|
||||
with open("input.txt", "r") as file: print(sum([int("".join([conv[0],conv[-1]])) for conv in [(lambda x : [ str(n.index(y) + 1) if y in n else y for y,n in zip(x, [['one','two','three','four','five','six','seven','eight','nine'] for _ in range(len(x))])])(re.findall(r"(?=(one|two|three|four|five|six|seven|eight|nine|\d))",line)) for line in file.readlines()]]))
|
7
01/example.txt
Normal file
7
01/example.txt
Normal file
@ -0,0 +1,7 @@
|
||||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
1000
01/input.txt
Normal file
1000
01/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user