-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day14Part1.ps1
48 lines (41 loc) · 1022 Bytes
/
Day14Part1.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$Maps = ((Get-Clipboard) -join "`n") -split "`n`n"
function TiltNorth {
param (
$Map
)
do {
$Change = $false
for ($Row = 1; $Row -lt $Map.Count; $Row++) {
for ($Col = 0; $Col -lt $Map[$Row].Count; $Col++) {
if ($Map[$Row][$Col] -eq "O" -and $Map[$Row-1][$Col] -eq ".") {
$Map[$Row][$Col] = "."
$Map[$Row-1][$Col] = "O"
$Change = $true
}
}
}
} while ($Change)
}
function GetLoad {
param (
$Map
)
$Load = 0
for ($Row = 0; $Row -lt $Map.Count; $Row++) {
for ($Col = 0; $Col -lt $Map[$Row].Count; $Col++) {
if ($Map[$Row][$Col] -eq "O") {
$Load += $Map.Count - $Row
}
}
}
$Load
}
foreach ($MapText in $Maps) {
$Map = @()
foreach ($Row in $MapText -split "`n") {
$Map += ,$Row.ToCharArray()
}
TiltNorth $Map
$Load = GetLoad $Map
}
$Load