diff --git a/MisterBiggs/advent-of-code-2019/Day 1/input.txt b/MisterBiggs/advent-of-code-2019/Day 1/input.txt new file mode 100644 index 000000000..4f9f8bb5b --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 1/input.txt @@ -0,0 +1,100 @@ +116860 +130144 +79347 +120725 +137692 +139037 +72089 +133224 +102168 +100679 +122298 +132969 +109196 +85162 +66316 +68461 +87608 +108091 +71061 +85477 +97748 +105766 +141169 +94553 +98932 +134376 +69822 +104858 +102584 +59682 +52092 +105784 +144100 +83695 +130436 +105447 +133102 +82770 +68684 +103878 +136774 +71462 +96828 +74743 +127523 +124145 +148013 +103862 +80052 +74095 +130394 +125589 +137576 +111299 +69311 +63144 +119014 +136084 +94348 +109511 +102493 +117791 +76202 +138442 +72724 +104579 +80285 +56847 +145460 +132255 +58264 +60460 +98995 +63343 +51207 +133619 +126155 +130707 +105010 +104589 +128527 +67715 +71823 +82517 +74115 +135483 +82230 +127410 +128969 +140127 +59133 +145973 +109430 +103608 +113203 +133402 +123971 +71761 +114178 +52940 -- 2.51.2 From dc1f80f7460abd00aaf92eeeb1232adb48c8fa06 Mon Sep 17 00:00:00 2001 From: Anson Date: Sun, 1 Dec 2019 18:37:46 -0700 Subject: [PATCH 02/17] day 1 complete --- .../advent-of-code-2019/Day 1/input.txt | 2 +- .../advent-of-code-2019/Day 1/rocket_eq.ipynb | 68 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb diff --git a/MisterBiggs/advent-of-code-2019/Day 1/input.txt b/MisterBiggs/advent-of-code-2019/Day 1/input.txt index 4f9f8bb5b..06e37eb05 100644 --- a/MisterBiggs/advent-of-code-2019/Day 1/input.txt +++ b/MisterBiggs/advent-of-code-2019/Day 1/input.txt @@ -97,4 +97,4 @@ 123971 71761 114178 -52940 +52940 \ No newline at end of file diff --git a/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb new file mode 100644 index 000000000..24aae8f3d --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb @@ -0,0 +1,68 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": { + "language_info": { + "name": "python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "version": "3.7.2" + }, + "orig_nbformat": 2, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3 + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "outputs": [], + "source": [ + "--- Day 1: The Tyranny of the Rocket Equation ---\n", + "Santa has become stranded at the edge of the Solar System while delivering presents to other planets! To accurately calculate his position in space, safely align his warp drive, and return to Earth in time to save Christmas, he needs you to bring him measurements from fifty stars.\n", + "\n", + "Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!\n", + "\n", + "The Elves quickly load you into a spacecraft and prepare to launch.\n", + "\n", + "At the first Go / No Go poll, every Elf is Go until the Fuel Counter-Upper. They haven't determined the amount of fuel required yet.\n", + "\n", + "Fuel required to launch a given module is based on its mass. Specifically, to find the fuel required for a module, take its mass, divide by three, round down, and subtract 2.\n", + "\n", + "For example:\n", + "\n", + "For a mass of 12, divide by 3 and round down to get 4, then subtract 2 to get 2.\n", + "For a mass of 14, dividing by 3 and rounding down still yields 4, so the fuel required is also 2.\n", + "For a mass of 1969, the fuel required is 654.\n", + "For a mass of 100756, the fuel required is 33583.\n", + "The Fuel Counter-Upper needs to know the total fuel requirement. To find it, individually calculate the fuel needed for the mass of each module (your puzzle input), then add together all the fuel values.\n", + "\n", + "What is the sum of the fuel requirements for all of the modules on your spacecraft?" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "3415695\n" + } + ], + "source": [ + "with open(\"C:\\Coding\\Advent Of Code 2019\\Day 1\\input.txt\") as input:\n", + " masses = list(map(int, input.read().split(\"\\n\")))\n", + " fuel = sum([mass // 3 - 2 for mass in masses])\n", + " print(fuel)" + ] + } + ] +} \ No newline at end of file -- 2.51.2 From 5743fe79ad36ac350b703b77bbc60bc86a3cf4cc Mon Sep 17 00:00:00 2001 From: Anson Date: Sun, 1 Dec 2019 18:38:30 -0700 Subject: [PATCH 03/17] cleaned code a little --- MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb index 24aae8f3d..42c0a8cd1 100644 --- a/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb +++ b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 1, "metadata": {}, "outputs": [ { @@ -59,10 +59,17 @@ ], "source": [ "with open(\"C:\\Coding\\Advent Of Code 2019\\Day 1\\input.txt\") as input:\n", - " masses = list(map(int, input.read().split(\"\\n\")))\n", + " masses = (map(int, input.read().split(\"\\n\")))\n", " fuel = sum([mass // 3 - 2 for mass in masses])\n", " print(fuel)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ] } \ No newline at end of file -- 2.51.2 From 6e5f1a68232387191b04f999e28d0829518cd653 Mon Sep 17 00:00:00 2001 From: Anson Date: Sun, 1 Dec 2019 19:00:41 -0700 Subject: [PATCH 04/17] part 2 complete --- .../advent-of-code-2019/Day 1/rocket_eq.ipynb | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb index 42c0a8cd1..ebf548dfe 100644 --- a/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb +++ b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -59,11 +59,55 @@ ], "source": [ "with open(\"C:\\Coding\\Advent Of Code 2019\\Day 1\\input.txt\") as input:\n", - " masses = (map(int, input.read().split(\"\\n\")))\n", + " masses = list(map(int, input.read().split(\"\\n\")))\n", " fuel = sum([mass // 3 - 2 for mass in masses])\n", " print(fuel)" ] }, + { + "cell_type": "markdown", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "--- Part Two ---\n", + "During the second Go / No Go poll, the Elf in charge of the Rocket Equation Double-Checker stops the launch sequence. Apparently, you forgot to include additional fuel for the fuel you just added.\n", + "\n", + "Fuel itself requires fuel just like a module - take its mass, divide by three, round down, and subtract 2. However, that fuel also requires fuel, and that fuel requires fuel, and so on. Any mass that would require negative fuel should instead be treated as if it requires zero fuel; the remaining mass, if any, is instead handled by wishing really hard, which has no mass and is outside the scope of this calculation.\n", + "\n", + "So, for each module mass, calculate its fuel and add it to the total. Then, treat the fuel amount you just calculated as the input mass and repeat the process, continuing until a fuel requirement is zero or negative. For example:\n", + "\n", + "A module of mass 14 requires 2 fuel. This fuel requires no further fuel (2 divided by 3 and rounded down is 0, which would call for a negative fuel), so the total fuel required is still just 2.\n", + "At first, a module of mass 1969 requires 654 fuel. Then, this fuel requires 216 more fuel (654 / 3 - 2). 216 then requires 70 more fuel, which requires 21 fuel, which requires 5 fuel, which requires no further fuel. So, the total fuel required for a module of mass 1969 is 654 + 216 + 70 + 21 + 5 = 966.\n", + "The fuel required by a module of mass 100756 and its fuel is: 33583 + 11192 + 3728 + 1240 + 411 + 135 + 43 + 12 + 2 = 50346.\n", + "What is the sum of the fuel requirements for all of the modules on your spacecraft when also taking into account the mass of the added fuel? (Calculate the fuel requirements for each module separately, then add them all up at the end.)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "5120654\n" + } + ], + "source": [ + "def actual_fuel(mass):\n", + " fuel = mass // 3 - 2\n", + " if fuel >= 0:\n", + " return fuel + actual_fuel(fuel)\n", + " else:\n", + " return 0\n", + "\n", + "fuel_total = 0\n", + "for mass in masses:\n", + " fuel_total += actual_fuel(mass)\n", + "print(fuel_total)" + ] + }, { "cell_type": "code", "execution_count": null, -- 2.51.2 From 7be3fbfb17baa1b3d908aba71e33a61347c784d8 Mon Sep 17 00:00:00 2001 From: Anson Date: Sun, 1 Dec 2019 19:01:43 -0700 Subject: [PATCH 05/17] cleaned up notebook --- MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb | 7 ------- 1 file changed, 7 deletions(-) diff --git a/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb index ebf548dfe..a5d67842c 100644 --- a/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb +++ b/MisterBiggs/advent-of-code-2019/Day 1/rocket_eq.ipynb @@ -107,13 +107,6 @@ " fuel_total += actual_fuel(mass)\n", "print(fuel_total)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ] } \ No newline at end of file -- 2.51.2 From 5af6eb22f4dd2496bb2855e572c7fa050577ca99 Mon Sep 17 00:00:00 2001 From: Anson Date: Sun, 1 Dec 2019 22:29:44 -0700 Subject: [PATCH 06/17] mess that is part 1 working --- .../advent-of-code-2019/Day 2/input.txt | 1 + .../Day 2/program_alarm.ipynb | 96 +++++++++++++++++++ .../Day 2/program_alarm.py | 25 +++++ 3 files changed, 122 insertions(+) create mode 100644 MisterBiggs/advent-of-code-2019/Day 2/input.txt create mode 100644 MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb create mode 100644 MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py diff --git a/MisterBiggs/advent-of-code-2019/Day 2/input.txt b/MisterBiggs/advent-of-code-2019/Day 2/input.txt new file mode 100644 index 000000000..480e46aa7 --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 2/input.txt @@ -0,0 +1 @@ +1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,9,1,19,1,19,5,23,1,23,5,27,2,27,10,31,1,31,9,35,1,35,5,39,1,6,39,43,2,9,43,47,1,5,47,51,2,6,51,55,1,5,55,59,2,10,59,63,1,63,6,67,2,67,6,71,2,10,71,75,1,6,75,79,2,79,9,83,1,83,5,87,1,87,9,91,1,91,9,95,1,10,95,99,1,99,13,103,2,6,103,107,1,107,5,111,1,6,111,115,1,9,115,119,1,119,9,123,2,123,10,127,1,6,127,131,2,131,13,135,1,13,135,139,1,9,139,143,1,9,143,147,1,147,13,151,1,151,9,155,1,155,13,159,1,6,159,163,1,13,163,167,1,2,167,171,1,171,13,0,99,2,0,14,0 diff --git a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb new file mode 100644 index 000000000..599c64b4c --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb @@ -0,0 +1,96 @@ +{ + "nbformat": 4, + "nbformat_minor": 2, + "metadata": { + "language_info": { + "name": "python", + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "version": "3.7.2" + }, + "orig_nbformat": 2, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3 + }, + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"C:\\Coding\\Advent Of Code 2019\\Day 2\\input.txt\") as input:\n", + " sequence = list(map(int, input.read().split(\",\")))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "sequence = [1,9,10,3,2,3,11,0,99,30,40,50]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "def intcode(seq):\n", + " opcode = seq[0]\n", + " vals = seq[1:3]\n", + " index = seq[3]\n", + "\n", + " if opcode == 1:\n", + " seq[index] = sum(vals)\n", + " return intcode(seq)\n", + " elif opcode == 2:\n", + " seq[index] = vals[0] * vals[1]\n", + " return intcode(seq)\n", + " elif opcode == 99:\n", + " return seq\n", + " else:\n", + " raise \"invalid opcode\"\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "ename": "IndexError", + "evalue": "list assignment index out of range", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mintcode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msequence\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m\u001b[0m in \u001b[0;36mintcode\u001b[1;34m(seq)\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mseq\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mintcode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mseq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mseq\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvals\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mvals\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36mintcode\u001b[1;34m(seq)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mseq\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mintcode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mseq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" + ] + } + ], + "source": [ + "intcode(sequence)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file diff --git a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py new file mode 100644 index 000000000..5f9f7bb12 --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py @@ -0,0 +1,25 @@ +def intcode(seq, offset=0): + opcode = seq[0 + offset] + if opcode == 99: + return seq + vals = [seq[seq[1 + offset]], seq[seq[2 + offset]]] + index = seq[3 + offset] + + if opcode == 1: + seq[index] = sum(vals) + return intcode(seq, offset + 4) + elif opcode == 2: + seq[index] = vals[0] * vals[1] + return intcode(seq, offset + 4) + + else: + raise "invalid opcode" + + +with open("C:\Coding\Advent Of Code 2019\Day 2\input.txt") as input: + sequence = list(map(int, input.read().split(","))) + +sequence[1] = 12 +sequence[2] = 2 + +print(intcode(sequence)) -- 2.51.2 From fff16cadee2c48ccdfb5fe4a55450e4eda1960ae Mon Sep 17 00:00:00 2001 From: Anson Date: Sun, 1 Dec 2019 23:01:31 -0700 Subject: [PATCH 07/17] part 2 solution --- .../Day 2/program_alarm.ipynb | 80 +++++++++++-------- .../Day 2/program_alarm.py | 71 +++++++++++----- 2 files changed, 97 insertions(+), 54 deletions(-) diff --git a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb index 599c64b4c..1593af1d2 100644 --- a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb +++ b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.ipynb @@ -21,68 +21,78 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "with open(\"C:\\Coding\\Advent Of Code 2019\\Day 2\\input.txt\") as input:\n", - " sequence = list(map(int, input.read().split(\",\")))" + " main_sequence = list(map(int, input.read().split(\",\")))" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ - "sequence = [1,9,10,3,2,3,11,0,99,30,40,50]" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [], - "source": [ - "def intcode(seq):\n", - " opcode = seq[0]\n", - " vals = seq[1:3]\n", - " index = seq[3]\n", + "def intcode(seq, offset=0):\n", + " opcode = seq[0 + offset]\n", + " if opcode == 99:\n", + " return seq\n", + " vals = [seq[seq[1 + offset]], seq[seq[2 + offset]]]\n", + " index = seq[3 + offset]\n", + " if index == 0:\n", + " print(offset)\n", "\n", " if opcode == 1:\n", " seq[index] = sum(vals)\n", - " return intcode(seq)\n", + " return intcode(seq, offset + 4)\n", " elif opcode == 2:\n", " seq[index] = vals[0] * vals[1]\n", - " return intcode(seq)\n", - " elif opcode == 99:\n", - " return seq\n", + " return intcode(seq, offset + 4)\n", + "\n", " else:\n", - " raise \"invalid opcode\"\n", - "\n" + " # raise \"invalid opcode\"\n", + " return seq" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "172\n" + } + ], + "source": [ + "for i in range(100):\n", + " for j in range(100):\n", + " sequence = main_sequence\n", + " sequence[1] = i\n", + " sequence[2] = j\n", + " if intcode(sequence)[0] == 19690720:\n", + " print(i,j)" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 22, "metadata": {}, "outputs": [ { - "ename": "IndexError", - "evalue": "list assignment index out of range", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mintcode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msequence\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36mintcode\u001b[1;34m(seq)\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mseq\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mintcode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mseq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 9\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mseq\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mvals\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mvals\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;32m\u001b[0m in \u001b[0;36mintcode\u001b[1;34m(seq)\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mseq\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0msum\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvals\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mintcode\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mseq\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32melif\u001b[0m \u001b[0mopcode\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mIndexError\u001b[0m: list assignment index out of range" - ] + "data": { + "text/plain": "[1, 171, 13, 0, 99]" + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "intcode(sequence)" + "sequence[172:177]" ] }, { diff --git a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py index 5f9f7bb12..b918cec77 100644 --- a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py +++ b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py @@ -1,25 +1,58 @@ -def intcode(seq, offset=0): - opcode = seq[0 + offset] - if opcode == 99: - return seq - vals = [seq[seq[1 + offset]], seq[seq[2 + offset]]] - index = seq[3 + offset] +# def intcode(seq, offset=0): +# opcode = seq[0 + offset] +# if opcode == 99: +# return seq +# vals = [seq[seq[1 + offset]], seq[seq[2 + offset]]] +# index = seq[3 + offset] - if opcode == 1: - seq[index] = sum(vals) - return intcode(seq, offset + 4) - elif opcode == 2: - seq[index] = vals[0] * vals[1] - return intcode(seq, offset + 4) +# if opcode == 1: +# seq[index] = sum(vals) +# return intcode(seq, offset + 4) +# elif opcode == 2: +# seq[index] = vals[0] * vals[1] +# return intcode(seq, offset + 4) - else: - raise "invalid opcode" +# else: +# return seq -with open("C:\Coding\Advent Of Code 2019\Day 2\input.txt") as input: - sequence = list(map(int, input.read().split(","))) +# with open("C:\Coding\Advent Of Code 2019\Day 2\input.txt") as input: +# main_sequence = list(map(int, input.read().split(","))) -sequence[1] = 12 -sequence[2] = 2 +# for i in range(100): +# for j in range(100): + +# sequence = main_sequence +# sequence[1] = j +# sequence[2] = i +# print(intcode(sequence)[0], i, j) +# if intcode(sequence)[0] == 19690720: +# print(i, j) +# break + +OP = [ + int(x) + for x in open("C:\Coding\Advent Of Code 2019\Day 2\input.txt").read().split(",") +] + +for x1 in range(100): + for x2 in range(100): + P = [x for x in OP] + P[1] = x1 + P[2] = x2 + ip = 0 + while True: + opcode = P[ip] + i1, i2, i3 = P[ip + 1], P[ip + 2], P[ip + 3] + if opcode == 1: + P[i3] = P[i1] + P[i2] + elif opcode == 2: + P[i3] = P[i1] * P[i2] + else: + assert opcode == 99 + break + ip += 4 + if P[0] == 19690720: + print(x1, x2) + print(100 * x1 + x2) -print(intcode(sequence)) -- 2.51.2 From e0afbbd57782100c74f1ca1ff19b360c42117fa0 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 2 Dec 2019 14:40:42 -0700 Subject: [PATCH 08/17] working solution --- .../Day 2/program_alarm.py | 88 +++++++------------ 1 file changed, 31 insertions(+), 57 deletions(-) diff --git a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py index b918cec77..ea555f004 100644 --- a/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py +++ b/MisterBiggs/advent-of-code-2019/Day 2/program_alarm.py @@ -1,58 +1,32 @@ -# def intcode(seq, offset=0): -# opcode = seq[0 + offset] -# if opcode == 99: -# return seq -# vals = [seq[seq[1 + offset]], seq[seq[2 + offset]]] -# index = seq[3 + offset] - -# if opcode == 1: -# seq[index] = sum(vals) -# return intcode(seq, offset + 4) -# elif opcode == 2: -# seq[index] = vals[0] * vals[1] -# return intcode(seq, offset + 4) - -# else: -# return seq - - -# with open("C:\Coding\Advent Of Code 2019\Day 2\input.txt") as input: -# main_sequence = list(map(int, input.read().split(","))) - -# for i in range(100): -# for j in range(100): - -# sequence = main_sequence -# sequence[1] = j -# sequence[2] = i -# print(intcode(sequence)[0], i, j) -# if intcode(sequence)[0] == 19690720: -# print(i, j) -# break - -OP = [ - int(x) - for x in open("C:\Coding\Advent Of Code 2019\Day 2\input.txt").read().split(",") -] - -for x1 in range(100): - for x2 in range(100): - P = [x for x in OP] - P[1] = x1 - P[2] = x2 - ip = 0 - while True: - opcode = P[ip] - i1, i2, i3 = P[ip + 1], P[ip + 2], P[ip + 3] - if opcode == 1: - P[i3] = P[i1] + P[i2] - elif opcode == 2: - P[i3] = P[i1] * P[i2] - else: - assert opcode == 99 - break - ip += 4 - if P[0] == 19690720: - print(x1, x2) - print(100 * x1 + x2) +def intcode(seq, offset=0): + opcode = seq[0 + offset] + if opcode == 99: + return seq + vals = [seq[seq[1 + offset]], seq[seq[2 + offset]]] + index = seq[3 + offset] + + if opcode == 1: + seq[index] = sum(vals) + return intcode(seq, offset + 4) + elif opcode == 2: + seq[index] = vals[0] * vals[1] + return intcode(seq, offset + 4) + + else: + return seq + + +with open("C:\Coding\Advent Of Code 2019\Day 2\input.txt") as input: + main_sequence = list(map(int, input.read().split(","))) + +for i in range(100): + for j in range(100): + + sequence = main_sequence[:] + sequence[1] = i + sequence[2] = j + print(intcode(sequence)[0], i, j) + if intcode(sequence)[0] == 19690720: + print("Answer: ", 100 * i + j) + quit() -- 2.51.2 From 465602c7906b833484efb8a9f39d1a7d50e58bde Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 2 Dec 2019 16:57:16 -0700 Subject: [PATCH 09/17] ignoring rust stuff --- MisterBiggs/advent-of-code-2019/.gitignore | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 MisterBiggs/advent-of-code-2019/.gitignore diff --git a/MisterBiggs/advent-of-code-2019/.gitignore b/MisterBiggs/advent-of-code-2019/.gitignore new file mode 100644 index 000000000..70bf74b97 --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/.gitignore @@ -0,0 +1,17 @@ + +# Created by https://www.gitignore.io/api/rust +# Edit at https://www.gitignore.io/?templates=rust + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# End of https://www.gitignore.io/api/rust -- 2.51.2 From aa762016185cc3e1134eeeb128c72c04d37cedd3 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 2 Dec 2019 17:04:41 -0700 Subject: [PATCH 10/17] gitignore fix since rust isnt in root --- MisterBiggs/advent-of-code-2019/.gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MisterBiggs/advent-of-code-2019/.gitignore b/MisterBiggs/advent-of-code-2019/.gitignore index 70bf74b97..23fa039a0 100644 --- a/MisterBiggs/advent-of-code-2019/.gitignore +++ b/MisterBiggs/advent-of-code-2019/.gitignore @@ -5,7 +5,7 @@ ### Rust ### # Generated by Cargo # will have compiled files and executables -/target/ +**/target/* # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -- 2.51.2 From 42e9eefadffcfe95febfa7b8f465b82231a61d22 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 2 Dec 2019 23:47:29 -0700 Subject: [PATCH 11/17] part 1 done --- .../Day 3/crossed_wires.py | 37 +++++++++++++++++++ .../advent-of-code-2019/Day 3/input.txt | 2 + 2 files changed, 39 insertions(+) create mode 100644 MisterBiggs/advent-of-code-2019/Day 3/crossed_wires.py create mode 100644 MisterBiggs/advent-of-code-2019/Day 3/input.txt diff --git a/MisterBiggs/advent-of-code-2019/Day 3/crossed_wires.py b/MisterBiggs/advent-of-code-2019/Day 3/crossed_wires.py new file mode 100644 index 000000000..c8fe0e989 --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 3/crossed_wires.py @@ -0,0 +1,37 @@ +# import numpy as np + +with open("Day 3/input.txt") as input: + wire_a, wire_b = input.read().split("\n") + wire_a = wire_a.split(",") + wire_b = wire_b.split(",") + +STEPS = {"U": (0, 1), "D": (0, -1), "L": (-1, 0), "R": (1, 0)} + + +def route(wire): + path = [] + x, y = 0, 0 + + for seg in wire: + direction = STEPS[seg[0]] + for _ in range(int(seg[1:])): + x += direction[0] + y += direction[1] + + path.append((x, y)) + return path + + +path_a = route(wire_a) +path_b = route(wire_b) + +crosses = set(path_a).intersection(set(path_b)) + +manhattan = None + +for cross in crosses: + dist = abs(cross[0]) + abs(cross[1]) + if manhattan is None or dist < manhattan: + manhattan = dist + +print(manhattan) diff --git a/MisterBiggs/advent-of-code-2019/Day 3/input.txt b/MisterBiggs/advent-of-code-2019/Day 3/input.txt new file mode 100644 index 000000000..91b87439d --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 3/input.txt @@ -0,0 +1,2 @@ +R1008,D256,L88,U390,R429,D828,R2,D452,L644,D942,R387,U221,L274,D837,R437,U664,R952,U126,L840,U425,L749,D199,L48,U394,L623,D562,L760,D856,L648,U666,R756,U396,L588,U217,R208,D492,L230,U60,L178,D211,L806,U423,L399,D159,L176,D555,R173,D946,L360,U415,L734,D441,L146,D332,R135,D529,L364,U742,L862,D790,L399,D392,R706,D740,L839,D950,R822,D27,R108,D873,L492,D465,L635,U771,L586,U66,R703,U943,R141,U396,R641,D339,R460,U295,L397,U799,R479,U963,L211,U933,R158,U248,R443,U807,R115,U885,R670,U116,L24,D980,R349,U363,L413,U444,L453,D497,L202,U300,L122,D895,L210,U218,R456,U293,L576,U968,L612,D225,L732,D34,R800,U925,R731,U520,R686,D181,L102,D824,R832,D527,L614,D624,R734,U552,L911,D352,R157,D70,R958,U317,L43,U902,R265,U986,R305,U264,L957,U888,R66,D413,L73,D642,R14,D559,R414,D985,R679,D965,R333,D332,L261,D446,L479,U430,L730,D37,L936,D615,L344,D215,R912,D95,L691,U383,L328,U560,R806,U711,R515,U448,R403,D109,L589,U458,L240,D375,L88,D479,R93,U794,L303,U783,L833,U500,R406,D589,L694,U504,L484,U695,R228,U813,R646,U768,L60,D326,L580,U840,L387,U147,L50,U155,L454,D574,L885,D705,R727,D827,R409,U335,L271,D388,R897,D563,L360,U70,R777,U903,R363,D202,R855,D159,R35,U585,L384,D540,R78,U13,R979,D702,L868,D868,R508,D552,L735,U923,R840,U133,L355,U282,R626,D699,L560,D26,R902,D873,L333,U492,L96,U461,R261,U784,L793,D723,R887,U836,R790,D400,L331,U389,L107,U534,L377,D831,R181,U325,L328,U778,L498,D109,L692,U185,R284,U930,R784,D843,L261,U119,L751,U313,R197,U911,L21,D201,L881,U119,R210,D700,R93,U208,R116 +L1009,D700,L634,U294,R898,D947,R650,U988,L623,D968,R761,U490,R525,U76,R633,D139,R348,D855,L983,U553,L454,D211,L240,D465,R260,U285,R653,D734,L346,U434,R813,U599,R98,D779,L58,D6,R309,U437,L712,U896,R262,U911,R400,D247,R297,U915,L223,D591,L755,D398,L980,U177,R186,U882,R418,U763,L741,D60,L942,U648,L430,D401,R30,D157,L901,D179,L615,U535,L586,D613,L606,U239,L133,D251,L549,D579,R612,U307,L127,D343,L43,D288,R245,U122,R352,D527,R476,U24,L805,U291,R953,D469,L941,U577,L384,U345,L463,D50,R311,D649,L746,D902,R644,U913,R147,D649,R848,D673,R93,U65,R363,U734,L289,U599,R738,U45,R128,D508,L93,D201,R51,U239,R17,D496,L661,D912,R165,U291,L207,D308,R241,D388,L910,D821,R714,D327,L605,U880,L682,D934,R334,D1,R602,D54,L51,D913,L575,U168,R614,D603,R452,U718,R689,D505,R83,D385,R636,D692,R424,D573,R686,D572,L467,D698,L21,U510,L497,U329,R286,U733,R584,U919,R499,U971,L558,U511,L565,D623,L502,U536,L483,U372,L686,D420,L900,U316,L37,U372,L915,D641,R165,D927,L137,U231,R813,U416,L131,D530,R486,U795,L507,U757,L208,U308,L521,U583,L758,U654,R554,D467,R381,U155,R47,U829,R92,D158,R54,D500,R17,D471,R748,U571,L194,D55,L921,U271,L730,U207,L204,U806,R19,D33,R218,D911,L106,U220,R551,U308,L268,U5,L374,U657,R639,U705,R294,U962,L927,U892,L477,U290,R378,D193,L154,U859,L618,D690,L769,D779,R752,D915,L693,D586,L558,D864,L523,U354,R386,U236,R888,U302,L75,U628,R132,D306,L939,U73,L687,D488,R21,D760,L856,U96,L116,U557,L639,U812,L389,D364,L807,U696,R781,D625,R565,U728,R134,D406,R785,U583,R60,D819,L939 \ No newline at end of file -- 2.51.2 From 35941114d3ea676c687315670e804bce4fa14466 Mon Sep 17 00:00:00 2001 From: Anson Date: Mon, 2 Dec 2019 23:58:39 -0700 Subject: [PATCH 12/17] part 2 complete --- .../advent-of-code-2019/Day 3/timing.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 MisterBiggs/advent-of-code-2019/Day 3/timing.py diff --git a/MisterBiggs/advent-of-code-2019/Day 3/timing.py b/MisterBiggs/advent-of-code-2019/Day 3/timing.py new file mode 100644 index 000000000..c760d8ecc --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 3/timing.py @@ -0,0 +1,37 @@ +with open("Day 3/input.txt") as input: + wire_a, wire_b = input.read().split("\n") + wire_a = wire_a.split(",") + wire_b = wire_b.split(",") + + +STEPS = {"U": (0, 1), "D": (0, -1), "L": (-1, 0), "R": (1, 0)} + + +def route(wire): + path = {} + x, y = 0, 0 + count = 0 + for seg in wire: + direction = STEPS[seg[0]] + for _ in range(int(seg[1:])): + x += direction[0] + y += direction[1] + count += 1 + path[(x, y)] = count + return path + + +path_a = route(wire_a) +path_b = route(wire_b) + +crosses = set(path_a.keys()).intersection(set(path_b.keys())) + +minimum = None + +for cross in crosses: + steps = path_a[cross] + path_b[cross] + + if minimum is None or minimum > steps: + minimum = steps + +print(minimum) -- 2.51.2 From 78e371077c4008048872c9eab4078ca1e3e5c1e4 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 3 Dec 2019 23:31:52 -0700 Subject: [PATCH 13/17] vscode stuff --- .../advent-of-code-2019/.vscode/launch.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 MisterBiggs/advent-of-code-2019/.vscode/launch.json diff --git a/MisterBiggs/advent-of-code-2019/.vscode/launch.json b/MisterBiggs/advent-of-code-2019/.vscode/launch.json new file mode 100644 index 000000000..01adf0bcd --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Current File", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} -- 2.51.2 From 13d2b87c3ad5397bbb73bf16e2dc038f39521419 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 3 Dec 2019 23:32:47 -0700 Subject: [PATCH 14/17] answer that I dont understand is wrong --- MisterBiggs/advent-of-code-2019/Day 4/code.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 MisterBiggs/advent-of-code-2019/Day 4/code.py diff --git a/MisterBiggs/advent-of-code-2019/Day 4/code.py b/MisterBiggs/advent-of-code-2019/Day 4/code.py new file mode 100644 index 000000000..af3919f0b --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 4/code.py @@ -0,0 +1,37 @@ +start = 272091 +end = 815432 + +index = start + +count = 0 + + +def ascending(index): + for i in range(len(str(index)) - 1): + + a, b = str(index)[i], str(index)[i + 1] + + if a > b: + index += 10 ** (len(str(index)) - i - 2) * abs(int(b) - int(a)) + return ascending(index) + break + return index + + +while True: + index = ascending(index) + + if index > end: + break + + for i in range(len(str(index)) - 1): + a, b = str(index)[i], str(index)[i + 1] + + if a == b: + count += 1 + print(index) + break + + index += 1 + +print(count) -- 2.51.2 From 5816141c5dce9ffec6c4e1e23a74665d955d0771 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 3 Dec 2019 23:33:03 -0700 Subject: [PATCH 15/17] correct answer --- MisterBiggs/advent-of-code-2019/Day 4/code.py | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/MisterBiggs/advent-of-code-2019/Day 4/code.py b/MisterBiggs/advent-of-code-2019/Day 4/code.py index af3919f0b..2d9791c5d 100644 --- a/MisterBiggs/advent-of-code-2019/Day 4/code.py +++ b/MisterBiggs/advent-of-code-2019/Day 4/code.py @@ -1,37 +1,13 @@ start = 272091 end = 815432 - -index = start - count = 0 +for i in range(start, end): + code = [int(x) for x in list(str(i))] -def ascending(index): - for i in range(len(str(index)) - 1): - - a, b = str(index)[i], str(index)[i + 1] - - if a > b: - index += 10 ** (len(str(index)) - i - 2) * abs(int(b) - int(a)) - return ascending(index) - break - return index - - -while True: - index = ascending(index) - - if index > end: - break - - for i in range(len(str(index)) - 1): - a, b = str(index)[i], str(index)[i + 1] - - if a == b: - count += 1 - print(index) - break - - index += 1 - + if code == sorted(code): + for c in code: + if code.count(c) >= 2: + count += 1 + break print(count) -- 2.51.2 From 68fdf765ba1c3000546459db172acb76e627f391 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 3 Dec 2019 23:35:04 -0700 Subject: [PATCH 16/17] part 2 ez pz --- MisterBiggs/advent-of-code-2019/Day 4/code.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MisterBiggs/advent-of-code-2019/Day 4/code.py b/MisterBiggs/advent-of-code-2019/Day 4/code.py index 2d9791c5d..bbbd60c5a 100644 --- a/MisterBiggs/advent-of-code-2019/Day 4/code.py +++ b/MisterBiggs/advent-of-code-2019/Day 4/code.py @@ -7,7 +7,7 @@ for i in range(start, end): if code == sorted(code): for c in code: - if code.count(c) >= 2: + if code.count(c) == 2: count += 1 break print(count) -- 2.51.2 From 3397128bb8b4f88c164c2d021326bd3d1e8eeb09 Mon Sep 17 00:00:00 2001 From: Anson Date: Wed, 4 Dec 2019 22:31:32 -0700 Subject: [PATCH 17/17] im too tired tonight --- MisterBiggs/advent-of-code-2019/Day 5/TEST.py | 39 +++++++++++++++++++ .../advent-of-code-2019/Day 5/input.txt | 1 + 2 files changed, 40 insertions(+) create mode 100644 MisterBiggs/advent-of-code-2019/Day 5/TEST.py create mode 100644 MisterBiggs/advent-of-code-2019/Day 5/input.txt diff --git a/MisterBiggs/advent-of-code-2019/Day 5/TEST.py b/MisterBiggs/advent-of-code-2019/Day 5/TEST.py new file mode 100644 index 000000000..1b1cf4680 --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 5/TEST.py @@ -0,0 +1,39 @@ +def intcode(seq, offset=0): + parameter = str(seq[offset]) + parameter = parameter.rjust(5, "0") + opcode = int(parameter[-2:]) + + parameters = [int(x) for x in parameter[:-2][::-1]] + + params = len(parameters) + + for parameter in parameters: + if parameter == 0: + index = seq[3 + offset] + + if opcode == 99: + return seq + vals = [seq[seq[1 + offset]], seq[seq[2 + offset]]] + + if opcode == 1: + seq[index] = sum(vals) + return intcode(seq, offset + 4) + elif opcode == 2: + seq[index] = vals[0] * vals[1] + return intcode(seq, offset + 4) + elif opcode == 3: + seq[index] = inp + return intcode(seq, offset + 4) + elif opcode == 4: + seq[index] = out + return intcode(seq, offset + 4) + + else: + return seq + + +# with open("C:\Coding\Advent Of Code 2019\Day 5\input.txt") as input: +# main_sequence = list(map(int, input.read().split(","))) + +print(intcode([1002, 4, 3, 4, 33])) + diff --git a/MisterBiggs/advent-of-code-2019/Day 5/input.txt b/MisterBiggs/advent-of-code-2019/Day 5/input.txt new file mode 100644 index 000000000..0f994a980 --- /dev/null +++ b/MisterBiggs/advent-of-code-2019/Day 5/input.txt @@ -0,0 +1 @@ +3,225,1,225,6,6,1100,1,238,225,104,0,1101,91,67,225,1102,67,36,225,1102,21,90,225,2,13,48,224,101,-819,224,224,4,224,1002,223,8,223,101,7,224,224,1,223,224,223,1101,62,9,225,1,139,22,224,101,-166,224,224,4,224,1002,223,8,223,101,3,224,224,1,223,224,223,102,41,195,224,101,-2870,224,224,4,224,1002,223,8,223,101,1,224,224,1,224,223,223,1101,46,60,224,101,-106,224,224,4,224,1002,223,8,223,1001,224,2,224,1,224,223,223,1001,191,32,224,101,-87,224,224,4,224,102,8,223,223,1001,224,1,224,1,223,224,223,1101,76,90,225,1101,15,58,225,1102,45,42,224,101,-1890,224,224,4,224,1002,223,8,223,1001,224,5,224,1,224,223,223,101,62,143,224,101,-77,224,224,4,224,1002,223,8,223,1001,224,4,224,1,224,223,223,1101,55,54,225,1102,70,58,225,1002,17,80,224,101,-5360,224,224,4,224,102,8,223,223,1001,224,3,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,1008,677,677,224,102,2,223,223,1005,224,329,1001,223,1,223,1108,677,226,224,1002,223,2,223,1006,224,344,101,1,223,223,107,677,226,224,1002,223,2,223,1006,224,359,101,1,223,223,108,677,677,224,1002,223,2,223,1006,224,374,1001,223,1,223,108,226,677,224,1002,223,2,223,1006,224,389,101,1,223,223,7,226,677,224,102,2,223,223,1006,224,404,1001,223,1,223,1108,677,677,224,1002,223,2,223,1005,224,419,101,1,223,223,1008,226,677,224,102,2,223,223,1006,224,434,101,1,223,223,107,226,226,224,102,2,223,223,1005,224,449,1001,223,1,223,1007,677,677,224,1002,223,2,223,1006,224,464,1001,223,1,223,1007,226,226,224,1002,223,2,223,1005,224,479,101,1,223,223,1008,226,226,224,102,2,223,223,1006,224,494,1001,223,1,223,8,226,226,224,102,2,223,223,1006,224,509,101,1,223,223,1107,677,677,224,102,2,223,223,1005,224,524,1001,223,1,223,1108,226,677,224,1002,223,2,223,1006,224,539,101,1,223,223,1107,677,226,224,1002,223,2,223,1006,224,554,101,1,223,223,1007,677,226,224,1002,223,2,223,1005,224,569,101,1,223,223,7,677,226,224,1002,223,2,223,1006,224,584,101,1,223,223,107,677,677,224,1002,223,2,223,1005,224,599,1001,223,1,223,8,226,677,224,1002,223,2,223,1005,224,614,101,1,223,223,7,677,677,224,1002,223,2,223,1006,224,629,1001,223,1,223,1107,226,677,224,1002,223,2,223,1006,224,644,101,1,223,223,108,226,226,224,102,2,223,223,1005,224,659,1001,223,1,223,8,677,226,224,1002,223,2,223,1005,224,674,101,1,223,223,4,223,99,226