Skip to content

Instantly share code, notes, and snippets.

@johannes-jansson
Created December 1, 2019 17:48
Show Gist options
  • Save johannes-jansson/7ee3ba3484103c861702b968cc4a01a4 to your computer and use it in GitHub Desktop.
Save johannes-jansson/7ee3ba3484103c861702b968cc4a01a4 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import math\n",
"fuel = 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(\"input\", \"r\") as f:\n",
" modules = [int(x) for x in f.read().split(\"\\n\")[0:-1]]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for module in modules:\n",
" while module > 8:\n",
" module = math.floor(module/3) - 2\n",
" fuel += module"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(fuel)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment