-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day13Part1.ps1
75 lines (62 loc) · 1.4 KB
/
Day13Part1.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$Maps = ((Get-Clipboard) -join "`n") -split "`n`n"
function Transpose {
param (
$Map
)
$NewMap = @()
for ($Col = 0; $Col -lt $Map[0].Count; $Col++) {
$Column = @()
for ($Row = 0; $Row -lt $Map.Count; $Row++) {
$Column += $Map[$Row][$Col]
}
$NewMap += ,$Column
}
$NewMap
}
function CompareRows {
param (
$Row1,
$Row2
)
$Same = $true
for ($ndx = 0; $ndx -lt $row1.Count; $ndx++) {
if ($Row1[$ndx] -ne $Row2[$ndx]) {
$Same = $false
break
}
}
$Same
}
function FindMirror {
param (
$Map
)
$Found = $false
for ($Row = 0; $Row -lt $Map.Count - 1; $Row++) {
$Prev = $Row
$Next = $Row + 1
while ($Prev -ge 0 -and $Next -lt $Map.Count) {
if (CompareRows $Map[$Prev] $Map[$Next]) {
$Prev--
$Next++
$Found = $true
} else {
$Found = $false
break
}
}
if ($Found) {break}
}
if ($Found) {$Row + 1}
}
$Vertical = 0
$Horizontal = 0
foreach ($MapText in $Maps) {
$Map = @()
foreach ($Row in $MapText -split "`n") {
$Map += ,$Row.ToCharArray()
}
$Vertical += FindMirror (Transpose $Map)
$Horizontal += FindMirror $Map
}
$Vertical + $Horizontal * 100