Kleine opruiming
This commit is contained in:
parent
f677283d7e
commit
970b0d885d
|
@ -1 +1,2 @@
|
|||
/.ipynb_checkpoints
|
||||
/.ipynb_checkpoints
|
||||
/data
|
129
Book_1.ipynb
129
Book_1.ipynb
|
@ -1,5 +1,47 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "d0b07b88-208c-4408-b9c4-ac9d42b5bad0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Vet mooi notebook van Bas"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5016996d-7e00-44a1-9553-8dd95b864662",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Laten we beginnen met de imports"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1e6ac084-5bf9-43f7-a7a6-8c8e20066159",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import re "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "8f3db4f3-92c2-4e2c-91a2-fe59b1109673",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Puzzel 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e76a322a-85e3-40b4-aa04-6f4dda2b7f40",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Deel 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
|
@ -15,7 +57,6 @@
|
|||
}
|
||||
],
|
||||
"source": [
|
||||
"import re \n",
|
||||
"f = open('Puzzle_1_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",
|
||||
|
@ -23,6 +64,14 @@
|
|||
"print(sum(numbers))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "00cbc4f3-d337-4702-bf25-d04717a1787b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Deel 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 35,
|
||||
|
@ -57,6 +106,84 @@
|
|||
"\n",
|
||||
"sum(listing)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "455fa9e3-535d-4708-b0fe-1179ad095f4c",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Puzzel 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "dedf36d2-0a24-45e2-90f7-889f1ca5da87",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Deel 1 & 2 tegelijk, oeps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "46f6cc4a-2be4-4b86-be2d-6e08404dc9ef",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"f = open('puzzle_2_2.txt', 'r')\n",
|
||||
"rows = []\n",
|
||||
"red = 12\n",
|
||||
"green = 13\n",
|
||||
"blue = 14\n",
|
||||
"for x in f:\n",
|
||||
" row = {}\n",
|
||||
" row['id'], row['content'] = x.split(':')\n",
|
||||
" row['id'] = int(re.findall('\\d+', row['id'])[0])\n",
|
||||
" row['counts'] = row['content'].split(';')\n",
|
||||
" listing = []\n",
|
||||
" maxes = {'red': 0, 'green': 0, 'blue': 0}\n",
|
||||
" for count in row['counts']:\n",
|
||||
" numbers = re.findall('\\d+', count)\n",
|
||||
" colors = re.findall('red|blue|green', count)\n",
|
||||
" for test_color, test_number in zip(colors, numbers):\n",
|
||||
" if maxes[test_color] < int(test_number):\n",
|
||||
" maxes[test_color] = int(test_number)\n",
|
||||
" listing.append(dict(zip(colors, numbers)))\n",
|
||||
" row['maxes'] = maxes\n",
|
||||
" row['counts'] = listing\n",
|
||||
" rows.append(row)\n",
|
||||
"\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "810e3c1a-af84-45e1-9508-a00c40523f7b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Naja hier pas de output"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "21a60b17-619f-426f-8617-5ff4352cca0c",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"count = 0\n",
|
||||
"count_2 = 0\n",
|
||||
"for row in rows:\n",
|
||||
" maxes = row['maxes']\n",
|
||||
" count_2 += maxes['red'] * maxes['blue'] * maxes['green']\n",
|
||||
" if red >= maxes['red'] and blue >= maxes['blue'] and green >= maxes['green']:\n",
|
||||
" count += row['id']\n",
|
||||
"print(count)\n",
|
||||
"print(count_2)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
1000
Puzzle_1_1.txt
1000
Puzzle_1_1.txt
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue