Task 1
This commit is contained in:
parent
96c9388d84
commit
d5e07fbd8d
|
@ -0,0 +1,323 @@
|
|||
............#....#.............
|
||||
...........##....#......#..#..#
|
||||
......#.......#......#.........
|
||||
..#.#....#....#.............##.
|
||||
..#........####....#...#.......
|
||||
..##.....#.#.#..#.........#....
|
||||
...#.#..#..#....#..#..#........
|
||||
#.......#.........#....##.###..
|
||||
......##..#.#...#.......#.#....
|
||||
................##.........#.##
|
||||
..##..........#...#.........#.#
|
||||
..........#...##...............
|
||||
#...#......#..#.#..#...##..#...
|
||||
..##....#.......#......#..#....
|
||||
....#......#......#....#.......
|
||||
.........#.....#..#............
|
||||
.#...#.#.........#........#....
|
||||
#..........####.....#..........
|
||||
......##.....#....#..#........#
|
||||
#......#......#...........#....
|
||||
....#.........#....#...#..#..#.
|
||||
.#........#......#.#.....#.....
|
||||
..#.#.#..........#....#.......#
|
||||
......#.#........##....##....##
|
||||
.....#.#..#...#................
|
||||
......#......##...............#
|
||||
..#..##.............#...##.....
|
||||
......##......##..#......#.....
|
||||
....#.............#..##.....##.
|
||||
........#...............##.....
|
||||
..#......#.##..#...#....#...#..
|
||||
#......#.......#.............#.
|
||||
.....#....##..............#....
|
||||
#.#.........#....#..##....#....
|
||||
.#...#...#....#.#............#.
|
||||
...#...#.#..##.##.......##.....
|
||||
......#..#....##..#.#..#..#....
|
||||
.......##..#..#......#..#.....#
|
||||
.##..#......#..........#....#..
|
||||
.....#................#..#....#
|
||||
........#..#....#.......#....#.
|
||||
..#......#.......#......#....#.
|
||||
....#...#.##........##....#....
|
||||
.....#........#...........#....
|
||||
...#....##..........#..#...#.#.
|
||||
...#.......#......#...##...#...
|
||||
.#.....#........#........#.#..#
|
||||
.#.........#..##.....#.......#.
|
||||
....#..#....#.......#......#...
|
||||
.#.#...##..##................##
|
||||
......#.#...#.......#....#....#
|
||||
........#....#..#.....#......#.
|
||||
.......#..........#......#.....
|
||||
...............................
|
||||
..#..#####..#..#..........#.#..
|
||||
.....#....##................#.#
|
||||
.................##............
|
||||
.#...#...#..#...........#...##.
|
||||
..#..#.#...........#.....##....
|
||||
.#.......#.....#..##..#.#....#.
|
||||
..........#.#......##...##.....
|
||||
........##..#......##...#......
|
||||
#......................#.......
|
||||
............#.....#....#.#...#.
|
||||
#......#..........##..#........
|
||||
.........#.......#...#.#.......
|
||||
...........##....#........#....
|
||||
#........#.....#...#........##.
|
||||
.#......##......#.##.......#..#
|
||||
.....#......#.#......#.......#.
|
||||
.....#.#.........#.............
|
||||
...........#..#....#.....#.#...
|
||||
...#............#...#..........
|
||||
..#..#...#.....................
|
||||
......#..#...#....#............
|
||||
.#.#.#........#..#...#.........
|
||||
..........#........#..#........
|
||||
..............#...#....#.......
|
||||
..#....#....##.......#...#.##..
|
||||
.#.........#...#......#........
|
||||
..#......#...#.........##.#...#
|
||||
...#.....#...#..#.............#
|
||||
.##........#.#.#.............#.
|
||||
..#.............#..#.#...#....#
|
||||
#...#.........#......#......#..
|
||||
.......##..#.#..........#...#..
|
||||
.......#.............#..#.#....
|
||||
.#..#....#.#...................
|
||||
....##...#..#....#..#..........
|
||||
....#.#............#...........
|
||||
###........##..#.#..#..........
|
||||
.#.#.#.......#...........#..#.#
|
||||
..........##..#.............#..
|
||||
.#...........#......#.#..#..##.
|
||||
...###......#.##........#.....#
|
||||
....#..#..#...#................
|
||||
...#.....#........#............
|
||||
....#...#...#..#..##.##.......#
|
||||
#.......#......#....#.......#..
|
||||
#.............#...#............
|
||||
##......#..#...#....##.#...#...
|
||||
.##....................#....#..
|
||||
..#.....#....#.#....#......#...
|
||||
.......#..#..#............#...#
|
||||
.#.....#.......#..#..#..#......
|
||||
......##.......................
|
||||
#..#...#.#.#....#.....#..#.....
|
||||
...................#...#...#...
|
||||
........#....##..#....#........
|
||||
##......#.#......##.###........
|
||||
.........#...##................
|
||||
.......#...#...#.......##......
|
||||
....#.......#......#.........##
|
||||
....#....#.#..#.....#..........
|
||||
...........#.......#........#..
|
||||
..#.........###.#........#.....
|
||||
.......#...........#.#.....##..
|
||||
..#...#..#..........#..........
|
||||
..........#.#....#.............
|
||||
.##....#........##.............
|
||||
.............#.#####........#.#
|
||||
.................##...#........
|
||||
##...#.#.......##........#.....
|
||||
.#...#...#..#..#....#....#.....
|
||||
..#...#........#..#............
|
||||
##...#.#........#......##.#..##
|
||||
.##......#..............##.#..#
|
||||
.........#...#............#...#
|
||||
....#..#....#...........#......
|
||||
........#..#....#...##...#.....
|
||||
..#..............#...#.#.....#.
|
||||
.#.......#.#.....#..###.......#
|
||||
...................#.......#...
|
||||
........##.....#..#.......##...
|
||||
.....#....................#...#
|
||||
...#.#....#............#.#.....
|
||||
#.......#.......#....#.........
|
||||
..#...............#............
|
||||
##...#...#...#..............#..
|
||||
...#..........#..#....##.......
|
||||
#............##.##......#.#.#..
|
||||
.#...........#.........#....##.
|
||||
..##....##.#....#.#.#.##...##.#
|
||||
........#.#.#.............#....
|
||||
.#...........#....##...#...#.#.
|
||||
.##...#.................#......
|
||||
....#.#..#....................#
|
||||
.##......#........#..#.........
|
||||
...#...............#...........
|
||||
.#.#..##..##.#........#........
|
||||
...........#....#.#.#......#...
|
||||
...................#........#.#
|
||||
..#............#...#.#........#
|
||||
....#....#.#.##......#...#.....
|
||||
..................#............
|
||||
..........................#....
|
||||
........#......................
|
||||
......#.#...#.#..##......#.#.#.
|
||||
.........#...#..#..............
|
||||
..#.......#..........##..#.....
|
||||
.........#............#........
|
||||
......#..#..#...###....#....#..
|
||||
#..#..............##.###..##..#
|
||||
.#..................#.....#...#
|
||||
........#........#........#....
|
||||
.........#........#.##......#..
|
||||
..#.....#.#..###...#....#......
|
||||
..#................##....#.....
|
||||
..#.#....##.....#......##...#..
|
||||
...#.......#........##.........
|
||||
#........#...#.#..........##..#
|
||||
................#...#.#.....#..
|
||||
.........#..#..#.#..#.#...#....
|
||||
##....#...##.........#.#...#.##
|
||||
....#..#.....##.....#.....##...
|
||||
................#............#.
|
||||
..#..#...#.....#......#.....##.
|
||||
....#.......#...#...#...#..#...
|
||||
....#..##....#.###.#...#..#....
|
||||
#..##.....#.....#.##..##...##.#
|
||||
.............###..........#....
|
||||
..................#.....###....
|
||||
..........#....#...#......#....
|
||||
...#..##.......#......#.#...#..
|
||||
..#.......................##.#.
|
||||
..#..#..#....#......#...#...##.
|
||||
#.............#................
|
||||
..........#.#.#.........#.#....
|
||||
.....##..#......##.#...........
|
||||
.#.#.#.#....#.#...#.....#.#...#
|
||||
......#.....##..............##.
|
||||
#..#.......##..##..............
|
||||
#..#..#................###.....
|
||||
.....#......#.........#........
|
||||
#...........#........#.#.......
|
||||
#........#.#...#....#....###..#
|
||||
###..#.#...........#.##.....#.#
|
||||
..#..........#..#............#.
|
||||
...#....#.......#..#.....###...
|
||||
.#....#.##.#..###..............
|
||||
.....#.##.##.......###.##...#.#
|
||||
..#..##.......###..............
|
||||
.#.........###..#..............
|
||||
..................###.....#..#.
|
||||
#....#....#.........#.....#....
|
||||
.........#.#..#....#.....#.....
|
||||
....##.......##.......#.#......
|
||||
.....#...#.##.....#............
|
||||
....#.#.#.......#..............
|
||||
.##..#.#..#.......##...........
|
||||
....#....##..#.....##.......#.#
|
||||
.....##....#..#.#........#.....
|
||||
........#.#.#....#....##...#..#
|
||||
..#......#.#.#..#.##....#.#.#..
|
||||
..#...#........#..#..........#.
|
||||
.........#...................#.
|
||||
........#.....##..#....#....#..
|
||||
#..............#..........#....
|
||||
#........#.#...........#.#.....
|
||||
..#......................#.#..#
|
||||
.........#.#.....#.#..........#
|
||||
......#....#.#.##........#.....
|
||||
.#....##......##..#...#.......#
|
||||
..#........#...#.##....#..#.#..
|
||||
.......#.....#..........#.....#
|
||||
.........#.#..#.........#....#.
|
||||
..........#.##.........##..#...
|
||||
......#.#..#.....#.#..........#
|
||||
......#.#.#..#..#.#............
|
||||
...##.#..#..............#....#.
|
||||
#..........#...................
|
||||
.#....#..#.#.......#........#..
|
||||
...#...#......#....#......#....
|
||||
..#.#.......#.......#.......#.#
|
||||
...#.#...#........#.....#......
|
||||
#.......#..#...................
|
||||
#..#..#.............#..#..#..#.
|
||||
#.......................#....##
|
||||
.#.........#....#....#.........
|
||||
...............#...#..#....#..#
|
||||
#.....#.#...#.#.....#..........
|
||||
....##.#..#...#.#....###...#.#.
|
||||
.................#....#........
|
||||
####.......##...##.......#.##..
|
||||
#..#....#....##............#...
|
||||
..##......#..#........#........
|
||||
....#..#..........#......#...##
|
||||
..#.#.............#...........#
|
||||
#...............#...#.......#.#
|
||||
#..#.........#.##.#.......#...#
|
||||
......#.....#.............#...#
|
||||
......#.##.........##...#......
|
||||
..#......##.#........#.......#.
|
||||
#..#.........#.##..............
|
||||
..#....#...#...#..#.....#.#....
|
||||
................#.......#......
|
||||
#.....#..............##....#.##
|
||||
##.....#...#.#.....#..##...#...
|
||||
#.#............##..........#..#
|
||||
..#.##......#..#....#..........
|
||||
....##.#....#.......##.....#...
|
||||
......#.#....###...#...........
|
||||
..................#......#....#
|
||||
..............##...............
|
||||
......#..#....#.....#..........
|
||||
.......#........#...#..........
|
||||
..#......#......##..#.##..#....
|
||||
..#.#...#...............#......
|
||||
....#.#.............#.#......#.
|
||||
....#.#.....#......#..#.......#
|
||||
........................#..#...
|
||||
.................#...........#.
|
||||
#......#......#.#.#.....##.....
|
||||
..#....##...#.....##.#.....#..#
|
||||
....#.........#....#.##.#.#....
|
||||
..#....###.....................
|
||||
.....#.#....#......#....##....#
|
||||
#.......#...#......##.......#..
|
||||
#....#.........##.....#........
|
||||
#.....#...........#..#.....#...
|
||||
.................#.....#..##..#
|
||||
..#...#......####...##.........
|
||||
...............................
|
||||
#........#.....#...............
|
||||
.#.........#....#.#......##....
|
||||
...#..........#.........#.#.#.#
|
||||
......##......#....###........#
|
||||
.....................#.#.#.....
|
||||
......#..#..#.......#...#......
|
||||
...##.#.............#.#.......#
|
||||
..#.#...#..#....#.....#.....#..
|
||||
..#..#.....................#..#
|
||||
........#....#..........#..#...
|
||||
#.##....#..#.#..#............#.
|
||||
..............###.............#
|
||||
.#.#..........#.#....#...#....#
|
||||
....#..........#.#..#......#...
|
||||
.........##.#...#..............
|
||||
..................#.....#.#....
|
||||
.#....#.......#.##.#.........#.
|
||||
.##..#...#......#..#...........
|
||||
.#.........#..........#.#......
|
||||
#.#......#.#.#.#.......#...#.#.
|
||||
.......#....#.#......#......#..
|
||||
...#..#....#.#..#..##...##.....
|
||||
#.#.#.......#....#.........##..
|
||||
#..#....#........###....#.#....
|
||||
....#..#.........#....#...#....
|
||||
...#.#.#.#..#..##.....#.##.....
|
||||
.......#.......#...............
|
||||
#.#.#......##....#.............
|
||||
...#.##........#.....#...##.#..
|
||||
...#.#.###..........#.......#..
|
||||
.....#...#.......#.........#...
|
||||
............#..#...#..##.......
|
||||
...#....#..##.##..........#.##.
|
||||
..................#........#...
|
||||
....#.##.#.##........#.#.......
|
||||
.#...........##.....##.......#.
|
||||
#...#.........#.....##.........
|
||||
#..#....#.#.........#..........
|
||||
..#......#.#.#......#.....#..#.
|
||||
..##......#..............#.....
|
|
@ -7,20 +7,46 @@ let input = readFileSync('./input/2020-day-03.txt', 'utf-8')
|
|||
.split('\n')
|
||||
.map(l => parseInt(l.trim(), 10));
|
||||
|
||||
let example: number[] = []
|
||||
let example: string =
|
||||
`..##.......
|
||||
#...#...#..
|
||||
.#....#..#.
|
||||
..#.#...#.#
|
||||
.#...##..#.
|
||||
..#.##.....
|
||||
.#.#.#....#
|
||||
.#........#
|
||||
#.##...#...
|
||||
#...##....#
|
||||
.#..#...#.#`;
|
||||
let tasksResults: any[] = ['N/A', 'N/A'];
|
||||
|
||||
describe('Day 02', () => {
|
||||
let sample = example.split('\n');
|
||||
let m = (sample.length * 3) / sample[0].length;
|
||||
let input: string[];
|
||||
let panels: number;
|
||||
before(() => {
|
||||
input = readFileSync('./input/2020-day-03.txt', 'utf-8')
|
||||
.split('\n');
|
||||
panels = (input.length * 3) / input[0].length;
|
||||
})
|
||||
describe('task01', () => {
|
||||
it('find a safe location', () => {
|
||||
assert.strictEqual(m, 3);
|
||||
assert.strictEqual(isTreeLocation(m, 0, sample[0]), false);
|
||||
assert.strictEqual(isTreeLocation(m, 3, sample[1]), false);
|
||||
assert.strictEqual(isTreeLocation(m, 6, sample[2]), true);
|
||||
})
|
||||
it('Calculate', () => {
|
||||
assert.strictEqual(task01(example), 0);
|
||||
tasksResults[0] = task01(input)
|
||||
assert.strictEqual(task01(m, sample), 7);
|
||||
tasksResults[0] = task01(panels, input)
|
||||
});
|
||||
});
|
||||
describe('test02', () => {
|
||||
it('Calculate', () => {
|
||||
assert.strictEqual(task02(input), 0);
|
||||
tasksResults[1] = task02(input);
|
||||
// assert.strictEqual(task02(input), 0);
|
||||
// tasksResults[1] = task02(input);
|
||||
});
|
||||
});
|
||||
after(() => {
|
||||
|
@ -29,10 +55,26 @@ describe('Day 02', () => {
|
|||
});
|
||||
});
|
||||
|
||||
function task01(input: number[]): number {
|
||||
return 0
|
||||
function task01(m: number, input: string[]): number {
|
||||
let dist = 3;
|
||||
let trees = 0;
|
||||
input.forEach((row: string, i: number) => {
|
||||
trees += isTreeLocation(m, dist*i, row) ? 1 : 0;
|
||||
});
|
||||
return trees;
|
||||
}
|
||||
|
||||
function task02(input: number[]): number {
|
||||
return task01(input);
|
||||
// function task02(input: number[]): number {
|
||||
// return task01(input);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
function isTreeLocation(m: number, col: number, pattern: string): boolean {
|
||||
let c = pattern;
|
||||
|
||||
for (let i = 0; i < m; i++) {
|
||||
c += pattern;
|
||||
}
|
||||
return c.charAt(col) === '#';
|
||||
}
|
Loading…
Reference in New Issue