Init (tm day3)
This commit is contained in:
4
day1/day1.py
Normal file
4
day1/day1.py
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Hoi Day 1!")
|
||||
0
day1/input.txt
Normal file
0
day1/input.txt
Normal file
45
day2/day2.py
Normal file
45
day2/day2.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
def validate_password(line):
|
||||
parts = re.split('([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)', line)
|
||||
lower = int(parts[1])
|
||||
upper = int(parts[2])
|
||||
char = parts[3]
|
||||
|
||||
password = parts[4]
|
||||
password = re.sub('[^%s]'% char, '', parts[4])
|
||||
length = len(password)
|
||||
if(length >= lower and length <= upper):
|
||||
return True
|
||||
|
||||
def validate_password_2(line):
|
||||
parts = re.split('([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)', line)
|
||||
lower = int(parts[1]) - 1
|
||||
upper = int(parts[2]) - 1
|
||||
char = parts[3]
|
||||
|
||||
password = parts[4]
|
||||
|
||||
if((password[lower] is char) is not (password[upper] is char)):
|
||||
return True
|
||||
|
||||
def part1():
|
||||
count = 0
|
||||
with open("day2/input.txt") as input:
|
||||
for line in input:
|
||||
if validate_password(line) == True:
|
||||
count += 1
|
||||
print("Day 1: %d"% count)
|
||||
|
||||
def part2():
|
||||
count = 0
|
||||
with open("day2/input.txt") as input:
|
||||
for line in input:
|
||||
if validate_password_2(line) == True:
|
||||
count += 1
|
||||
print("Day 2: %d"% count)
|
||||
|
||||
if __name__ == "__main__":
|
||||
part1();
|
||||
part2();
|
||||
1000
day2/input.txt
Normal file
1000
day2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
33
day3/day3.py
Normal file
33
day3/day3.py
Normal file
@@ -0,0 +1,33 @@
|
||||
lines = []
|
||||
|
||||
def load():
|
||||
global lines
|
||||
file = open("day3/input.txt")
|
||||
lines = file.readlines()
|
||||
|
||||
def trees(right, down):
|
||||
width = 0
|
||||
height = 0
|
||||
line_width = 31
|
||||
count = 0
|
||||
|
||||
while height < len(lines):
|
||||
line = lines[height]
|
||||
if(line[width % line_width] == "#"):
|
||||
count += 1
|
||||
width += right
|
||||
height += down
|
||||
|
||||
return count
|
||||
|
||||
def part1():
|
||||
print("Part 1: %d"% trees(3,1))
|
||||
|
||||
def part2():
|
||||
count = trees(1,1) * trees(3,1) * trees(5,1) * trees(7,1) * trees(1,2)
|
||||
print("Part 2: %d" % count)
|
||||
|
||||
if __name__ == "__main__":
|
||||
load()
|
||||
part1()
|
||||
part2()
|
||||
323
day3/input.txt
Normal file
323
day3/input.txt
Normal file
@@ -0,0 +1,323 @@
|
||||
....#..#.................#..#..
|
||||
#..#.#.#..#.###.#..#...#..#....
|
||||
.#....#......#.#.#..##...#...#.
|
||||
.............#.#..#........#.#.
|
||||
............##.#..#...##.###...
|
||||
.....#..#......#......##.......
|
||||
........##........#...........#
|
||||
..................#..#.........
|
||||
......#..#...#..#......###..#..
|
||||
.#....#...........#.....#.##...
|
||||
..#..#.#........###..#....#...#
|
||||
..#..##..#..#....#..#......#...
|
||||
......#....................#...
|
||||
.........#..#..................
|
||||
..#.#.....#......#.#....#...#..
|
||||
..#..........##.......##.##....
|
||||
#.......#.##.....#...#....#....
|
||||
####..............###.#....#...
|
||||
....#........#.#..###..#...#..#
|
||||
#.#......#...#.##....#.....#...
|
||||
.......#......#.....#........#.
|
||||
.##.........#...#.........#....
|
||||
............#....#.#........#..
|
||||
#..##..#....#...#.#....#....#..
|
||||
.....#....##..#................
|
||||
.#...........#....#..#.....#...
|
||||
......#.#...#..###.............
|
||||
#...#...........#..###.#..#..#.
|
||||
...................#..#....#..#
|
||||
....#...#...#.#.....#....#.##..
|
||||
.......#.......#.#.........#...
|
||||
#..#.......#...#..#.#......#...
|
||||
..##...........#....#..#.......
|
||||
.#...............#...##........
|
||||
.....#..........#............#.
|
||||
..#.......#.#.#...........#..#.
|
||||
........#..#.#.#........#.#.##.
|
||||
.###..............#.#..........
|
||||
.#....###.....#......#....#....
|
||||
............#.#......#..#....#.
|
||||
.#.#.............#........##...
|
||||
.....#..###....##.....#....#..#
|
||||
.##....#...#.#.........#......#
|
||||
....##.......#...............##
|
||||
..........##.##.......#........
|
||||
......#....##.........##.#.#.#.
|
||||
..............#....#..#......#.
|
||||
......##.........#.........#...
|
||||
.#...##...##....##..#..#.....#.
|
||||
.#......#.###.#....#...#......#
|
||||
.##.......................#..#.
|
||||
....#......#.##..........#.###.
|
||||
.#.....##..........#.#.........
|
||||
....#.#.........#...#..........
|
||||
.#..##.#....##.......#.......#.
|
||||
.........#.......#............#
|
||||
###..........#.....##.#....#...
|
||||
.......###.#....#........#...##
|
||||
..#..#....#.......#.#..........
|
||||
.#..#..........#......#...#....
|
||||
.....###.#..#.....#...#..#.....
|
||||
........#.#.#..........#.#..#..
|
||||
........#...##.................
|
||||
...#.............#.#..#......##
|
||||
......#......##......#...#.#..#
|
||||
.#..#...##..........#...##.....
|
||||
..#.#....####..#...#....##....#
|
||||
.#..##.........#..##......#....
|
||||
#....#.#.........#.............
|
||||
....###..............#....#....
|
||||
....#..#..#...###..#.#..#.#....
|
||||
....#.....#...........###..#...
|
||||
....#.#.....#...#.....#.......#
|
||||
..#.......#..................#.
|
||||
#...................##.........
|
||||
....#.#.#.#.#.....#.....#......
|
||||
...............##..#..##.#...##
|
||||
..#.....#.....##.........#..#..
|
||||
...#...#.....#..##..##....#..##
|
||||
..#.................#....#...#.
|
||||
#....##...............##..#....
|
||||
..#.....#.....##.........##...#
|
||||
..#.###..............#...#.....
|
||||
.......................#.......
|
||||
#...#..#.....##...#...#........
|
||||
..........#......#.###....#...#
|
||||
..#.....#.##.#..#.#.......#....
|
||||
#.##...#............#..........
|
||||
#........#.#.#..#...#..#.....##
|
||||
#............#.#...............
|
||||
.#..#.......#.#.....#.#......##
|
||||
.#.#....#........#..##.........
|
||||
..#....#......#.#...##...#.....
|
||||
##.....#......................#
|
||||
...#.......#..##.....#........#
|
||||
......##..#...............##...
|
||||
.....#...#......##....#.#......
|
||||
.#...#....#.#.#........#...#.#.
|
||||
.......#...#...##...#..........
|
||||
.##..#..##........##....###.#..
|
||||
..##........#........##........
|
||||
............#....#......#......
|
||||
.......#...........#.......#...
|
||||
#.#......##.#...#....#.#.....#.
|
||||
..#.#.#......##........#....#..
|
||||
#.#.####.#..#..........#.......
|
||||
......................#.#......
|
||||
...#.......#.....#......#..#.#.
|
||||
...#....#....##..........#..##.
|
||||
......#......#....#.........#..
|
||||
.........#....#...#.#.........#
|
||||
.....#...##.#.#.#......#.....#.
|
||||
........#...#......#.#....#....
|
||||
.....#.........#.............#.
|
||||
.#...........#.#....##.......#.
|
||||
.#..#......#....#....#....#....
|
||||
#.......#.#.#.#..#.......#.....
|
||||
..#...#...#......#.............
|
||||
.....#.......#..#.........##..#
|
||||
#..##...........#.#.........#..
|
||||
#..#..........#....#......#...#
|
||||
#...#............#....##..#.##.
|
||||
....#.#..#....#.........##..##.
|
||||
.........#..........#.......##.
|
||||
#...#........................#.
|
||||
....#....#..#...........##...#.
|
||||
.....###.###.#....#.....#.....#
|
||||
.#..###..#...##..........#.....
|
||||
#..#.....#...#........#........
|
||||
.#..##..#......#.....#......##.
|
||||
#.....##........#.#..#....#.#..
|
||||
.#....#...#..#...............#.
|
||||
..........#.#........#.....#...
|
||||
..#.#.....#....#........#.###..
|
||||
...#..#...#.##.....#..........#
|
||||
..#......##....................
|
||||
.....#...#....#..#....#.......#
|
||||
......#............#....#...#..
|
||||
.#..#....#.....#........##.....
|
||||
...#..#.......#...............#
|
||||
##.#..#...............#.#..##..
|
||||
..#.........#.####.####........
|
||||
.........#...#.#........#..###.
|
||||
..###.....#.........##........#
|
||||
#..##.....##.#..........#....##
|
||||
.#..#....###..#.....##..#......
|
||||
#...#..#........#.............#
|
||||
#.#....#........#.........#.###
|
||||
.....#....#.###.......#........
|
||||
...........#............#..#...
|
||||
..........#.#..##......###....#
|
||||
..##....#...........#....#....#
|
||||
..#...##.#.......#.##.......#..
|
||||
.......#......#..........#....#
|
||||
.........#..#..............####
|
||||
#.#...#...#......#...#..#...#.#
|
||||
.#.#...#.....#.......#.#..##.#.
|
||||
......##..##...#...............
|
||||
....#....#...##.......#.#......
|
||||
.............................#.
|
||||
..##...#.......#......#.......#
|
||||
.#.##.##....#......##.......#..
|
||||
.......##..#....#.##.#.#.......
|
||||
....#.............#......#..#..
|
||||
...#.........#....#..#.....#.#.
|
||||
......#......#......#.........#
|
||||
........#..#.#.....#.....#...#.
|
||||
.#.......#.........#...#.......
|
||||
#.#.##.....#...#...............
|
||||
..#.......##.....#............#
|
||||
.................##.#..#.....##
|
||||
........#.###....#.......##.#..
|
||||
....#.#..#..#.......#.#....#..#
|
||||
.#..#..#..#...##....#..#.....#.
|
||||
...#..#...#..........#........#
|
||||
...........##....#...##.#...###
|
||||
.##..#.......##.....##....#....
|
||||
...#.#..#..#..##..#.....##.....
|
||||
.#.....#..........#...#........
|
||||
.....#..#.#..#.................
|
||||
..#.......#..#.....##.......#..
|
||||
............##.##.....#...#....
|
||||
#......#......................#
|
||||
...#..........#...#...#..#.....
|
||||
......##..............##.##....
|
||||
................##......#.###..
|
||||
.###...#..........#...........#
|
||||
#....#...#.........##......#...
|
||||
.............#...............#.
|
||||
.###.....#......#...#.......#..
|
||||
......##..#.#.#.....#........#.
|
||||
..#.#..........#.#......##.....
|
||||
.#.#...#.#.....#.#..#.....#....
|
||||
.......#....#.#....##..........
|
||||
#.........#........####.#......
|
||||
...#..#.....#..............#.#.
|
||||
...#..........................#
|
||||
..##....#..#..........#....#...
|
||||
..##.##.#.#.#......#..#........
|
||||
...#..#.#.#..#........#.......#
|
||||
.....#.....#..#...#........##..
|
||||
..#..#...........#...##..##..#.
|
||||
#.....#.....#..#..##........#..
|
||||
...#..............#......#..#..
|
||||
...#.#...........###...#.#.....
|
||||
..........................#.#..
|
||||
....#........#..#..........#.#.
|
||||
.#..#..........#.#..........#..
|
||||
....#.........#......#.#....#..
|
||||
..#........#.................#.
|
||||
...#......#............#.......
|
||||
...#.#...#..##....#........#...
|
||||
......##.#....#.#......#.......
|
||||
........#..........#........#..
|
||||
###..#.....#...#......#...###..
|
||||
..##...#..###............#...#.
|
||||
#.......#..#..#............##..
|
||||
#........####......#...........
|
||||
#..#..#...........#.......####.
|
||||
......#..##................#...
|
||||
.....#..##......#.#...#..#.....
|
||||
......#.....##.....#.###.......
|
||||
.#.....#.........#.......#.#..#
|
||||
.##...........###...#....#...#.
|
||||
.#....#..#....#.##...#.........
|
||||
.................##............
|
||||
......#......#.............#...
|
||||
.........##.#........#....#...#
|
||||
..##....#.......#....##.#......
|
||||
.......#.#.#.....##..#.#.......
|
||||
......#.#.#.#......#...#.......
|
||||
....##...#.....#..#......#.....
|
||||
..............#......#.##......
|
||||
#.##..###........#.##........##
|
||||
#..#.........#.#......#.#......
|
||||
.#..###.......#................
|
||||
..............#...#..##.#.#....
|
||||
.....#..#........#...##.#...#..
|
||||
.#...##.....#........#..###.#..
|
||||
....#.....#...#........#.......
|
||||
....#.##.....#....#............
|
||||
#.#..#....#....#............#..
|
||||
....#....#...#.#...#...######..
|
||||
.##.........#..#.....#.....#...
|
||||
..##...............#...........
|
||||
........##...#........#..#.....
|
||||
...#................###.##..##.
|
||||
.#..#..#..#...#.............#..
|
||||
#.....#..##.#....#.#......#..#.
|
||||
...#...#...#.....#...#...#.....
|
||||
..##.###..#..#...##...........#
|
||||
.#.......##........#.#..#..#...
|
||||
..#.......#.###................
|
||||
..#...#........##...#..#......#
|
||||
...#...#............#.#......#.
|
||||
..#...#.....#.#.#.#........#...
|
||||
.#........#......##....##...#..
|
||||
...#..##....#.........#....#.#.
|
||||
....#........##...............#
|
||||
.###.....#...#..#.#.....#.....#
|
||||
..#...#..................#...##
|
||||
#..#....###....................
|
||||
...........#...#...........#...
|
||||
........#.....#................
|
||||
#........#...........#........#
|
||||
........#..#....#...#....#..#..
|
||||
#.#....#......#.......##.......
|
||||
.#.....##..#...#......#.#.#....
|
||||
..#..##.#.....#...#.#......#.#.
|
||||
.##....#...#....#......##......
|
||||
.#..#..#...##.##..#.#..#.......
|
||||
.....#.#...........#.#........#
|
||||
.#...#....#..................#.
|
||||
...........#...#.........#.....
|
||||
.#..###........##......#..#...#
|
||||
.............###..##.....#.#..#
|
||||
.#..#..........#......#........
|
||||
..#........#.#...#.......##.#..
|
||||
....#...........##......#...#..
|
||||
...........#....#.....#...#.#..
|
||||
...#...........#.....#.#..#..#.
|
||||
......#.......#................
|
||||
##.......#.....#............#.#
|
||||
.##.....#.#.#..................
|
||||
..........#.....##..#.#.#......
|
||||
.###.#.....##...#..#.#........#
|
||||
#....#........##..#..#.........
|
||||
.............#.........##..#...
|
||||
......##.#...#.#.#....##.......
|
||||
.#.......###.#.###..##........#
|
||||
..##.....#..#.............#..#.
|
||||
.#...#......#.#.............#..
|
||||
..##.#...#.........##....#...#.
|
||||
...........#......#.#..........
|
||||
.....#..#...##.....#....#..#...
|
||||
#...................##...#.....
|
||||
..#.................#.....#....
|
||||
..............#..#.#...###.....
|
||||
.......#........#...#.....#....
|
||||
.............#.......#...##..#.
|
||||
.#...#..#...#..#.....#......#.#
|
||||
....#..#..#...#...........#....
|
||||
.....#..#......##.##....#..#...
|
||||
...#......#..#.#...#.....#.....
|
||||
.......##..#.#.......#..#....##
|
||||
#.#..#....##.##.#.#..........#.
|
||||
..........#..........#....##.#.
|
||||
....#.................#...#..#.
|
||||
...#.....#..#...#.#...#..#.....
|
||||
....#.#..###....#.............#
|
||||
#....#..#.#..........#..#..#...
|
||||
...#..#......#...#...#...#...#.
|
||||
##....#.......#..........#.....
|
||||
#......#.........#...#.........
|
||||
##...##.#....#....#..#..#.#....
|
||||
....#..#.....#.##.#.......#.#..
|
||||
..##....##....#...#..####...#.#
|
||||
..##..........#.............#..
|
||||
..#......#..............#......
|
||||
...#......#..#.#...#.......#...
|
||||
.#............#....#...##.##..#
|
||||
..##..........#...........#..#.
|
||||
..#..##..#....#..#.#..#..#..#..
|
||||
Reference in New Issue
Block a user