From 573e0a77abf946ddc4ca0d6e6dff7d327ed7dbf8 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 11 Dec 2020 11:08:30 -0600 Subject: [PATCH] some updates --- Advent Of Code Day 11-part1.ps1 | 46 ++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/Advent Of Code Day 11-part1.ps1 b/Advent Of Code Day 11-part1.ps1 index 5301cbd..5dbddc0 100644 --- a/Advent Of Code Day 11-part1.ps1 +++ b/Advent Of Code Day 11-part1.ps1 @@ -1,7 +1,8 @@ function Get-OpenSeatCount { param ( [int]$seatrow, - [int]$seatnum + [int]$seatnum, + $seatmap ) $seatrow.gettype() $seatnum.gettype() @@ -11,14 +12,14 @@ function Get-OpenSeatCount { $seatnum.gettype() write-host "Input: $seatrow , $seatnum" $positionstocheck=@{} - $positionstocheck.add('UpperLeft',@($seatrow -1,$seatnum -1)) - $positionstocheck.add('UpperMiddle',@($seatrow -1,$seatnum)) - $positionstocheck.add('UpperRight',@($seatrow -1,$seatnum +1)) - $positionstocheck.add('Left',@($seatrow,$seatnum -1)) - $positionstocheck.add('Right',@($seatrow,$seatnum +1)) - $positionstocheck.add('LowerLeft',@($seatrow +1,$seatnum -1)) - $positionstocheck.add('LowerMiddle',@($seatrow +1,$seatnum)) - $positionstocheck.add('LowerRight',@($seatrow +1,$seatnum +1)) + $positionstocheck.add('UpperLeft',@(($seatrow -1),($seatnum -1))) + $positionstocheck.add('UpperMiddle',@(($seatrow -1),($seatnum))) + $positionstocheck.add('UpperRight',@(($seatrow -1),($seatnum +1))) + $positionstocheck.add('Left',@(($seatrow),($seatnum -1))) + $positionstocheck.add('Right',@(($seatrow),($seatnum +1))) + $positionstocheck.add('LowerLeft',@(($seatrow +1),($seatnum -1))) + $positionstocheck.add('LowerMiddle',@(($seatrow +1),($seatnum))) + $positionstocheck.add('LowerRight',@(($seatrow +1),($seatnum +1))) $occupiedSeats=0 foreach($position in $positionstocheck.keys){ $row,$num = $positionstocheck.$position @@ -28,5 +29,30 @@ function Get-OpenSeatCount { } return $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]='#' + } + } + } + $seatmap +} $seatmap = get-content .\aocd11input.txt -Get-OpenSeatCount -seatrow 33 -seatnum 5 \ No newline at end of file +$nochangesin=0 +do{ + $oldseatmap = $seatmap + $seatmap = proc-Seats -seatmap $seatmap + if($oldseatmap -eq $seatmap){ + $nochangesin++ + } +} while ( + $nochangesin -lt 3 +) +