Dit duurde echt niet lang ofzo
This commit is contained in:
parent
08bd33e765
commit
8754a1036b
58
Book_1.ipynb
58
Book_1.ipynb
|
@ -18,13 +18,15 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": 240,
|
||||
"id": "1e6ac084-5bf9-43f7-a7a6-8c8e20066159",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import re \n",
|
||||
"import numpy as np"
|
||||
"import numpy as np\n",
|
||||
"from functools import reduce\n",
|
||||
"from math import factorial"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -469,10 +471,60 @@
|
|||
"# just sum the total cards at the end\n",
|
||||
"print(sum(copies_of_card))\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" \n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "bdaf4568-5996-493b-9d9b-398b5e16f522",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# AANSCHOUW!!!!!\n",
|
||||
"Het wonder, het fantastischste ding ooit, oneliners"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 302,
|
||||
"id": "091f006e-838e-418b-8282-610cc6fadccc",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"21568"
|
||||
]
|
||||
},
|
||||
"execution_count": 302,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"reduce(lambda total, multipliers: (total + 2**(multipliers-1) if (multipliers > 0) else total) ,map(lambda numbers: len(numbers)-len(set(numbers)), [re.findall('(?:(\\d+)\\s|\\n)', line) for line in open('data/puzzle_4.txt')]), 0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 400,
|
||||
"id": "cdbdddfb-c0e4-4f9b-8b6c-4dd561c6236a",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"11827296"
|
||||
]
|
||||
},
|
||||
"execution_count": 400,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"sum([y for (x,y) in reduce(lambda total, cards: total + [(cards[0], 1)] + [(card, 1+sum([total_card[1] for total_card in total if total_card[0] == cards[0]])) for card in cards[1]], enumerate([j+1+i for j in range(len(re.findall(r'(?:\\b(\\d+)\\s)(?=.*\\s\\1\\b)', line)))] for i, line in enumerate(open('data/puzzle_4.txt'))), [])])"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
|
@ -6,6 +6,8 @@ Laten we beginnen met de imports
|
|||
```python
|
||||
import re
|
||||
import numpy as np
|
||||
from functools import reduce
|
||||
from math import factorial
|
||||
```
|
||||
|
||||
## Puzzel 1
|
||||
|
@ -298,10 +300,36 @@ for i, card_id in enumerate(card_numbers):
|
|||
# just sum the total cards at the end
|
||||
print(sum(copies_of_card))
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
|
||||
11827296
|
||||
|
||||
|
||||
# AANSCHOUW!!!!!
|
||||
Het wonder, het fantastischste ding ooit, oneliners
|
||||
|
||||
|
||||
```python
|
||||
reduce(lambda total, multipliers: (total + 2**(multipliers-1) if (multipliers > 0) else total) ,map(lambda numbers: len(numbers)-len(set(numbers)), [re.findall('(?:(\d+)\s|\n)', line) for line in open('data/puzzle_4.txt')]), 0)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
21568
|
||||
|
||||
|
||||
|
||||
|
||||
```python
|
||||
sum([y for (x,y) in reduce(lambda total, cards: total + [(cards[0], 1)] + [(card, 1+sum([total_card[1] for total_card in total if total_card[0] == cards[0]])) for card in cards[1]], enumerate([j+1+i for j in range(len(re.findall(r'(?:\b(\d+)\s)(?=.*\s\1\b)', line)))] for i, line in enumerate(open('data/puzzle_4.txt'))), [])])
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
11827296
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue