Added python solution for day 1
authorNeil Smith <neil.git@njae.me.uk>
Mon, 3 Dec 2018 10:56:03 +0000 (10:56 +0000)
committerNeil Smith <neil.git@njae.me.uk>
Mon, 3 Dec 2018 10:56:03 +0000 (10:56 +0000)
src/advent01/advent01.ipynb [new file with mode: 0644]

diff --git a/src/advent01/advent01.ipynb b/src/advent01/advent01.ipynb
new file mode 100644 (file)
index 0000000..0904728
--- /dev/null
@@ -0,0 +1,103 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "[-16, 12, -18, -1, 5]"
+      ]
+     },
+     "execution_count": 1,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "changes = [int(l.strip()) for l in open('../../data/advent01.txt')]\n",
+    "changes[:5]"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "472"
+      ]
+     },
+     "execution_count": 2,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "sum(changes)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "66932"
+      ]
+     },
+     "execution_count": 5,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "frequencies = set()\n",
+    "i = 0\n",
+    "current_frequency = 0\n",
+    "\n",
+    "while current_frequency not in frequencies:\n",
+    "    frequencies.add(current_frequency)\n",
+    "    current_frequency += changes[i]\n",
+    "    i += 1\n",
+    "    i %= len(changes)\n",
+    "    \n",
+    "current_frequency    "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "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.6.7"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}