From b82ab61b2dfe42c6869f234d5483fbeb1ac24811 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 11 Dec 2020 12:19:10 -0600 Subject: [PATCH] some progress --- Advent Of Code Day 11-part1.ps1 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Advent Of Code Day 11-part1.ps1 b/Advent Of Code Day 11-part1.ps1 index 7a9d28a..4ea15bc 100644 --- a/Advent Of Code Day 11-part1.ps1 +++ b/Advent Of Code Day 11-part1.ps1 @@ -17,8 +17,12 @@ function Get-OpenSeatCount { foreach($position in $positionstocheck.keys){ $row,$num = $positionstocheck.$position $myrow = $seatmap[$row] - if($myrow[$num] -eq '#'){ - $occupiedSeats++ + try{ + if($myrow[$num] -eq '#'){ + $occupiedSeats++ + } + } catch{ + } } return [int]$occupiedSeats @@ -27,8 +31,8 @@ function proc-Seats(){ param( $seatmap ) - for($row=0;$row -lt $seatmap.count - 1; $row++){ - for($seatnum=0; $seatnum -lt ($seatmap[$row].ToCharArray().count -1); $seatnum++){ + for($row=0;$row -lt $seatmap.count; $row++){ + for($seatnum=0; $seatnum -lt ($seatmap[$row].ToCharArray().count); $seatnum++){ if($seatmap[$row][$seatnum] -ne '.'){ $occupiedseats = Get-OpenSeatCount -seatrow $row -seatnum $seatnum -seatmap $seatmap #write-host "Occupied Around $occupiedseats, SEATNUM $seatnum, SEATROW $row" @@ -47,13 +51,17 @@ function proc-Seats(){ } $seatmap = @(get-content .\aocd11input.txt) $nochangesin=0 +$loopnum=0 do{ - $oldseatmap = $seatmap + $loopnum++ + write-host "Loop $loopnum" + $oldseatmap = @($seatmap) $seatmap = proc-Seats -seatmap $seatmap - if($oldseatmap -eq $seatmap){ + if(($oldseatmap -join "") -eq ($seatmap -join "")){ $nochangesin++ } + #$seatmap } while ( $nochangesin -lt 3 ) - +(($seatmap -join "").tochararray()|?{$_ -eq '#'}).count