2018 d11 p1 & p2

This commit is contained in:
Tristan 2018-12-11 23:10:09 +00:00
parent b4d985a55a
commit 700cfbde66
4 changed files with 134 additions and 36 deletions

45
2018/11/part1.py Normal file
View file

@ -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]))

49
2018/11/part2.py Normal file
View file

@ -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]))

View file

@ -1,31 +1,34 @@
# [2018](https://adventofcode.com/2018 "2018 puzzle calendar") # [2018](https://adventofcode.com/2018 "2018 puzzle calendar")
1. [js :star: :star:](https://adventofcode.com/2015/day/1 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2015/day/1 "see puzzle")
1. [py :star: :star:](https://adventofcode.com/2015/day/2 "see puzzle") 2. [:star: :star:](https://adventofcode.com/2015/day/2 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/3 "see puzzle") 3. [:star: :star:](https://adventofcode.com/2015/day/3 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/4 "see puzzle") 4. [:star: :star:](https://adventofcode.com/2015/day/4 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") 5. [:star: :star:](https://adventofcode.com/2015/day/5 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/6 "see puzzle") 6. [:star: :star:](https://adventofcode.com/2015/day/6 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/7 "see puzzle") 7. [:star: :star:](https://adventofcode.com/2015/day/7 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/8 "see puzzle") 8. [:star: :star:](https://adventofcode.com/2015/day/8 "see puzzle")
1. [js :star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") 9. [:star: :star:](https://adventofcode.com/2015/day/9 "see puzzle")
1. [java :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 # Languages Used
### Python ### Python
1. - 2. :star: :star:
1. :star: :star:
1. -
11. :star: :star:
### Node JS ### Node JS
1. :star: :star: 1. :star: :star:
1. -
1. :star: :star:
1. :star: :star: 3. :star: :star:
1. :star: :star: 4. :star: :star:
1. :star: :star: 5. :star: :star:
1. :star: :star: 6. :star: :star:
1. :star: :star: 7. :star: :star:
10. :star: :star: 8. :star: :star:
9. :star: :star:
### Java (Processing) ### Java (Processing)
10. :star: :star: 10. :star: :star:

View file

@ -1,10 +1,10 @@
# Advent of Code Solutions # 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 ```js
if (advent) { 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") 1. [:star:](https://adventofcode.com/2015/day/6 "see puzzle")
#### [2018](https://adventofcode.com/2018 "2018 puzzle calendar") #### [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/2018/day/1 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/2 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/2 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/3 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/3 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/4 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/4 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/5 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/5 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/6 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/6 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/7 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/7 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/8 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/8 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/day/9 "see puzzle") 1. [:star: :star:](https://adventofcode.com/2018/day/9 "see puzzle")
1. [:star: :star:](https://adventofcode.com/2015/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 ## Languages Used
* Python * Python
- .py - py
* Node JS * Node JS
- .js - js
* Java (Processing) * Java (Processing)
- .pde - pde