mirror of
https://github.com/paradizelost/AdventOfCode2020.git
synced 2024-11-24 18:34:45 -06:00
AoC Day 9 Part 1 completed
This commit is contained in:
parent
abb6be7614
commit
5d4f279b0a
37
Advent Of Code Day 9-part1.ps1
Normal file
37
Advent Of Code Day 9-part1.ps1
Normal file
@ -0,0 +1,37 @@
|
||||
$inputdata=import-csv -header "Number" .\aocd9input.txt
|
||||
$inputdata | %{$_.Number = [int64]$_.Number}
|
||||
$buffer=25
|
||||
$mynumbers=$inputdata[0 .. 24] | select-object -ExpandProperty Number
|
||||
for($i=25; $i -lt $inputdata.count; $i++){
|
||||
|
||||
$minval = (($mynumbers|Sort-Object )[0 .. 1] |measure-object -sum | select-object -ExpandProperty sum)[0]
|
||||
$maxval = (($mynumbers|Sort-Object )[-2 .. -1] |measure-object -sum | select-object -ExpandProperty sum)[0]
|
||||
$newnum = $inputdata[$i].Number
|
||||
write-host "Prior $($mynumbers[-1]) : $newnum"
|
||||
if($newnum -lt $minval){
|
||||
write-host "ERROR $newnum too low"
|
||||
break
|
||||
}
|
||||
if($newnum -gt $maxval){
|
||||
write-host "ERROR $newnum too high"
|
||||
break
|
||||
}
|
||||
$possiblevalues = @()
|
||||
for($b=0;$b -lt $mynumbers.Count;$b++){
|
||||
$mynum=$mynumbers[$b]
|
||||
for($a=1;$a -lt $mynumbers.count;$a++ ){
|
||||
$nextnum = $mynumbers[$a]
|
||||
if($mynum -eq $nextnum){
|
||||
#write-host "$mynum is same as $nextnum"
|
||||
continue
|
||||
}
|
||||
$possiblevalues += $mynum + $nextnum
|
||||
}
|
||||
}
|
||||
if($possiblevalues -notcontains $newnum){
|
||||
write-host "ERROR $newnum not a sum of prior $buffer numbers"
|
||||
break
|
||||
}
|
||||
$null,$mynumbers=$mynumbers
|
||||
$mynumbers += $newnum
|
||||
}
|
1000
aocd9input.txt
Normal file
1000
aocd9input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user