Skip to content

Commit 4221735

Browse files
committed
Day 11 (first part attempt - incomplete)
1 parent cbf4000 commit 4221735

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

2022/day11/test-input

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Monkey 0:
2+
Starting items: 79, 98
3+
Operation: new = old * 19
4+
Test: divisible by 23
5+
If true: throw to monkey 2
6+
If false: throw to monkey 3
7+
8+
Monkey 1:
9+
Starting items: 54, 65, 75, 74
10+
Operation: new = old + 6
11+
Test: divisible by 19
12+
If true: throw to monkey 2
13+
If false: throw to monkey 0
14+
15+
Monkey 2:
16+
Starting items: 79, 60, 97
17+
Operation: new = old * old
18+
Test: divisible by 13
19+
If true: throw to monkey 1
20+
If false: throw to monkey 3
21+
22+
Monkey 3:
23+
Starting items: 74
24+
Operation: new = old + 3
25+
Test: divisible by 17
26+
If true: throw to monkey 0
27+
If false: throw to monkey 1

2022/day11/test.py

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
with open('test-input') as t:
2+
data = t.read()
3+
4+
def list_of_lists(length):
5+
list = []
6+
for x in range(0, length):
7+
list.append([])
8+
return list
9+
10+
monkeys = []
11+
for monkey in data.split('\n\n'):
12+
monkeys.append(monkey.split('\n'))
13+
14+
15+
rounds = 20
16+
inspections = []
17+
for x in range(0, len(monkeys)):
18+
inspections.append(0)
19+
for r in range(0, rounds):
20+
mks = list_of_lists(len(monkeys))
21+
for monkey in monkeys:
22+
m = monkey[2].split(' ')
23+
inspections[int(monkey[0].split(' ')[-1].strip(':'))] += len(monkey[1].split(':')[1].split(', '))
24+
if monkey[1].split(':')[1].split(', ') != ['']:
25+
for item in monkey[1].split(':')[1].split(', '):
26+
if m[-1].isdigit() and m[-3] == 'old':
27+
if m[-2] == '+':
28+
worry = int(item)+int(m[-1])
29+
elif m[-2] == '*':
30+
worry = int(item)*int(m[-1])
31+
elif m[-1] == 'old' and m[-3] == 'old':
32+
worry = int(item)*int(item)
33+
# worry = round(worry/3)
34+
worry = int(str(worry/3).split('.')[0])
35+
"""
36+
if worry%int(monkey[3].split(' ')[-1]) == 0:
37+
if monkeys[int(monkey[4].split(' ')[-1])][1].split(':')[1] == '':
38+
monkeys[int(monkey[4].split(' ')[-1])][1] += str(worry)
39+
else:
40+
monkeys[int(monkey[4].split(' ')[-1])][1] +=', '+str(worry)
41+
else:
42+
if monkeys[int(monkey[5].split(' ')[-1])][1].split(':')[1] == '':
43+
monkeys[int(monkey[5].split(' ')[-1])][1] += str(worry)
44+
else:
45+
monkeys[int(monkey[5].split(' ')[-1])][1] +=', '+str(worry)
46+
"""
47+
if worry%int(monkey[3].split(' ')[-1]) == 0:
48+
mks[int(monkey[4].split(' ')[-1])].append(worry)
49+
else:
50+
mks[int(monkey[5].split(' ')[-1])].append(worry)
51+
# i += 1
52+
# inspections[int(monkey[0].split(' ')[-1].strip(':'))] += i
53+
monkey[1] = monkey[1].split(':')[0]+':'
54+
55+
for monkey in range(0, len(monkeys)):
56+
if mks[monkey] != []:
57+
if monkeys[monkey][1].split(':')[-1] != '':
58+
monkeys[monkey][1].split(':')[-1] += ', '
59+
for k in range(0, len(mks[monkey])):
60+
monkeys[monkey][1] += str(mks[monkey][k])
61+
if k+1 != len(mks[monkey]):
62+
monkeys[monkey][1] += ', '
63+
64+
65+
"""
66+
for m in range(0, len(mks)):
67+
print(m)
68+
if monkeys[int(monkeys[m][2].split(' ')[-1])][1].split(':')[1] != '':
69+
monkeys[int(monkeys[m][2].splot(' ')[-1])][1] += ', '
70+
for k in range(0, len(mks[m])):
71+
monkeys += str(mks[m][k])
72+
if k+1 != len(mks[m]):
73+
monkeys += ', '
74+
"""
75+
76+
print(inspections)

0 commit comments

Comments
 (0)