Sorry, het is lelijk

Dit gaat au doen
This commit is contained in:
BasGremmen 2023-12-02 23:15:13 +01:00
parent f6b6ef9ccd
commit f677283d7e
2 changed files with 1083 additions and 0 deletions

83
Book_1.ipynb Normal file
View File

@ -0,0 +1,83 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"id": "12d018ab-1fa6-4403-b58f-188e27644d31",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"55834\n"
]
}
],
"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",
"numbers = [int(x) for x in numbers]\n",
"print(sum(numbers))\n"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "c7e92c53-f373-4894-b34f-ac06c15e87e7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"53221"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f = open('Puzzle_1_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",
"listing = []\n",
"for number_pair in numbers:\n",
" number_string = \"\"\n",
" for number in number_pair:\n",
" if number in l:\n",
" number_string += str(l.index(number) + 1)\n",
" else:\n",
" number_string += str(number)\n",
" listing.append(int(number_string))\n",
"\n",
"sum(listing)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

1000
Puzzle_1_1.txt Normal file

File diff suppressed because it is too large Load Diff