Skip to content

Commit 28d7caa

Browse files
author
Lukas Gabriel
committed
Add 2015 Day 10 and 2015 Day 11 (WIP)
1 parent 7aa226f commit 28d7caa

File tree

10 files changed

+175
-1
lines changed

10 files changed

+175
-1
lines changed

2015/10/2015_10.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# --- Day 10: Elves Look, Elves Say ---
2+
3+
## --- Part One ---
4+
5+
Today, the Elves are playing a game called look-and-say. They take turns making sequences by reading aloud the previous sequence and using that reading as the next sequence. For example, 211 is read as "one two, two ones", which becomes 1221 (1 2, 2 1s).
6+
7+
Look-and-say sequences are generated iteratively, using the previous value as input for the next step. For each step, take the previous value, and replace each run of digits (like 111) with the number of digits (3) followed by the digit itself (1).
8+
9+
For example:
10+
11+
```text
12+
1 becomes 11 (1 copy of digit 1).
13+
11 becomes 21 (2 copies of digit 1).
14+
21 becomes 1211 (one 2 followed by one 1).
15+
1211 becomes 111221 (one 1, one 2, and two 1s).
16+
111221 becomes 312211 (three 1s, two 2s, and one 1).
17+
Starting with the digits in your puzzle input, apply this process 40 times. What is the length of the result?
18+
```
19+
20+
## --- Part Two ---
21+
22+
Neat, right? You might also enjoy hearing John Conway talking about this sequence (that's Conway of Conway's Game of Life fame).
23+
24+
Now, starting again with the digits in your puzzle input, apply this process 50 times. What is the length of the new result?

2015/10/2015_10.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3113322113

2015/10/2015_10_01.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Advent of Code 2015, Day 10: Elves Look, Elves Say. Part 1
2+
# https://adventofcode.com/2015/day/10
3+
4+
5+
def main():
6+
ITERATIONS = 40
7+
8+
input = open("./2015/10/2015_10.txt", "r", encoding="utf-8").readline().strip()
9+
10+
output = ""
11+
counter = 1
12+
for _ in range(ITERATIONS):
13+
output = ""
14+
for i in range(len(input)):
15+
if i < len(input) - 1 and input[i] == input[i + 1]:
16+
counter += 1
17+
else:
18+
output += str(counter) + input[i]
19+
counter = 1
20+
input = output
21+
22+
23+
return f"The length of the ouput is {len(output)}."
24+
25+
26+
if __name__ == "__main__":
27+
print(main())

2015/10/2015_10_02.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Advent of Code 2015, Day 10: Elves Look, Elves Say. Part 2
2+
# https://adventofcode.com/2015/day/10#part2
3+
4+
5+
def main():
6+
ITERATIONS = 50
7+
8+
input = open("./2015/10/2015_10.txt", "r", encoding="utf-8").readline().strip()
9+
10+
output = ""
11+
counter = 1
12+
for _ in range(ITERATIONS):
13+
output = ""
14+
for i in range(len(input)):
15+
if i < len(input) - 1 and input[i] == input[i + 1]:
16+
counter += 1
17+
else:
18+
output += str(counter) + input[i]
19+
counter = 1
20+
input = output
21+
22+
23+
return f"The length of the ouput is {len(output)}."
24+
25+
26+
if __name__ == "__main__":
27+
print(main())

2015/11/2015_11.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# --- Day 11: Corporate Policy ---
2+
3+
## --- Part One ---
4+
5+
Santa's previous password expired, and he needs help choosing a new one.
6+
7+
To help him remember his new password after the old one expires, Santa has devised a method of coming up with a password based on the previous one. Corporate policy dictates that passwords must be exactly eight lowercase letters (for security reasons), so he finds his new password by incrementing his old password string repeatedly until it is valid.
8+
9+
Incrementing is just like counting with numbers: `xx`, `xy`, `xz`, `ya`, `yb`, and so on. Increase the rightmost letter one step; if it was `z`, it wraps around to `a`, and repeat with the next letter to the left until one doesn't wrap around.
10+
11+
Unfortunately for Santa, a new Security-Elf recently started, and he has imposed some additional password requirements:
12+
13+
Passwords must include one increasing straight of at least three letters, like `abc`, `bcd`, `cde`, and so on, up to `xyz`. They cannot skip letters; `abd` doesn't count.
14+
Passwords may not contain the letters `i`, `o`, or `l`, as these letters can be mistaken for other characters and are therefore confusing.
15+
Passwords must contain at least two different, non-overlapping pairs of letters, like `aa`, `bb`, or `zz`.
16+
17+
For example:
18+
19+
- `hijklmmn` meets the first requirement (because it contains the straight `hij`) but fails the second requirement requirement (because it contains `i` and `l`).
20+
- `abbceffg` meets the third requirement (because it repeats `bb` and `ff`) but fails the first requirement.
21+
- `abbcegjk` fails the third requirement, because it only has one double letter (`bb`).
22+
- The next password after `abcdefgh` is `abcdffaa`.
23+
- The next password after `ghijklmn` is `ghjaabcc`, because you eventually skip all the passwords that start with `ghi..`., since `i` is not allowed.
24+
25+
Given Santa's current password (your puzzle input), what should his next password be?
26+
27+
## --- Part Two ---

2015/11/2015_11.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hepxcrrq

2015/11/2015_11_01.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Advent of Code 2015, 11: Corporate Policy. Part 1
2+
# https://adventofcode.com/2015/day/11
3+
4+
5+
def increment_password(password) -> str:
6+
password = list(password)
7+
i = len(password) - 1
8+
while i >= 0:
9+
if password[i] == "z":
10+
password[i] = "a"
11+
i -= 1
12+
else:
13+
password[i] = chr(ord(password[i]) + 1)
14+
break
15+
return password
16+
17+
18+
def password_is_ok(password) -> bool:
19+
if "i" in password or "o" in password or "l" in password:
20+
return False
21+
# ...
22+
return
23+
24+
25+
def main():
26+
solution = ""
27+
28+
input = open("./2015/10/2015_11.txt", "r", encoding="utf-8").readline().strip()
29+
30+
31+
return f"The new password is {solution}."
32+
33+
34+
if __name__ == "__main__":
35+
print(main())

2015/9/2015_09.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# --- Day 9: All in a Single Night ---
22

3+
## --- Part One ---
4+
35
Every year, Santa manages to deliver all of his presents in a single night.
46

57
This year, however, he has some new locations to visit; his elves have provided him the distances between every pair of locations. He can start and end at any two (different) locations he wants, but he must visit each location exactly once. What is the shortest distance he can travel to achieve this?

2023/1/2023_01.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,25 @@ treb7uchet
2424
In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142.
2525

2626
Consider your entire calibration document. What is the sum of all of the calibration values?
27+
28+
29+
# --- Part Two ---
30+
31+
Your calculation isn't quite right. It looks like some of the digits are actually spelled out with letters: one, two, three, four, five, six, seven, eight, and nine also count as valid "digits".
32+
33+
Equipped with this new information, you now need to find the real first and last digit on each line. For example:
34+
35+
```text
36+
two1nine
37+
eightwothree
38+
abcone2threexyz
39+
xtwone3four
40+
4nineeightseven2
41+
zoneight234
42+
7pqrstsixteen
43+
```
44+
45+
In this example, the calibration values are 29, 83, 13, 24, 42, 14, and 76. Adding these together produces 281.
46+
47+
What is the sum of all of the calibration values?
48+

2023/1/2023_01_02.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,19 @@
55
import re
66

77

8+
DIGITS = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
9+
10+
811
def main():
912
solution = 0
10-
13+
1114
for line in open("./2023/1/2023_01.txt", "r", encoding="utf-8"):
1215
digits = re.findall(r"\d", line)
16+
17+
print(line)
18+
for n, digit in enumerate(DIGITS):
19+
print(re.findall(DIGITS[n], line))
20+
1321
solution += int("".join(digits[0] + digits[-1]))
1422

1523
return f"The sum of all values is {solution}"

0 commit comments

Comments
 (0)