mirror of
https://github.com/paradizelost/AdventOfCode2020.git
synced 2024-11-25 02:44:45 -06:00
Functional day 9 part 2, just have to manually set the number looking for. next up is merging the 2 parts into 1.
This commit is contained in:
parent
5d4f279b0a
commit
7460b6c29f
21
Advent Of Code Day 9-part2.ps1
Normal file
21
Advent Of Code Day 9-part2.ps1
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
$inputdata=import-csv -header "Number" .\aocd9input.txt
|
||||||
|
$inputdata | %{$_.Number = [int64]$_.Number}
|
||||||
|
$howmanynums=2
|
||||||
|
|
||||||
|
foreach($num in ($howmanynums .. $inputdata.count)){
|
||||||
|
|
||||||
|
|
||||||
|
for($i=0;$i -lt $inputdata.count - $num; $i++){
|
||||||
|
$possiblevalues = @()
|
||||||
|
$mynums = $inputdata[$i .. ($i + $num -1)]|Select-Object -ExpandProperty Number
|
||||||
|
$mysum = $mynums | Measure-Object -sum | Select-Object -ExpandProperty Sum
|
||||||
|
if($mysum -eq 15353384){
|
||||||
|
$minnum = ($mynums | Measure-Object -minimum).minimum
|
||||||
|
$maxnum = ($mynums | Measure-Object -Maximum).Maximum
|
||||||
|
write-host "$mynums sum to $mysum"
|
||||||
|
write-host "Smallest $minnum + Largest $maxnum = $($minnum + $maxnum)"
|
||||||
|
break
|
||||||
|
}
|
||||||
|
#write-host "$mynums : $mysum"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user