-
Notifications
You must be signed in to change notification settings - Fork 0
/
day4.ps1
54 lines (31 loc) · 1.26 KB
/
day4.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
# Day 4: Camp Cleanup
## Part 1
#$list = get-content .\test.txt
$list = get-content .\input.txt
$matching = 0
foreach ($line in $list) {
$pairs = $line -split ','
[int[]]$set1 = invoke-expression $($pairs[0].Replace("-",".."))
[int[]]$set2 = invoke-expression $($pairs[1].Replace("-",".."))
#"{0}:{1}" -f [string]$($set1 -join ''),[string]$($set2 -join '')
$diff = Compare-Object $set1 $set2 -IncludeEqual -ExcludeDifferent
#"{0}:{1}:{2}" -f $set1.count,$set2.count,$diff.inputobject.count
if ($diff.inputobject.count -in ($set1.Count,$set2.count)) {
"found: {0}:{1}" -f [string]$($set1 -join ''),[string]$($set2 -join '')
$matching +=1
}
}
"Matching pairs: {0}" -f $matching
## part 2
$matching = 0
foreach ($line in $list) {
$pairs = $line -split ','
[int[]]$set1 = invoke-expression $($pairs[0].Replace("-",".."))
[int[]]$set2 = invoke-expression $($pairs[1].Replace("-",".."))
#"{0}:{1}" -f [string]$($set1 -join ','),[string]$($set2 -join ',')
$diff = Compare-Object $set1 $set2 -IncludeEqual -ExcludeDifferent
if ($diff.inputobject.count -ge 1) {
$matching +=1
}
}
"Matching pairs: {0}" -f $matching