From: Neil Smith Date: Mon, 3 Dec 2018 10:56:03 +0000 (+0000) Subject: Added python solution for day 1 X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-18.git;a=commitdiff_plain;h=fdcf61ea8c709fb16adec57e32ad444256f0233f Added python solution for day 1 --- diff --git a/src/advent01/advent01.ipynb b/src/advent01/advent01.ipynb new file mode 100644 index 0000000..0904728 --- /dev/null +++ b/src/advent01/advent01.ipynb @@ -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 +}