More test scripts

This commit is contained in:
K. Lange 2021-01-04 19:59:11 +09:00
parent 873ffb3428
commit 6195649458
5 changed files with 1532 additions and 0 deletions

323
test/day3.in Normal file
View File

@ -0,0 +1,323 @@
.............#...#....#.....##.
.#...##.........#.#.........#.#
.....##......#.......#.........
.......#...........#.#.........
#...........#...#..#.#......#..
.........##....#.#...#.........
.....#.........#.#...........#.
....#...............##....##...
#.#.............#..#.......#.#.
...#...........................
......#..#....#.............#..
........#......#.......#.......
....#.....#..#.#...#.........#.
..#.#.......#.##...#....#.....#
...........#.........#..#......
#...........#.#..#...#.#.#....#
........#......................
....#.#.....#....#.......#..#..
.............................#.
....##..........#.....##......#
......#.....................#..
..#.....##.......#.............
....#.#..............#.#.......
..#.#........#.....#..##.......
.....#...##.........##....#.#..
.#....#..#..#...........#......
.............#.....##........#.
..#....#............#.........#
###..........#........#.......#
#...#..#.#.#.........#..#......
..#....#......#.............#..
#...#........#..#...#.....#....
.#..........#.#........#.......
#.....#.........#..#......#....
....#....##........#......#....
.......#....#.....#..#..#.....#
.........#...#.#...#.##........
.##.##...........#..##..#......
.#.##....#........#...#........
.......##.........##.####.....#
....#..##....#.................
.#........#..........#.........
##....##..........##........#..
#......#...........#....#..#...
.......#..#....##..##.....#....
.........#.#.#...#.....#.......
......#...#...#....#......#....
##....#..........#....##....##.
###.........#...#...#..........
#.....##.#........#.......#....
#...............#...##.#......#
..#.....####.###......#......#.
....#.......#..........#.......
....##..............#.#.#......
.......##..#.......#...........
..#.......##....#.......###...#
........#...#.......#.#...#....
.........##....#..#....#.......
............#.#.......#.#......
.....#.....#...#....#.##.......
.......#.........#.......#.....
.#..#...#.....#............#.##
.......#.#......##.............
##.#......#.....#.#............
.#....#.....#............#...#.
.........#.......#.#...........
#............#.##...#..#...#.#.
......#....#.......#....#......
..........#........#..#.#......
#..##.......#.........#..#.....
.........#.....##........#.#..#
..#................#...........
....#..#........##.........#..#
###...#....##.#......##.......#
.......#......##..#.......#....
.......###...#...#..........##.
................#.......#......
.#......##.##........#.........
....##.#.....##.......#........
...........#...........#.....#.
..#........#..#.#...#.#........
#...............#...#.##.##.#.#
................#.......#......
.#..#......#........#.#........
...##..#.......#.......#..#....
.#.....#.#....##..#........#...
........##......#..........#...
.#.......#.......#...#..#......
.#..##.....#....#............#.
...#..........#....#........#..
..#.#..#.......#.#.##..........
#........###.....#.#.......#.##
.....#....##.............#.#..#
..##............#...##.........
...#.........#...........#.....
...#......#.#...#..###.........
.............#...##............
.....##..##.####.#..#......#.#.
.#...#.....#.....#.#.....#.....
.........#.......###.....#..##.
.##.#..#..........#.##.#.#.....
.#...#...#.#.##......#..#......
.............#......#......#...
#.....................#......#.
...#.....#.....#....#........#.
................##..#....#..#..
#.###...#.....................#
...#..#....#.......#.........#.
...........#..#..#...........#.
.......#..#......#....#.#......
..........#......#..#....#.....
.#.#.....#...#.#...#...#.#....#
.....#.......#............#...#
#.#....#......#......#........#
.#.#..#.........##...#.........
#..###..#......................
..#.#..#.......................
.##.....#...#......#..#........
...#...........#...#.......##..
..#...........#........#.......
........#....#.....#.#.........
..........#...........#.....#..
......#...#...##.#.............
.#...#...##....................
............###.........#......
.#.#...................#..#....
....#.#...#.#........#.#.......
....#...#...........#.......#.#
...........#............#...##.
.....####....#.#......#.#......
.##.............#............#.
......#.........#............##
#.#....#...##....#.......#....#
.....#.#....#..#..#...#..#.#..#
.........................#.....
......#.#....###.......#....#..
.....................##.#...#.#
..#.....#.#.#...#...#..........
........#..##........#...#...#.
..........#.#.##....#....##....
.............#..#..............
..#.##..#.......#...#..#..##..#
..#..#....#.#..........#..#....
..........#....#...#......#....
.##...#.......................#
.#.....#....#..........#.......
...........#..#......##.....#..
......###.#..##....#...#.##....
.......#..#.#....#.............
...#..#......##.........###.#..
...........#............##...#.
...#...#...........##.....#....
..................#............
.#.#.#...#..............#..##..
#.#....#........#.........#.##.
#.#.#.......#.....#..........#.
...##.....##.#.....#...........
.#....#..............##...##..#
........##.....................
#..#..#.....###.............#..
.......#...........#...........
.........#.....................
.......#...#...#.....##........
......#.........#........#.....
...#....##..#.####.#.......#.#.
.....#..#......#........#.##..#
.##....#......##......#...###..
..###.#........##.#...#.......#
............#......##....#.#...
.....#....##..##............##.
......##....#.#...#....#.#..#.#
.......#.........#.#.....#.#...
.......#.#....#................
.##...###..#.....#............#
#.#......#.#..#..#.#...#..#..#.
..#.#.#.....#............#...##
.##....###.........#..#........
.#..#.#..#.#....#.........##.#.
....#..#...##.##........#......
........#.#....##....#....#....
.......#..#..#.#..............#
#....#....#.....#....#.........
.#.###...#....#.......#........
.........#.#....##....#...#....
....#.............#.....##.##..
.....#.....#...##..#.#.##...##.
.........#..#................##
...##..##......#.....#........#
.#....#.....#.#......#..###....
#.....#..#.....................
....#.#...#.#.................#
.....##..................#.....
#....##...#.##..###...#........
##.#.........#.......#....#....
.#.#.............##..#.##......
...#.#..............#......#...
.............#.........#.....#.
#.......#........#......#.....#
.....#..............#.##.#.....
#......##...................#..
##.#.....#..........#........#.
#...........##...........#.....
.#...#.....#..#..##....#.......
.....#.........#....##.#.......
#........#......#.............#
.#..................####.#.....
#...#......#....##...#.#..#..#.
............#.#............#...
............#........#.#..###..
.#..#..#..#.#.#.....#.#........
#.....#..#.#...#..#..#........#
#................#....#..#.....
....#..#..#.#......#.#..#.....#
.#..#.......#...##.#.#.....#..#
#.....................#.......#
.............#.......#...#.....
....#......#.........###.##....
....#..#.......#.#........#....
....#...#....#.#....#..........
...#..#......#.............#...
.......###.#.........#....#.#..
..#.....##.....................
.#.#...........#..##....#......
..........##.#....#.#..........
...........#.#..#.#..#.#.......
..........#..#...#.....##......
.....#.........#...#.#..#......
#.#................#..........#
...#.....##.#..#...#.##.......#
.....##...........#............
.....#...#...#...#.#.....#.....
...........##..................
.........#................#....
......#.....#.#...#.......#....
...#...#........#...#...#.#.#..
...............##..#....##...#.
...#.#...........##.......##..#
...........#............#......
.#....#.#.......##.#.#.#.......
.....#.#..#.#.#................
.#............#...#.#..........
.....#.......#.#.......#.....#.
#....#...........#...#....##...
..#...#..##.....#....#..#......
#.#.........#..#.#..#.#......#.
................#......##......
#........#..............#....#.
........#..#.#........#..#..#..
#..........#......#............
..##.......#..#.......#....#...
.#........#..#..#.#.......##...
................#..............
#.................#...........#
##..#...................#....##
#..#....#.....#.#..#.#.#......#
#................#.#.#...#.....
.............#..#...#..##...#.#
#..................#...........
..............#..#.....##.....#
..#...............#.#..........
.....#......#....#..#...#......
.#......#...##.....###.....#...
...##...##.##....#.#.#..#......
....#.#.......#..##....#.##....
...#.........#.#.....#...#...##
.##.#.........##..#.##..#......
.#...#......#......#.........#.
.............#.................
..........#..............#.....
##...........#...#...###....#..
....#...............#..........
.......####.....#......#.......
........#..........#..#........
..#.......#..#.................
......#.#..##...##....#........
.##...#........#...#....#...#..
.......................#.......
.........##..#..#...#....##...#
..#..#...#.....#.........#..#..
.......#....#.........#...#..#.
.............#.................
.....##..#.....###....##.#.....
....#.#..#..#.#.....##....#..#.
......#..#..............#.##..#
..#..#......#.#.........#..#...
..........#.#..#....#.....#....
.....................#.........
...#.....#.......##..#.#.......
.....#...#..........###....#.#.
......#.....##............#...#
.......#..........#.#..#...#..#
#...#..#...........#..##..#....
.#......#.......##.....#..#....
...#..#....#.......##......#...
........#.......##...#.......#.
.....#........#................
......#........#....#..........
...#....#....###.........#.#...
##..............#......#..#.#..
.........##....#........#..#.#.
.......#.##.#........#........#
.....###..#..#...........#....#
.......#....##.......#.#...#...
#..............#.#....#..#...#.
#..#....#..#.#............#..#.
.#...##.#..................#...
...#...............##.........#
###..............#.#..#.#.#....
.#......#.#.....##.......#.....
...#.................#.#.......
.#...#....#...#..#......#...#..
...##....#........#.#.#..#.....
..#.....#........#....#.#......
...........#.#...#.............
......#.....#.....#.........#..
.#.##.###...#.##.......#.......
.............#....#.......#....
..............#...........#....
.............#..#.#.....#....#.
.......#........##...##..##....
..##...#............#..#......#
.............#...##.....#......
.#...##..##.#.........#.##...#.

16
test/day3.krk Normal file
View File

@ -0,0 +1,16 @@
from fileio import open
let f = open('test/day3.in')
let lines = f.read().split('\n')[:-1]
def count_trees(lines, x_off, y_off):
let modulo = len(lines[0])
let x = 0, y = 0, trees = 0
while y < len(lines):
if lines[y][x % modulo] == '#':
trees += 1
x += x_off
y += y_off
return trees
print "part 1:", count_trees(lines, 3, 1)
print "part 2:", count_trees(lines, 1, 1) * count_trees(lines, 3, 1) * count_trees(lines, 5, 1) * count_trees(lines, 7, 1) * count_trees(lines, 1, 2)

1096
test/day4.in Normal file

File diff suppressed because it is too large Load Diff

79
test/day4.krk Normal file
View File

@ -0,0 +1,79 @@
from fileio import open
let f = open('test/day4.in')
let lines = f.read().split('\n')[:-1]
def any(iterator):
for v in iterator:
if v: return True
return False
def all(iterator):
for v in iterator:
if not v: return False
return True
def is_digits(val, cnt):
if len(val) != cnt:
return False
return not any([x not in '0123456789' for x in val])
def check_passport(passport):
print "Checking",passport
let expected = ['byr','iyr','eyr','hgt','hcl','ecl','pid']
if not all([e in passport for e in expected]):
print 'Missing expected value'
return 0
#return 1
if not is_digits(passport['byr'], 4) or int(passport['byr']) < 1920 or int(passport['byr']) > 2002:
print 'Bad birth year'
return 0
if not is_digits(passport['iyr'], 4) or int(passport['iyr']) < 2010 or int(passport['iyr']) > 2020:
print 'Bad issue year'
return 0
if not is_digits(passport['eyr'], 4) or int(passport['eyr']) < 2020 or int(passport['eyr']) > 2030:
print 'Bad expire year'
return 0
if passport['hgt'][-2:] == 'cm':
if not is_digits(passport['hgt'][:-2], 3) or int(passport['hgt'][:-2]) < 150 or int(passport['hgt'][:-2]) > 193:
print 'bad height in cm'
return 0
elif passport['hgt'][-2:] == 'in':
if not is_digits(passport['hgt'][:-2], 2) or int(passport['hgt'][:-2]) < 59 or int(passport['hgt'][:-2]) > 76:
print 'bad height in inches:', int(passport['hgt'][:-2])
return 0
else:
print 'bad height generally'
return 0
if len(passport['hcl']) != 7 or passport['hcl'][0] != '#' or any([x not in '0123456789abcdef' for x in passport['hcl'][1:]]):
print 'bad hair color'
return 0
if passport['ecl'] not in ['amb','blu','brn','gry','grn','hzl','oth']:
print 'bad eye color'
return 0
if not is_digits(passport['pid'], 9):
print 'bad pid'
return 0
return 1
let count = 0
let passport = {}
for line in lines:
if not len(line):
count += check_passport(passport)
passport = {}
continue
let elems = line.split(' ')
for elem in elems:
let s = elem.split(':', 1)
passport[s[0]] = s[1]
count += check_passport(passport)
print "count =", count

View File

@ -0,0 +1,18 @@
class AClass():
"""A docstring"""
def foo(self):
print "class member foo"
# What about blank lines?
def bar(self):
print "class member bar"
# Oh my.
let a = AClass()
a.foo()
a.bar()
print AClass.__doc__