Cleaned up 2015
This commit is contained in:
parent
feed239050
commit
d97ebb0f6b
@ -22,13 +22,19 @@ For example:
|
||||
to make an MD5 hash starting with five zeroes is `1048970`; that is,
|
||||
the MD5 hash of `pqrstuv1048970` looks like `000006136ef...`.
|
||||
|
||||
Your puzzle answer was `254575`.
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
Now find one that starts with *six zeroes*.
|
||||
|
||||
Your puzzle answer was `1038736`.
|
||||
|
||||
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.
|
||||
|
||||
Your puzzle input was `bgvyzdsv`{.puzzle-input}.
|
||||
|
||||
|
@ -6,7 +6,7 @@ from fred import list2int
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
part = 2
|
||||
part = 1
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
|
75
2015/06/6.md
Normal file
75
2015/06/6.md
Normal file
@ -0,0 +1,75 @@
|
||||
## \-\-- Day 6: Probably a Fire Hazard \-\--
|
||||
|
||||
Because your neighbors keep defeating you in the holiday house
|
||||
decorating contest year after year, you\'ve decided to deploy one
|
||||
million lights in a [1000x1000
|
||||
grid]{title="Hey, be glad I'm not asking for the resistance between two points!"}.
|
||||
|
||||
Furthermore, because you\'ve been especially nice this year, Santa has
|
||||
mailed you instructions on how to display the ideal lighting
|
||||
configuration.
|
||||
|
||||
Lights in your grid are numbered from 0 to 999 in each direction; the
|
||||
lights at each corner are at `0,0`, `0,999`, `999,999`, and `999,0`. The
|
||||
instructions include whether to `turn on`, `turn off`, or `toggle`
|
||||
various inclusive ranges given as coordinate pairs. Each coordinate pair
|
||||
represents opposite corners of a rectangle, inclusive; a coordinate pair
|
||||
like `0,0 through 2,2` therefore refers to 9 lights in a 3x3 square. The
|
||||
lights all start turned off.
|
||||
|
||||
To defeat your neighbors this year, all you have to do is set up your
|
||||
lights by doing the instructions Santa sent you in order.
|
||||
|
||||
For example:
|
||||
|
||||
- `turn on 0,0 through 999,999` would turn on (or leave on) every
|
||||
light.
|
||||
- `toggle 0,0 through 999,0` would toggle the first line of 1000
|
||||
lights, turning off the ones that were on, and turning on the ones
|
||||
that were off.
|
||||
- `turn off 499,499 through 500,500` would turn off (or leave off) the
|
||||
middle four lights.
|
||||
|
||||
After following the instructions, *how many lights are lit*?
|
||||
|
||||
Your puzzle answer was `377891`.
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
You just finish implementing your winning light pattern when you realize
|
||||
you mistranslated Santa\'s message from Ancient Nordic Elvish.
|
||||
|
||||
The light grid you bought actually has individual brightness controls;
|
||||
each light can have a brightness of zero or more. The lights all start
|
||||
at zero.
|
||||
|
||||
The phrase `turn on` actually means that you should increase the
|
||||
brightness of those lights by `1`.
|
||||
|
||||
The phrase `turn off` actually means that you should decrease the
|
||||
brightness of those lights by `1`, to a minimum of zero.
|
||||
|
||||
The phrase `toggle` actually means that you should increase the
|
||||
brightness of those lights by `2`.
|
||||
|
||||
What is the *total brightness* of all lights combined after following
|
||||
Santa\'s instructions?
|
||||
|
||||
For example:
|
||||
|
||||
- `turn on 0,0 through 0,0` would increase the total brightness by
|
||||
`1`.
|
||||
- `toggle 0,0 through 999,999` would increase the total brightness by
|
||||
`2000000`.
|
||||
|
||||
Your puzzle answer was `14110788`.
|
||||
|
||||
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](6/input).
|
||||
|
90
2015/06/solution.py
Normal file
90
2015/06/solution.py
Normal file
@ -0,0 +1,90 @@
|
||||
#!/bin/python3
|
||||
import sys,time,re
|
||||
from pprint import pprint
|
||||
from collections import defaultdict
|
||||
from itertools import product
|
||||
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int,get_re,nprint,lprint,loadFile
|
||||
start_time = time.time()
|
||||
|
||||
input_f = 'input'
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
# #
|
||||
#########################################
|
||||
def part1():
|
||||
instructions = []
|
||||
|
||||
with open(input_f) as file:
|
||||
tmp = []
|
||||
for line in file:
|
||||
tmp = [re.match(r'.+?(?=\d)',line).group().strip()]
|
||||
tmp += [int(i) for i in re.findall(r'\d+',line)]
|
||||
instructions.append(tmp)
|
||||
|
||||
size = 1000
|
||||
maps = defaultdict(bool)
|
||||
|
||||
for i in instructions:
|
||||
for x in product(range(i[1],i[3]+1),range(i[2],i[4]+1)):
|
||||
if i[0] == 'turn off':
|
||||
maps[x] = False
|
||||
elif i[0] == 'turn on':
|
||||
maps[x] = True
|
||||
else:
|
||||
if maps[x] == True:
|
||||
maps[x] = False
|
||||
else:
|
||||
maps[x] = True
|
||||
count = 0
|
||||
|
||||
for i in product(range(0,size),range(0,size)):
|
||||
if maps[i] == True:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
start_time = time.time()
|
||||
print('Part 1:',part1(), '\t\t', round((time.time() - start_time)*1000), 'ms')
|
||||
|
||||
|
||||
#########################################
|
||||
# #
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
def part2():
|
||||
instructions = []
|
||||
|
||||
with open(input_f) as file:
|
||||
tmp = []
|
||||
for line in file:
|
||||
tmp = [re.match(r'.+?(?=\d)',line).group().strip()]
|
||||
tmp += [int(i) for i in re.findall(r'\d+',line)]
|
||||
instructions.append(tmp)
|
||||
|
||||
size = 1000
|
||||
|
||||
maps = defaultdict(int)
|
||||
|
||||
for i in instructions:
|
||||
for x in product(range(i[1],i[3]+1),range(i[2],i[4]+1)):
|
||||
if i[0] == 'turn off':
|
||||
if maps[x] != 0:
|
||||
maps[x] -= 1
|
||||
elif i[0] == 'turn on':
|
||||
maps[x] += 1
|
||||
else:
|
||||
maps[x] += 2
|
||||
|
||||
count = 0
|
||||
|
||||
for i in product(range(0,size),range(0,size)):
|
||||
count += maps[i]
|
||||
|
||||
return count
|
||||
|
||||
start_time = time.time()
|
||||
print('Part 2:',part2(), '\t', round((time.time() - start_time)*1000), 'ms')
|
@ -1 +0,0 @@
|
||||
bgvyzdsv
|
@ -1,31 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
import hashlib
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
count = 0
|
||||
found = False
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = line.rstrip()
|
||||
while found == False:
|
||||
m = hashlib.md5()
|
||||
text = tmp + str(count)
|
||||
#print(text)
|
||||
m.update(text.encode('UTF-8'))
|
||||
nr = m.hexdigest()
|
||||
#print(nr)
|
||||
|
||||
if nr[0:5] == '00000':
|
||||
print(count)
|
||||
print(text)
|
||||
print(nr)
|
||||
found = True
|
||||
else:
|
||||
count += 1
|
||||
#print(nr[ 0 : 5 ])
|
||||
found = False
|
@ -1,31 +0,0 @@
|
||||
#!/bin/python3
|
||||
|
||||
import sys
|
||||
from pprint import pprint
|
||||
import hashlib
|
||||
|
||||
input_f = sys.argv[1]
|
||||
|
||||
result = 0
|
||||
count = 0
|
||||
found = False
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
tmp = line.rstrip()
|
||||
while found == False:
|
||||
m = hashlib.md5()
|
||||
text = tmp + str(count)
|
||||
#print(text)
|
||||
m.update(text.encode('UTF-8'))
|
||||
nr = m.hexdigest()
|
||||
#print(nr)
|
||||
|
||||
if nr[0:6] == '000000':
|
||||
print(count)
|
||||
print(text)
|
||||
print(nr)
|
||||
found = True
|
||||
else:
|
||||
count += 1
|
||||
#print(nr[ 0 : 5 ])
|
||||
found = False
|
@ -1,2 +0,0 @@
|
||||
abcdef
|
||||
pqrstuv
|
1000
2015/day5/input
1000
2015/day5/input
File diff suppressed because it is too large
Load Diff
@ -1,40 +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()
|
||||
print(tmp)
|
||||
vowel_count = 0
|
||||
t = ['ab','cd','pq','xy']
|
||||
first = False
|
||||
second = False
|
||||
for i in t:
|
||||
if tmp.find(i) != -1:
|
||||
print(" is naughty because it contains " + i)
|
||||
first = True
|
||||
break
|
||||
f = 'aeiou'
|
||||
for idx,i in enumerate(tmp):
|
||||
if idx+1 < len(tmp) and first == False:
|
||||
#print(idx,idx+1,len(tmp))
|
||||
if i == tmp[idx+1]:
|
||||
second = True
|
||||
if second == False and first == False:
|
||||
print("naughte cus no double")
|
||||
for idx,i in enumerate(tmp):
|
||||
if f.find(i) != -1 and second == True and first == False:
|
||||
vowel_count += 1
|
||||
if vowel_count == 3:
|
||||
print(" is nice because it contains " + str(vowel_count) + " vowels and double letters")
|
||||
result += 1
|
||||
if second == True and vowel_count < 3:
|
||||
print("naughty cus " + str(vowel_count) + " vowels")
|
||||
print()
|
||||
print(result)
|
@ -1,40 +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()
|
||||
print(tmp)
|
||||
vowel_count = 0
|
||||
t = ['ab','cd','pq','xy']
|
||||
first = False
|
||||
second = False
|
||||
for i in t:
|
||||
if tmp.find(i) != -1:
|
||||
print(" is naughty because it contains " + i)
|
||||
first = True
|
||||
break
|
||||
f = 'aeiou'
|
||||
for idx,i in enumerate(tmp):
|
||||
if idx+1 < len(tmp) and first == False:
|
||||
#print(idx,idx+1,len(tmp))
|
||||
if i == tmp[idx+1]:
|
||||
second = True
|
||||
if second == False and first == False:
|
||||
print("naughte cus no double")
|
||||
for idx,i in enumerate(tmp):
|
||||
if f.find(i) != -1 and second == True and first == False:
|
||||
vowel_count += 1
|
||||
if vowel_count == 3:
|
||||
print(" is nice because it contains " + str(vowel_count) + " vowels and double letters")
|
||||
result += 1
|
||||
if second == True and vowel_count < 3:
|
||||
print("naughty cus " + str(vowel_count) + " vowels")
|
||||
print()
|
||||
print(result)
|
@ -1,5 +0,0 @@
|
||||
ugknbfddgicrmopn
|
||||
aaa
|
||||
jchzalrnumimnmhp
|
||||
haegwjzuvuyypxyu
|
||||
dvszwmarrgswjxmb
|
@ -1,3 +0,0 @@
|
||||
turn on 2,3 through 4,4
|
||||
turn off 1,2 through 3,2
|
||||
toggle 5,0 through 7,3
|
@ -13,6 +13,7 @@ with open(sys.argv[1]) as file:
|
||||
tmp += [int(i) for i in re.findall(r'\d+',line)]
|
||||
instructions.append(tmp)
|
||||
|
||||
print(instructions)
|
||||
size = 1000
|
||||
|
||||
maps = defaultdict(bool)
|
||||
|
@ -1,35 +0,0 @@
|
||||
import sys
|
||||
from pprint import pprint
|
||||
import re
|
||||
from itertools import product
|
||||
from collections import defaultdict
|
||||
|
||||
instructions = []
|
||||
|
||||
with open(sys.argv[1]) as file:
|
||||
tmp = []
|
||||
for line in file:
|
||||
tmp = [re.match(r'.+?(?=\d)',line).group().strip()]
|
||||
tmp += [int(i) for i in re.findall(r'\d+',line)]
|
||||
instructions.append(tmp)
|
||||
|
||||
size = 1000
|
||||
|
||||
maps = defaultdict(int)
|
||||
|
||||
for i in instructions:
|
||||
for x in product(range(i[1],i[3]+1),range(i[2],i[4]+1)):
|
||||
if i[0] == 'turn off':
|
||||
if maps[x] != 0:
|
||||
maps[x] -= 1
|
||||
elif i[0] == 'turn on':
|
||||
maps[x] += 1
|
||||
else:
|
||||
maps[x] += 2
|
||||
|
||||
count = 0
|
||||
|
||||
for i in product(range(0,size),range(0,size)):
|
||||
count += maps[i]
|
||||
|
||||
print(count)
|
Loading…
Reference in New Issue
Block a user