From b0e0fbda585bb8a330a73a4a0ce323b15e533012 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 11 Dec 2020 12:02:06 -0600 Subject: [PATCH] some progress --- Advent Of Code Day 11-part1.ps1 | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/Advent Of Code Day 11-part1.ps1 b/Advent Of Code Day 11-part1.ps1 index 5dbddc0..7a9d28a 100644 --- a/Advent Of Code Day 11-part1.ps1 +++ b/Advent Of Code Day 11-part1.ps1 @@ -4,13 +4,6 @@ function Get-OpenSeatCount { [int]$seatnum, $seatmap ) - $seatrow.gettype() - $seatnum.gettype() - $seatrow = [int]$seatrow - $seatnum = [int]$seatnum - $seatrow.gettype() - $seatnum.gettype() - write-host "Input: $seatrow , $seatnum" $positionstocheck=@{} $positionstocheck.add('UpperLeft',@(($seatrow -1),($seatnum -1))) $positionstocheck.add('UpperMiddle',@(($seatrow -1),($seatnum))) @@ -23,28 +16,36 @@ function Get-OpenSeatCount { $occupiedSeats=0 foreach($position in $positionstocheck.keys){ $row,$num = $positionstocheck.$position - if($seatmap[$row][$num] -eq '#'){ + $myrow = $seatmap[$row] + if($myrow[$num] -eq '#'){ $occupiedSeats++ } } - return $occupiedSeats + return [int]$occupiedSeats } function proc-Seats(){ param( $seatmap ) - for($row=0;$row -lt $seatmap.count; $row++){ - for($seatnum=0, $seatnum -lt $seatmap[$row].ToCharArray().count){ - if((Get-OpenSeatCount -seatrow $row -seatnum $seatnum -seatmap $seatmap) -ge 4){ - $seatmap[$row][$seatnum]='L' - } else { - $seatmap[$row][$seatnum]='#' + for($row=0;$row -lt $seatmap.count - 1; $row++){ + for($seatnum=0; $seatnum -lt ($seatmap[$row].ToCharArray().count -1); $seatnum++){ + if($seatmap[$row][$seatnum] -ne '.'){ + $occupiedseats = Get-OpenSeatCount -seatrow $row -seatnum $seatnum -seatmap $seatmap + #write-host "Occupied Around $occupiedseats, SEATNUM $seatnum, SEATROW $row" + $myrow = $seatmap[$row].tochararray() + if( $occupiedseats -ge 4){ + $myrow[$seatnum]='L' + $seatmap[$row]=$myrow -join "" + } else { + $myrow[$seatnum]='#' + $seatmap[$row]=$myrow -join "" + } } } } $seatmap } -$seatmap = get-content .\aocd11input.txt +$seatmap = @(get-content .\aocd11input.txt) $nochangesin=0 do{ $oldseatmap = $seatmap