Updated 2015/01,02,03
This commit is contained in:
parent
6edd15b0e1
commit
58f56e33c7
@ -1,17 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
for idx,i in enumerate(line):
|
||||
if i == '(':
|
||||
result += 1
|
||||
if i == ')':
|
||||
result -= 1
|
||||
print(result)
|
46
2015/01/solution.py
Normal file
46
2015/01/solution.py
Normal file
@ -0,0 +1,46 @@
|
||||
#!/bin/python3
|
||||
import sys,re
|
||||
from pprint import pprint
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
part = 2
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
result = 0
|
||||
if part == 1:
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
for idx,i in enumerate(line):
|
||||
if i == '(':
|
||||
result += 1
|
||||
if i == ')':
|
||||
result -= 1
|
||||
print(result)
|
||||
|
||||
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
result = 0
|
||||
if part == 2:
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
for idx,i in enumerate(line):
|
||||
if i == '(':
|
||||
result += 1
|
||||
if i == ')':
|
||||
result -= 1
|
||||
if result == -1:
|
||||
print(idx+1)
|
||||
break
|
63
2015/02/2.md
Normal file
63
2015/02/2.md
Normal file
@ -0,0 +1,63 @@
|
||||
## \-\-- Day 2: I Was Told There Would Be No Math \-\--
|
||||
|
||||
The elves are running low on wrapping paper, and so they need to submit
|
||||
an order for more. They have a list of the dimensions (length `l`, width
|
||||
`w`, and height `h`) of each present, and only want to order exactly as
|
||||
much as they need.
|
||||
|
||||
Fortunately, every present is a box (a perfect [right rectangular
|
||||
prism](https://en.wikipedia.org/wiki/Cuboid#Rectangular_cuboid)), which
|
||||
makes calculating the required wrapping paper for each gift a little
|
||||
easier: find the surface area of the box, which is
|
||||
`2*l*w + 2*w*h + 2*h*l`. The elves also need a little extra paper for
|
||||
each present: the area of the smallest side.
|
||||
|
||||
For example:
|
||||
|
||||
- A present with dimensions `2x3x4` requires `2*6 + 2*12 + 2*8 = 52`
|
||||
square feet of wrapping paper plus `6` square feet of slack, for a
|
||||
total of `58` square feet.
|
||||
- A present with dimensions `1x1x10` requires `2*1 + 2*10 + 2*10 = 42`
|
||||
square feet of wrapping paper plus `1` square foot of slack, for a
|
||||
total of `43` square feet.
|
||||
|
||||
All numbers in the elves\' list are in
|
||||
feet.
|
||||
How many total *square feet of wrapping paper* should they order?
|
||||
|
||||
Your puzzle answer was `1588178`.
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
The elves are also running low on ribbon. Ribbon is all the same width,
|
||||
so they only have to worry about the length they need to order, which
|
||||
they would again like to be exact.
|
||||
|
||||
The ribbon required to wrap a present is the shortest distance around
|
||||
its sides, or the smallest perimeter of any one face. Each present also
|
||||
requires a bow made out of ribbon as well; the feet of ribbon required
|
||||
for the perfect bow is equal to the cubic feet of volume of the present.
|
||||
Don\'t ask how they tie the bow, though; they\'ll never tell.
|
||||
|
||||
For example:
|
||||
|
||||
- A present with dimensions `2x3x4` requires `2+2+3+3 = 10` feet of
|
||||
ribbon to wrap the present plus `2*3*4 = 24` feet of ribbon for the
|
||||
bow, for a total of `34` feet.
|
||||
- A present with dimensions `1x1x10` requires `1+1+1+1 = 4` feet of
|
||||
ribbon to wrap the present plus `1*1*10 = 10` feet of ribbon for the
|
||||
bow, for a total of `14` feet.
|
||||
|
||||
How many total *feet of ribbon* should they order?
|
||||
|
||||
Your puzzle answer was `3783758`.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars:
|
||||
\*\*
|
||||
|
||||
At this point, you should [return to your Advent calendar](/2015) and
|
||||
try another puzzle.
|
||||
|
||||
If you still want to see it, you can [get your puzzle
|
||||
input](2/input).
|
||||
|
52
2015/02/solution.py
Normal file
52
2015/02/solution.py
Normal file
@ -0,0 +1,52 @@
|
||||
#!/bin/python3
|
||||
import sys,re
|
||||
from pprint import pprint
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
part = 2
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
result = 0
|
||||
|
||||
if part == 1:
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = line.rstrip().split('x')
|
||||
tmp = list(map(int,tmp))
|
||||
first = tmp[0] * tmp[1]
|
||||
second = tmp[1] * tmp[2]
|
||||
third = tmp[2] * tmp[0]
|
||||
smallest = min(first,second,third)
|
||||
result = result + (2*first) + (2*second) + (2*third) + smallest
|
||||
print(result)
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
result = 0
|
||||
|
||||
if part == 2:
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = line.rstrip().split('x')
|
||||
tmp = list(map(int,tmp))
|
||||
first = tmp[0] * tmp[1]
|
||||
second = tmp[1] * tmp[2]
|
||||
third = tmp[2] * tmp[0]
|
||||
#2*l*w + 2*w*h + 2*h*l
|
||||
smallest = min(first,second,third)
|
||||
tmp.sort()
|
||||
rib = tmp[0]+tmp[0]+tmp[1]+tmp[1]
|
||||
bow = tmp[0]*tmp[1]*tmp[2]
|
||||
result = result + rib + bow
|
||||
print(result)
|
60
2015/03/3.md
Normal file
60
2015/03/3.md
Normal file
@ -0,0 +1,60 @@
|
||||
## \-\-- Day 3: Perfectly Spherical Houses in a Vacuum \-\--
|
||||
|
||||
Santa is delivering presents to an infinite two-dimensional grid of
|
||||
houses.
|
||||
|
||||
He begins by delivering a present to the house at his starting location,
|
||||
and then an elf at the North Pole calls him via radio and tells him
|
||||
where to move next. Moves are always exactly one house to the north
|
||||
(`^`), south (`v`), east (`>`), or west (`<`). After each move, he
|
||||
delivers another present to the house at his new location.
|
||||
|
||||
However, the elf back at the north pole has had a little too much
|
||||
eggnog, and so his directions are a little off, and Santa ends up
|
||||
visiting some houses more than once. How many houses receive *at least
|
||||
one present*?
|
||||
|
||||
For example:
|
||||
|
||||
- `>` delivers presents to `2` houses: one at the starting location,
|
||||
and one to the east.
|
||||
- `^>v<` delivers presents to `4` houses in a square, including twice
|
||||
to the house at his starting/ending location.
|
||||
- `^v^v^v^v^v` delivers a bunch of presents to some very lucky
|
||||
children at only `2` houses.
|
||||
|
||||
Your puzzle answer was `2081`.
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
The next year, to speed up the process, Santa creates a robot version of
|
||||
himself, *Robo-Santa*, to deliver presents with him.
|
||||
|
||||
Santa and Robo-Santa start at the same location (delivering two presents
|
||||
to the same starting house), then take turns moving based on
|
||||
instructions from the elf, who is
|
||||
eggnoggedly
|
||||
reading from the same script as the previous year.
|
||||
|
||||
This year, how many houses receive *at least one present*?
|
||||
|
||||
For example:
|
||||
|
||||
- `^v` delivers presents to `3` houses, because Santa goes north, and
|
||||
then Robo-Santa goes south.
|
||||
- `^>v<` now delivers presents to `3` houses, and Santa and Robo-Santa
|
||||
end up back where they started.
|
||||
- `^v^v^v^v^v` now delivers presents to `11` houses, with Santa going
|
||||
one direction and Robo-Santa going the other.
|
||||
|
||||
Your puzzle answer was `2341`.
|
||||
|
||||
Both parts of this puzzle are complete! They provide two gold stars:
|
||||
\*\*
|
||||
|
||||
At this point, you should [return to your Advent calendar](/2015) and
|
||||
try another puzzle.
|
||||
|
||||
If you still want to see it, you can [get your puzzle
|
||||
input](3/input).
|
||||
|
110
2015/03/solution.py
Normal file
110
2015/03/solution.py
Normal file
@ -0,0 +1,110 @@
|
||||
#!/bin/python3
|
||||
import sys,re
|
||||
from pprint import pprint
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
part = 2
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
|
||||
if part == 1:
|
||||
result = 0
|
||||
arr = []
|
||||
l = 101
|
||||
for i in range(0,l):
|
||||
arr.append([])
|
||||
for j in range(0,l):
|
||||
arr[i].append('O')
|
||||
|
||||
start=int((l-1)/2)
|
||||
|
||||
X = start
|
||||
Y = start
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = list(line.rstrip())
|
||||
arr[X][Y] = 'X'
|
||||
for idx,i in enumerate(tmp):
|
||||
if i == '^':
|
||||
Y -= 1
|
||||
if i == '>':
|
||||
X += 1
|
||||
if i == '<':
|
||||
X -= 1
|
||||
if i == 'v':
|
||||
Y += 1
|
||||
|
||||
arr[X][Y] = 'X'
|
||||
|
||||
for idx,i in enumerate(arr):
|
||||
for jdx,j in enumerate(i):
|
||||
if arr[idx][jdx] == 'X':
|
||||
result += 1
|
||||
print(result)
|
||||
|
||||
|
||||
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
if part == 2:
|
||||
result = 0
|
||||
arr = []
|
||||
l = 101
|
||||
for i in range(0,l):
|
||||
arr.append([])
|
||||
for j in range(0,l):
|
||||
arr[i].append('O')
|
||||
|
||||
start=int((l-1)/2)
|
||||
|
||||
X = start
|
||||
Y = start
|
||||
|
||||
rX = start
|
||||
rY = start
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = list(line.rstrip())
|
||||
arr[X][Y] = 'X'
|
||||
arr[rX][rY] = 'X'
|
||||
for idx,i in enumerate(tmp):
|
||||
if idx % 2 == 0:
|
||||
if i == '^':
|
||||
Y -= 1
|
||||
if i == '>':
|
||||
X += 1
|
||||
if i == '<':
|
||||
X -= 1
|
||||
if i == 'v':
|
||||
Y += 1
|
||||
else:
|
||||
if i == '^':
|
||||
rY -= 1
|
||||
if i == '>':
|
||||
rX += 1
|
||||
if i == '<':
|
||||
rX -= 1
|
||||
if i == 'v':
|
||||
rY += 1
|
||||
|
||||
arr[X][Y] = 'X'
|
||||
arr[rX][rY] = 'X'
|
||||
|
||||
for idx,i in enumerate(arr):
|
||||
for jdx,j in enumerate(i):
|
||||
if arr[idx][jdx] == 'X':
|
||||
result += 1
|
||||
print(result)
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,17 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
for idx,i in enumerate(line):
|
||||
if i == '(':
|
||||
result += 1
|
||||
if i == ')':
|
||||
result -= 1
|
||||
print(result)
|
@ -1,20 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
for idx,i in enumerate(line):
|
||||
if i == '(':
|
||||
result += 1
|
||||
if i == ')':
|
||||
result -= 1
|
||||
if result == -1:
|
||||
print(idx+1)
|
||||
break
|
||||
print(result)
|
@ -1 +0,0 @@
|
||||
))(((((
|
1000
2015/day2/input
1000
2015/day2/input
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = line.rstrip().split('x')
|
||||
tmp = list(map(int,tmp))
|
||||
first = tmp[0] * tmp[1]
|
||||
second = tmp[1] * tmp[2]
|
||||
third = tmp[2] * tmp[0]
|
||||
#2*l*w + 2*w*h + 2*h*l
|
||||
smallest = min(first,second,third)
|
||||
#print(first,second, third, smallest)
|
||||
result = result + (2*first) + (2*second) + (2*third) + smallest
|
||||
print(result)
|
@ -1,24 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = line.rstrip().split('x')
|
||||
tmp = list(map(int,tmp))
|
||||
first = tmp[0] * tmp[1]
|
||||
second = tmp[1] * tmp[2]
|
||||
third = tmp[2] * tmp[0]
|
||||
#2*l*w + 2*w*h + 2*h*l
|
||||
smallest = min(first,second,third)
|
||||
#print(first,second, third, smallest)
|
||||
tmp.sort()
|
||||
rib = tmp[0]+tmp[0]+tmp[1]+tmp[1]
|
||||
bow = tmp[0]*tmp[1]*tmp[2]
|
||||
result = result + rib + bow
|
||||
print(result)
|
@ -1,2 +0,0 @@
|
||||
2x3x4
|
||||
1x1x10
|
File diff suppressed because one or more lines are too long
@ -1,41 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
arr = []
|
||||
l = 101
|
||||
for i in range(0,l):
|
||||
arr.append([])
|
||||
for j in range(0,l):
|
||||
arr[i].append('O')
|
||||
|
||||
start=int((l-1)/2)
|
||||
|
||||
X = start
|
||||
Y = start
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = list(line.rstrip())
|
||||
arr[X][Y] = 'X'
|
||||
for idx,i in enumerate(tmp):
|
||||
if i == '^':
|
||||
Y -= 1
|
||||
if i == '>':
|
||||
X += 1
|
||||
if i == '<':
|
||||
X -= 1
|
||||
if i == 'v':
|
||||
Y += 1
|
||||
|
||||
arr[X][Y] = 'X'
|
||||
|
||||
for idx,i in enumerate(arr):
|
||||
for jdx,j in enumerate(i):
|
||||
if arr[idx][jdx] == 'X':
|
||||
result += 1
|
||||
print(result)
|
@ -1,56 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
arr = []
|
||||
l = 101
|
||||
for i in range(0,l):
|
||||
arr.append([])
|
||||
for j in range(0,l):
|
||||
arr[i].append('O')
|
||||
|
||||
start=int((l-1)/2)
|
||||
|
||||
X = start
|
||||
Y = start
|
||||
|
||||
rX = start
|
||||
rY = start
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = list(line.rstrip())
|
||||
arr[X][Y] = 'X'
|
||||
arr[rX][rY] = 'X'
|
||||
for idx,i in enumerate(tmp):
|
||||
if idx % 2 == 0:
|
||||
if i == '^':
|
||||
Y -= 1
|
||||
if i == '>':
|
||||
X += 1
|
||||
if i == '<':
|
||||
X -= 1
|
||||
if i == 'v':
|
||||
Y += 1
|
||||
else:
|
||||
if i == '^':
|
||||
rY -= 1
|
||||
if i == '>':
|
||||
rX += 1
|
||||
if i == '<':
|
||||
rX -= 1
|
||||
if i == 'v':
|
||||
rY += 1
|
||||
|
||||
arr[X][Y] = 'X'
|
||||
arr[rX][rY] = 'X'
|
||||
|
||||
for idx,i in enumerate(arr):
|
||||
for jdx,j in enumerate(i):
|
||||
if arr[idx][jdx] == 'X':
|
||||
result += 1
|
||||
print(result)
|
@ -1 +0,0 @@
|
||||
^v
|
@ -1 +0,0 @@
|
||||
^>v<
|
@ -1 +0,0 @@
|
||||
^v^v^v^v^v
|
Loading…
Reference in New Issue
Block a user