Skulle inte ens göra något i år eftersom jag har lite för mycket annat. Har hittills aldrig tagit mig mer än 6 dagar så kom fram till att jag kanske kan göra de första två i varje fall nu när de såg relativt chill ut och jag dessutom råkade ha VS code öppet för att peta på ett script så...
Dag: 2
Språk: Powershell
Del 1
[CmdletBinding()]
param ()
$import = Get-Content input2.csv
$depth = 0
$horizontal = 0
foreach ($line in $import) {
Write-Verbose "Got instruction $line"
$parts = $line -split " "
$direction = $parts[0]
$len = $parts[1]
if ($direction -eq "forward") {
$horizontal += $len
Write-Verbose "Adding $len to horizontal, it is now $horizontal"
}
elseif ($direction -eq "down") {
$depth += $len
Write-Verbose "Adding $len to depth, it is now $depth"
}
elseif ($direction -eq "up") {
$depth -= $len
Write-Verbose "Subtracting $len from depth, it is now $depth"
}
}
return $horizontal * $depth
Del 2
[CmdletBinding()] #för att få -verbose att fungera
param ()
$import = Get-Content input2.csv
$aim = 0
$depth = 0
$horizontal = 0
foreach ($line in $import) {
Write-Verbose "Got instruction $line"
$parts = $line -split " "
$direction = $parts[0]
$len = $parts[1]
if ($direction -eq "forward") {
$horizontal += $len
Write-Verbose "Added $len to horizontal, it is now $horizontal"
$depthchange = [int]$len * [int]$aim
$depth += $depthchange
Write-Verbose "Added $depthchange to depth, it is now $depth"
}
elseif ($direction -eq "down") {
$aim += $len
Write-Verbose "Added $len to aim, it is now $aim"
}
elseif ($direction -eq "up") {
$aim -= $len
Write-Verbose "Subtracted $len from aim, it is now $aim"
}
}
return $horizontal * $depth