some progress

This commit is contained in:
dan 2020-12-11 12:19:10 -06:00
parent b0e0fbda58
commit b82ab61b2d

View File

@ -17,9 +17,13 @@ function Get-OpenSeatCount {
foreach($position in $positionstocheck.keys){ foreach($position in $positionstocheck.keys){
$row,$num = $positionstocheck.$position $row,$num = $positionstocheck.$position
$myrow = $seatmap[$row] $myrow = $seatmap[$row]
try{
if($myrow[$num] -eq '#'){ if($myrow[$num] -eq '#'){
$occupiedSeats++ $occupiedSeats++
} }
} catch{
}
} }
return [int]$occupiedSeats return [int]$occupiedSeats
} }
@ -27,8 +31,8 @@ function proc-Seats(){
param( param(
$seatmap $seatmap
) )
for($row=0;$row -lt $seatmap.count - 1; $row++){ for($row=0;$row -lt $seatmap.count; $row++){
for($seatnum=0; $seatnum -lt ($seatmap[$row].ToCharArray().count -1); $seatnum++){ for($seatnum=0; $seatnum -lt ($seatmap[$row].ToCharArray().count); $seatnum++){
if($seatmap[$row][$seatnum] -ne '.'){ if($seatmap[$row][$seatnum] -ne '.'){
$occupiedseats = Get-OpenSeatCount -seatrow $row -seatnum $seatnum -seatmap $seatmap $occupiedseats = Get-OpenSeatCount -seatrow $row -seatnum $seatnum -seatmap $seatmap
#write-host "Occupied Around $occupiedseats, SEATNUM $seatnum, SEATROW $row" #write-host "Occupied Around $occupiedseats, SEATNUM $seatnum, SEATROW $row"
@ -47,13 +51,17 @@ function proc-Seats(){
} }
$seatmap = @(get-content .\aocd11input.txt) $seatmap = @(get-content .\aocd11input.txt)
$nochangesin=0 $nochangesin=0
$loopnum=0
do{ do{
$oldseatmap = $seatmap $loopnum++
write-host "Loop $loopnum"
$oldseatmap = @($seatmap)
$seatmap = proc-Seats -seatmap $seatmap $seatmap = proc-Seats -seatmap $seatmap
if($oldseatmap -eq $seatmap){ if(($oldseatmap -join "") -eq ($seatmap -join "")){
$nochangesin++ $nochangesin++
} }
#$seatmap
} while ( } while (
$nochangesin -lt 3 $nochangesin -lt 3
) )
(($seatmap -join "").tochararray()|?{$_ -eq '#'}).count