Skip to content
Snippets Groups Projects
Commit 2a2c5d6c authored by BoB's avatar BoB
Browse files

Renaming of file day_7

parent 02e7a932
Branches
Tags
No related merge requests found
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
......@@ -35,34 +21,48 @@
},
{
"cell_type": "code",
"source": [
"# part 2 (in part 1 skip last case in return statement)\n",
"def solve(x, s, target):\n",
" if not x or s > target: return s == target\n",
" return solve(x[1:], s + x[0], target) or solve(x[1:], s * x[0], target) or solve(x[1:], int(str(s) + str(x[0])), target)\n",
"\n",
"sum(target for target, elements in zip(*readdata('input07.txt')) if solve(elements[1:], elements[0], target))"
],
"execution_count": 16,
"metadata": {
"id": "n41e8HbQgZ7R",
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "n41e8HbQgZ7R",
"outputId": "aca2ad7d-3dcb-400f-99a3-8719bfa8917e"
},
"execution_count": 16,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"162987117690649"
]
},
"execution_count": 16,
"metadata": {},
"execution_count": 16
"output_type": "execute_result"
}
],
"source": [
"# part 2 (in part 1 skip last case in return statement)\n",
"def solve(x, s, target):\n",
" if not x or s > target: return s == target\n",
" return solve(x[1:], s + x[0], target) or solve(x[1:], s * x[0], target) or solve(x[1:], int(str(s) + str(x[0])), target)\n",
"\n",
"sum(target for target, elements in zip(*readdata('input07.txt')) if solve(elements[1:], elements[0], target))"
]
}
]
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment