-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay_3_P2.ps1
67 lines (40 loc) · 1.38 KB
/
Day_3_P2.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
$claims = gc ".\Day_3_Input.txt"
$ClaimsArr = @()
$claims | % {
$Rowinf = $_ -replace "#" -replace " @ ","," -replace ": ","," -replace "x","," -split ","
$RowObjProp = [Ordered]@{
"id" = $Rowinf[0]
"x" = [int]$Rowinf[1]
"y" = [int]$Rowinf[2]
"w" = [int]$Rowinf[3]
"h" = [int]$Rowinf[4]
}
$ClaimsArr += New-Object -TypeName PSobject -Property $RowObjProp
}
$Grid = @{}
foreach($z in $ClaimsArr){
Write-Host "processing $($z.id)"
for($x=$z.x + 1;$x -le ($z.x + $z.w);$x++){
for($y=$z.y + 1;$y -le ($z.y + $z.h);$y++){
[array]$grid["x$($x)y$($y)"] += $z.id
}
}
}
$overlappedGrids = ($Grid.GetEnumerator() | ? {($_.Value | Measure-Object | select -expand Count) -gt 1})
$uniquGrids = ($Grid.GetEnumerator() | ? {($_.Value | Measure-Object | select -expand Count) -eq 1})
$ClaimsSizeHash = @()
$ClaimsArr | % {
$ClaimsSize = ($_.w * $_.h)
$ClaimsSizeHash += New-Object -TypeName PSobject -Property @{
"ID" = $_.id
"Size" = $ClaimsSize
}
}
$intact = @()
foreach($claimsizeInHash in $ClaimsSizeHash) {
$GridCount = $uniquGrids | ? {$_.value -eq $($claimsizeInHash.id)} | Measure-Object | select -expand Count
if ($claimsizeInHash.Size -eq $GridCount){
$intact += $claimsizeInHash.ID
}
}
$intact