-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdvent Of Code Day 6-part2.ps1
More file actions
39 lines (37 loc) · 1.06 KB
/
Copy pathAdvent Of Code Day 6-part2.ps1
File metadata and controls
39 lines (37 loc) · 1.06 KB
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
$input=get-content "aocd6input.txt" -Raw
$mydata = $input -split "(\r?\n){2}"
$mysum=0
foreach($form in $mydata){
$group=$form.split("`n")
$mygroup=@{}
if($form -eq "`n"){
continue
}
$emptycount = 0
foreach($person in $group){
if($person.length -eq 0){
$emptycount++
continue
} else {
foreach($char in $person.ToCharArray()){
if(-not($mygroup[$char])){
$mygroup[$char]=1
} else {
$mygroup[$char]= $mygroup[$char]+1
}
}
}
}
$mytotal = $mygroup.keys|ForEach-Object {$mygroup[$_]|where-object {[int]$_ -eq ([int]$group.count - [int]$emptycount)}}
$mysum+=$mytotal.count
write-host @"
Count of group: $($group.count)
Empty Count: $($emptycount)
Tallys: $($mygroup.keys|ForEach-Object {$mygroup[$_]})
MyTotal: $mytotal
MySum: $mysum
MyCount: $($mytotal.count)
Group Answers: $group
"@
}
write-host "FINAL: $mysum"