parent
970b0d885d
commit
d2454b4675
29
Book_1.ipynb
29
Book_1.ipynb
|
@ -18,7 +18,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 1,
|
||||
"id": "1e6ac084-5bf9-43f7-a7a6-8c8e20066159",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -44,7 +44,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 2,
|
||||
"id": "12d018ab-1fa6-4403-b58f-188e27644d31",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
@ -57,7 +57,7 @@
|
|||
}
|
||||
],
|
||||
"source": [
|
||||
"f = open('Puzzle_1_1.txt', 'r')\n",
|
||||
"f = open('data/puzzle_1.txt', 'r')\n",
|
||||
"digits = [re.findall('\\d', line) for line in f]\n",
|
||||
"numbers = [str(digit[0]) + str(digit[-1]) for digit in digits]\n",
|
||||
"numbers = [int(x) for x in numbers]\n",
|
||||
|
@ -74,7 +74,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 35,
|
||||
"execution_count": 3,
|
||||
"id": "c7e92c53-f373-4894-b34f-ac06c15e87e7",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
@ -84,13 +84,13 @@
|
|||
"53221"
|
||||
]
|
||||
},
|
||||
"execution_count": 35,
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"f = open('Puzzle_1_1.txt', 'r')\n",
|
||||
"f = open('data/puzzle_1.txt', 'r')\n",
|
||||
"l = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']\n",
|
||||
"digits = [re.findall('(?=(\\d|'+'|'.join(l)+'))', line) for line in f]\n",
|
||||
"numbers = [[digit[0],digit[-1]] for digit in digits]\n",
|
||||
|
@ -125,12 +125,12 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 4,
|
||||
"id": "46f6cc4a-2be4-4b86-be2d-6e08404dc9ef",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"f = open('puzzle_2_2.txt', 'r')\n",
|
||||
"f = open('data/puzzle_2.txt', 'r')\n",
|
||||
"rows = []\n",
|
||||
"red = 12\n",
|
||||
"green = 13\n",
|
||||
|
@ -169,10 +169,19 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"id": "21a60b17-619f-426f-8617-5ff4352cca0c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"3035\n",
|
||||
"66027\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"count = 0\n",
|
||||
"count_2 = 0\n",
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
# Vet mooi notebook van Bas
|
||||
|
||||
Laten we beginnen met de imports
|
||||
|
||||
|
||||
```python
|
||||
import re
|
||||
```
|
||||
|
||||
## Puzzel 1
|
||||
|
||||
### Deel 1
|
||||
|
||||
|
||||
```python
|
||||
f = open('data/puzzle_1.txt', 'r')
|
||||
digits = [re.findall('\d', line) for line in f]
|
||||
numbers = [str(digit[0]) + str(digit[-1]) for digit in digits]
|
||||
numbers = [int(x) for x in numbers]
|
||||
print(sum(numbers))
|
||||
|
||||
```
|
||||
|
||||
55834
|
||||
|
||||
|
||||
### Deel 2
|
||||
|
||||
|
||||
```python
|
||||
f = open('data/puzzle_1.txt', 'r')
|
||||
l = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
|
||||
digits = [re.findall('(?=(\d|'+'|'.join(l)+'))', line) for line in f]
|
||||
numbers = [[digit[0],digit[-1]] for digit in digits]
|
||||
listing = []
|
||||
for number_pair in numbers:
|
||||
number_string = ""
|
||||
for number in number_pair:
|
||||
if number in l:
|
||||
number_string += str(l.index(number) + 1)
|
||||
else:
|
||||
number_string += str(number)
|
||||
listing.append(int(number_string))
|
||||
|
||||
sum(listing)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
53221
|
||||
|
||||
|
||||
|
||||
## Puzzel 2
|
||||
|
||||
### Deel 1 & 2 tegelijk, oeps
|
||||
|
||||
|
||||
```python
|
||||
f = open('data/puzzle_2.txt', 'r')
|
||||
rows = []
|
||||
red = 12
|
||||
green = 13
|
||||
blue = 14
|
||||
for x in f:
|
||||
row = {}
|
||||
row['id'], row['content'] = x.split(':')
|
||||
row['id'] = int(re.findall('\d+', row['id'])[0])
|
||||
row['counts'] = row['content'].split(';')
|
||||
listing = []
|
||||
maxes = {'red': 0, 'green': 0, 'blue': 0}
|
||||
for count in row['counts']:
|
||||
numbers = re.findall('\d+', count)
|
||||
colors = re.findall('red|blue|green', count)
|
||||
for test_color, test_number in zip(colors, numbers):
|
||||
if maxes[test_color] < int(test_number):
|
||||
maxes[test_color] = int(test_number)
|
||||
listing.append(dict(zip(colors, numbers)))
|
||||
row['maxes'] = maxes
|
||||
row['counts'] = listing
|
||||
rows.append(row)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
### Naja hier pas de output
|
||||
|
||||
|
||||
```python
|
||||
count = 0
|
||||
count_2 = 0
|
||||
for row in rows:
|
||||
maxes = row['maxes']
|
||||
count_2 += maxes['red'] * maxes['blue'] * maxes['green']
|
||||
if red >= maxes['red'] and blue >= maxes['blue'] and green >= maxes['green']:
|
||||
count += row['id']
|
||||
print(count)
|
||||
print(count_2)
|
||||
```
|
||||
|
||||
3035
|
||||
66027
|
||||
|
Loading…
Reference in New Issue