Skip to content

Instantly share code, notes, and snippets.

@tech-zombie
Last active Dec 4, 2020
Embed
What would you like to do?
Advent of code day3 2020 POSH
#puzzle can be found at https://adventofcode.com/2020/day/3
$i = gc .\input.txt
$position = 1
$results = $null
$horizontalMovement = 3
foreach($line in $i)
{
$check = $position % $line.Length
$position = $position + $horizontalMovement
$hit = if ($check -eq 0)
{
$line.Substring([int]$line.Length-1,1)
}
else { $line.Substring([int]$check-1,1) }
if ($hit -eq '#')
{$results++}
$hit
}
$results
#puzzle can be found at https://adventofcode.com/2020/day/3
$movement = import-csv .\moves.csv -Header 'horizontal','vertical'
$slope = get-content .\input.txt
[int]$result = 1
foreach ($move in $movement)
{
$verticalPath = for ($i=0; $i -lt $slope.count; $i+=$move.vertical){$slope[$i]}
$position = 1
$results = 0
$horizontalMovement = $move.horizontal
foreach ($line in $verticalPath)
{
$check = $position % $line.Length
$position = $position + $horizontalMovement
$hit = if ($check -eq 0)
{
$line.Substring([int]$line.Length-1,1)
}
else { $line.Substring([int]$check-1,1) }
if ($hit -eq '#')
{$results++}
}
$result = $result *$results
$results
}
$result
........#.............#........
...#....#...#....#.............
.#..#...#............#.....#..#
..#......#..##............###..
..........#......#..#..#.......
.#..#.......#.........#.#......
.........#..#....##..#.##....#.
..#....##...#..................
##..........#.##...#....##..#..
...#....#...#..............#...
...........................#..#
..##.##.#..................#...
...#.##..#............#........
........#.......#...#.....##.#.
.##..........#......#.......#..
...#..........#...#..#.......#.
......#...#...#.##.......#.#...
........#...#...#...##.........
#..............#.#....#.......#
..#..#..#.#....#...............
.....#........#...#..........#.
##......#...#..#.##.......#....
..#.#.....#.#.............#.#.#
#..#..##......##...#...........
..#......#........#.....#......
.....#.......#....#.#...#......
...#........#...........#...#..
.......#.#...........###....#..
...#...........##....##........
#....#..####....#.....#..#....#
..........#...........#........
...#.......#....#.#.........#..
....#...#.......#..###.........
......#......#..#......#..#....
...#.....#............#..#.....
...#.#.#.#..#.......#.....#....
#....##...#.........#...##.....
#..#.......#..#..#..#...##.....
#.......#............#.....#...
.#........##....##...#........#
.....#...#.....................
.......#........#..............
.....#............#.#.#...#.#..
.....##..#.............#.......
..#.##..#........#..#...#......
.........#.#....#...........#..
.#.....#..#....#.....#...#.....
....#.#................#.......
...............##......#...#...
.##...#...#.......##.#....#....
............#........#.......#.
......##.#.#...................
.#.#..............#.......#....
#.....#...#.......#..#...#.....
.............#....#..#......#..
........#...##................#
.......#...#..#..##............
..#..#...##...#..#.#.....#...#.
.#.#...#.........#.#...........
...###....#.......#...#........
........#......##.#...#..##..#.
.....................#.#.......
.............#...........#...#.
#..#..#.....#.#...#............
...#....#.....#...........#....
..##.....##...#......#..##.....
#.....#.....###.#.....#....##..
.#...........###...............
..................#..##.#...#..
................#....##.#......
.#.#.#...#....#.........#..#.#.
#.......#........##............
.......##.#....#.#............#
..........#..##.#....#.........
........##..#....#.............
.........#....#...........##...
#.........#.#..#..#..........#.
.....#........#......#.........
....#.#.#...............#......
.#..#..##...#.##..........#....
..#....................#.#.....
.........#....#...........#.#.#
........#....##.##.............
..#.....#.......#..#......#....
#..........#.#.....#.#....#....
........##.#.....#..#.....#.#..
...................#...#....#.#
............#..#....#...#...#..
..............#.#.........#....
...#..#..#.#..##..##...........
.#...........................#.
.#.......#...........#....#.#.#
......#..#...#........#...##...
.........#......#.#.......#...#
...#..##................#......
.............#.#..##....#.#....
...............#..#......#.....
.#......#.#.#....#........#....
........#..#.##..#..#.........#
...#....#.#...#..#.......#..#..
..#...##.........#..#...#......
...#...........#.............#.
....#.....................#....
.....#..#...............#.#...#
....#..........#........#......
..#....#........##..##.........
...#....#..#.#.......#...#.....
..#........#....#...##....#.#..
.#...#........##.....#....###..
#....#....##......#........#...
.........#..#.#..........#....#
....#...#.....#.......##.......
..............#..........#.##..
#...#..#..............#......#.
.................#......##....#
..#..##..#.......#..#.#......#.
.............#........#.....#.#
.#.##............#..#..........
..#...#...........#..##........
.#....#...#....#.......#.......
...#.#..#..#..#....#.....#..#..
....#..##..............#...#...
#..........###......###........
.##.##......#..#............#..
.#...........#.#.....#...#.....
#.#..#...#............#........
.........#...#...#..........##.
.......###..#..........#.......
...........###.....#........#..
.#.............#.....#......#..
...#.....#....#.#.........##...
....##..##...#.......##........
......#....##.........#......#.
..........#.....##..#.....#..#.
..........####...#..#.........#
.##....#..#.#...#.......#......
...#.#.##.#.#...#....#.#.#.....
.........#...##........##.....#
..#........#..........##...##.#
##...##..........#.#...........
..............#......#.........
........#.....#.#.......#......
.#...#.....#....#.#..#.........
.....#....................##...
....#..................#.#...##
.....#............#..##........
#..........#....#.#.......##.#.
....#..#.....................#.
#..#....##.....#...............
..#...#..#..##....#.#..........
.......#......#.#.......#.....#
...#.#.......#...#.##..........
....#..........#....#.#.#......
.......#..#..........#..##.....
#......#......#...#......#...#.
###..#....##......##........#..
.#..........#.....#.......#.#..
.......#.....#.....#.#.........
..#...#....#...................
..............#.##.............
.#...#.......#.##...#.#.......#
.......#......................#
....#.#...#.#........#.........
.#......#....#...#.............
#.......#...###.....#.#.#..#...
#....##.#...............##.....
..#.......#..................#.
.....####...............#......
.##......#......#.#.......##.#.
#......##..###....#....#......#
.##.......##.##...#.##.........
......##............#.......#..
......#..#.....##.#............
.#..........#.....##...........
#.........#......#......##.#...
.........#.......#..#......#.#.
.........#.......#...........#.
.#..##.#..................##...
.............#.............#...
.....##........#......##...##..
..#..#.#.....#..#....#.........
.....#....#.....#.....#........
#......##.....#....#....#......
#.................#..#.#......#
.......#..#......#....#.#...#.#
....#.........#..#..........#.#
##......#............#...#...#.
....##......#...#.....#....##..
.#...##.........#..............
......#.....................#..
..#..........###....#..........
#....#...#..#.............#....
#........#.#......#....#.......
.#...#.......#..#...#.#...#..#.
................##.#.....#.....
###.......#...#................
...#.......#...#.#.....#.......
..#.........#.....#.#.......#..
......#.......................#
#.....#.#..#....#.......#......
...#....#..#....####...........
.............#.....#...##......
.......#.........#...#..#......
.##..#.........#....#.#........
....##...#.#...........#....#..
.........................##....
..###.......##....#.#.........#
.#....#.#.#...........##....#..
......#...#..#..#..#..#.......#
..#....#.#.......#..#..#..#...#
.....##...#.##....#.#...#......
.........#..#....#..#..........
.##..##.........#.#.....#......
..........#...##...#.#...#.....
#.##..#..#.............#.......
...#...........#.......#......#
.......#....#....#...##.......#
..#.##........###..#......#....
...#...........###......#..#..#
.#.........#.#.........#.#.....
##.......##.##.##......##......
............#...#..........#...
....................#..........
...#..#...........#...#...#....
.................#...#......###
...#................#.#.##.....
...............#........#......
#.............##......#.#..#...
..#.#.....#..#.##.....##...#...
......#.........#......#.......
#.......#......#....#........#.
.#..##.....#.........#.........
....##.##.#...#.........##.#...
...............#..#..#..##.....
.#..#...............###........
.##............##..............
...............#...##...#...#.#
..#.#......#.#..#.............#
#.#..#..##.........#.#.#...#...
....##.#....................##.
.........#..#.....#.....#..#..#
....#......#......#.##....#....
........###..#.............#..#
##................#.........#..
#.....#.......#....#...........
..#.......#..#........#....#...
..#.#.##..#.#...##........#.##.
..#..........#............#....
..........#...............##...
..........###........#.#.......
.....###..#.............#......
##.............#...#.....#.....
.....#......#....#........#.#..
............#..#..............#
.................#...........##
#........#.........###.....#...
..#.#..............##......#.#.
.#...........#.........#..##..#
...............................
.#.....#..#....#....#......#...
.#...#......#.#..#....#.......#
......#.##.......#......#......
......#..###..#................
#..#.....#........##...#.......
......##.........##....#...##..
.#..........#.................#
#..#.......#...............#...
.........#..###....#.#.##.#....
..#...#.##..##...............##
.........#.....................
.#....##...#......#....#.......
............#..........#..#....
...#......##....#....#........#
.#...................#.........
#.#........###....#..........#.
.........#....#....#........##.
.#....#..#.........#..#........
...............#..#...#..#...##
.........#....##....#......#...
.#.............................
...#........#...#.#...#.#..#...
.....#..##...#.#...............
#.....#....#.........#.........
#...#...........##.........#...
..##........#.#...#...#......#.
...........#.....#...#.#.......
......###....#.....#...........
......##...#..........#....#.#.
.......##..##..........#.......
....#............#..#....##....
..##...................#.#.....
...#.#..#.#....................
.#..##..#............##.###..#.
#.#...#....#.#..........#.#....
........#....#.....#...........
..##....#...#.......#..........
...........##.##....#..........
.....#............#............
.......#.............#....#....
.................#......#......
......##.......#....#..##...#..
.#..#....#.....................
...#.#.#...#......##...........
##........##.#....#....#.......
.......#.....#..#..#...#.##....
#..........#....#.#..#..#..#...
...##..............#...........
.........#.....#.#....#.......#
.........#....##..#..##..#.....
.....#......................#..
...###...#..#......#...........
....#.....................#....
...............................
..#.....###.......#..#....#....
#..........#.................#.
......#.......###.......#..##..
.............#.##..............
......#..#.#..#...........#....
...#....##.#...#..#.#...#....#.
..................#...#....#.##
......#.#....#.................
......#.#.....#.....#..##......
#..##...........#..#.....#.##..
1 1
3 1
5 1
7 1
1 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment