main
Henri 2021-12-02 12:42:21 +02:00
parent b4f2003833
commit f144906716
3 changed files with 1049 additions and 0 deletions

43
day02/day02.ps1 Normal file
View File

@ -0,0 +1,43 @@
param(
[parameter(mandatory=$true)]
$path
)
$commands = gc $path | % {
if ($_ -match '(?<command>forward|up|down) (?<amt>\d+)') {
[pscustomobject] @{
command = $Matches["command"];
amt = [int]$Matches["amt"];
}
}
}
echo "question 1"
$position = 0
$depth = 0
foreach ($c in $commands) {
switch ($c.command) {
"forward" { $position += $c.amt }
"up" { $depth -= $c.amt }
"down" { $depth += $c.amt }
}
}
echo "position: $position, depth: $depth, answer: $($position * $depth)"
echo "question 2"
$position = 0
$depth = 0
$aim = 0
foreach ($c in $commands) {
switch ($c.command) {
"forward" { $position += $c.amt; $depth += $aim * $c.amt }
"up" { $aim -= $c.amt }
"down" { $aim += $c.amt }
}
}
echo "position: $position, depth: $depth, answer: $($position * $depth)"

1000
day02/input.txt Normal file

File diff suppressed because it is too large Load Diff

6
day02/test.txt Normal file
View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2