Added python solution for day 1
[advent-of-code-18.git] / src / advent01 / advent01.ipynb
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "metadata": {},
7 "outputs": [
8 {
9 "data": {
10 "text/plain": [
11 "[-16, 12, -18, -1, 5]"
12 ]
13 },
14 "execution_count": 1,
15 "metadata": {},
16 "output_type": "execute_result"
17 }
18 ],
19 "source": [
20 "changes = [int(l.strip()) for l in open('../../data/advent01.txt')]\n",
21 "changes[:5]"
22 ]
23 },
24 {
25 "cell_type": "code",
26 "execution_count": 2,
27 "metadata": {},
28 "outputs": [
29 {
30 "data": {
31 "text/plain": [
32 "472"
33 ]
34 },
35 "execution_count": 2,
36 "metadata": {},
37 "output_type": "execute_result"
38 }
39 ],
40 "source": [
41 "sum(changes)"
42 ]
43 },
44 {
45 "cell_type": "code",
46 "execution_count": 5,
47 "metadata": {},
48 "outputs": [
49 {
50 "data": {
51 "text/plain": [
52 "66932"
53 ]
54 },
55 "execution_count": 5,
56 "metadata": {},
57 "output_type": "execute_result"
58 }
59 ],
60 "source": [
61 "frequencies = set()\n",
62 "i = 0\n",
63 "current_frequency = 0\n",
64 "\n",
65 "while current_frequency not in frequencies:\n",
66 " frequencies.add(current_frequency)\n",
67 " current_frequency += changes[i]\n",
68 " i += 1\n",
69 " i %= len(changes)\n",
70 " \n",
71 "current_frequency "
72 ]
73 },
74 {
75 "cell_type": "code",
76 "execution_count": null,
77 "metadata": {},
78 "outputs": [],
79 "source": []
80 }
81 ],
82 "metadata": {
83 "kernelspec": {
84 "display_name": "Python 3",
85 "language": "python",
86 "name": "python3"
87 },
88 "language_info": {
89 "codemirror_mode": {
90 "name": "ipython",
91 "version": 3
92 },
93 "file_extension": ".py",
94 "mimetype": "text/x-python",
95 "name": "python",
96 "nbconvert_exporter": "python",
97 "pygments_lexer": "ipython3",
98 "version": "3.6.7"
99 }
100 },
101 "nbformat": 4,
102 "nbformat_minor": 2
103 }