From 700cfbde66457f55f0dc13384aa3c11e2d07ffa5 Mon Sep 17 00:00:00 2001 From: Tristan Date: Tue, 11 Dec 2018 23:10:09 +0000 Subject: [PATCH] 2018 d11 p1 & p2 --- 2018/11/part1.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2018/11/part2.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2018/README.md | 45 +++++++++++++++++++++++--------------------- README.md | 31 +++++++++++++++--------------- 4 files changed, 134 insertions(+), 36 deletions(-) create mode 100644 2018/11/part1.py create mode 100644 2018/11/part2.py diff --git a/2018/11/part1.py b/2018/11/part1.py new file mode 100644 index 0000000..bb0e28c --- /dev/null +++ b/2018/11/part1.py @@ -0,0 +1,45 @@ +gsn = 9798 # input + + +def get_power(x, y): + rack_id = x + 10 + power = ((rack_id * y) + gsn) * rack_id + h_digit = int(str(power)[-3]) if len(str(power)) >= 3 else 0 + return h_digit - 5 + +size = 300 +side = 1 +top = 1 +totals = [[0 for i in range(size)]] +printing = size <= 10 +if printing: + print(*range(side, side+size), sep='\t') + print('_ _ _\t|'*size) +for y in range(1, size): + row = [0] + totals.append([0]) + p = [] + + for x in range(1, size): + point = get_power(x+side, y+top) + left = row[x-1] if len(row) > 0 else 0 + row.append(left + point) + up = totals[y-1][x] if len(totals) > 1 else 0 + totals[y].append(up + left + point) + p.append(point) + + if printing: + print(str(y+top), end = '\t| ') + print(*p, sep='\t| ') + print('_ _ _\t|'*size) + +largest = ((0,0),0) +for y in range(1, len(totals)-3): + for x in range(1, len(totals[y])-3): + p = ((x+side, y+top), totals[y+2][x+2] - totals[y-1][x+2] - totals[y+2][x-1] + totals[y-1][x-1]) + if p[1] > largest[1]: + largest = p + +print('largest:\n\ +\tco-ordinates: {}\n\ +\tvalue: {}'.format(largest[0], largest[1])) \ No newline at end of file diff --git a/2018/11/part2.py b/2018/11/part2.py new file mode 100644 index 0000000..6c04e8c --- /dev/null +++ b/2018/11/part2.py @@ -0,0 +1,49 @@ +gsn = 9798 # input + + +def get_power(x, y): + rack_id = x + 10 + power = ((rack_id * y) + gsn) * rack_id + h_digit = int(str(power)[-3]) if len(str(power)) >= 3 else 0 + return h_digit - 5 + +size = 300 +side = 1 +top = 1 +totals = [[0 for i in range(size)]] + +printing = size <= 10 +if printing: + print(*range(side, side+size), sep='\t') + print('_ _ _\t|'*size) + +for y in range(1, size): + row = [0] + totals.append([0]) + p = [] + + for x in range(1, size): + point = get_power(x+side, y+top) + left = row[x-1] if len(row) > 0 else 0 + row.append(left + point) + up = totals[y-1][x] if len(totals) > 1 else 0 + totals[y].append(up + left + point) + p.append(point) + + if printing: + print(str(y+top), end = '\t| ') + print(*p, sep='\t| ') + print('_ _ _\t|'*size) + +largest = ((0,0),0) +for s_size in range(1, size): + for y in range(1, len(totals)-s_size): + for x in range(1, len(totals[y])-s_size): + p = ((x+side, y+top),totals[y+s_size-1][x+s_size-1] - totals[y-1][x+s_size-1] - totals[y+s_size-1][x-1] + totals[y-1][x-1], s_size) + if p[1] > largest[1]: + largest = p + +print('largest\n\ +\tco-ordinates: {}\n\ +\tsize: {}\n\ +\tvalue: {}'.format(largest[0], largest[2], largest[1])) \ No newline at end of file diff --git a/2018/README.md b/2018/README.md index 9ce52e1..9028d99 100644 --- a/2018/README.md +++ b/2018/README.md @@ -1,31 +1,34 @@ # [2018](https://adventofcode.com/2018 "2018 puzzle calendar") -1. [js :star: :star:](https://adventofcode.com/2015/day/1 "see puzzle") -1. [py :star: :star:](https://adventofcode.com/2015/day/2 "see puzzle") -1. [js :star: :star:](https://adventofcode.com/2015/day/3 "see puzzle") -1. [js :star: :star:](https://adventofcode.com/2015/day/4 "see puzzle") -1. [js :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") -1. [js :star: :star:](https://adventofcode.com/2015/day/6 "see puzzle") -1. [js :star: :star:](https://adventofcode.com/2015/day/7 "see puzzle") -1. [js :star: :star:](https://adventofcode.com/2015/day/8 "see puzzle") -1. [js :star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") -1. [java :star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2015/day/1 "see puzzle") +2. [:star: :star:](https://adventofcode.com/2015/day/2 "see puzzle") +3. [:star: :star:](https://adventofcode.com/2015/day/3 "see puzzle") +4. [:star: :star:](https://adventofcode.com/2015/day/4 "see puzzle") +5. [:star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") +6. [:star: :star:](https://adventofcode.com/2015/day/6 "see puzzle") +7. [:star: :star:](https://adventofcode.com/2015/day/7 "see puzzle") +8. [:star: :star:](https://adventofcode.com/2015/day/8 "see puzzle") +9. [:star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") +10. [:star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") +11. [:star: :star:](https://adventofcode.com/2015/day/10 "see puzzle") # Languages Used ### Python -1. - -1. :star: :star: -1. - +2. :star: :star: + + +11. :star: :star: ### Node JS 1. :star: :star: -1. - -1. :star: :star: -1. :star: :star: -1. :star: :star: -1. :star: :star: -1. :star: :star: -1. :star: :star: -10. :star: :star: + + +3. :star: :star: +4. :star: :star: +5. :star: :star: +6. :star: :star: +7. :star: :star: +8. :star: :star: +9. :star: :star: ### Java (Processing) 10. :star: :star: \ No newline at end of file diff --git a/README.md b/README.md index fd0235c..1dd6a4e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Advent of Code Solutions -It's a fun challenge. [2018](https://adventofcode.com/2018) is currently in progress. +It's a fun challenge. [2018](#2018) is currently in progress. ```js if (advent) { - programmer.gotTo("adventofcode.com"); + programmer.goTo("adventofcode.com"); } ``` @@ -18,21 +18,22 @@ if (advent) { 1. [:star:](https://adventofcode.com/2015/day/6 "see puzzle") #### [2018](https://adventofcode.com/2018 "2018 puzzle calendar") -1. [:star: :star:](https://adventofcode.com/2015/day/1 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/2 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/3 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/4 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/6 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/7 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/8 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") -1. [:star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/1 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/2 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/3 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/4 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/5 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/6 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/7 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/8 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/9 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/10 "see puzzle") +1. [:star: :star:](https://adventofcode.com/2018/day/11 "see puzzle") ## Languages Used * Python - - .py + - py * Node JS - - .js + - js * Java (Processing) - - .pde \ No newline at end of file + - pde \ No newline at end of file