Skip to content

Instantly share code, notes, and snippets.

@IISResetMe IISResetMe/1.ps1 Secret
Last active Dec 26, 2018

Embed
What would you like to do?
Advent of PowerShell 2018, Day 2
param(
[string[]]$IDs
)
# Prepare our char count function
$TestCharExactCount = {
return @($_.ToCharArray() |Group-Object -NoElement).Where({$_.Count -eq $n}).Count -gt 0
}
# Create two new closures over $n = 2 and $n = 3
$n = 2
$TestExactly2 = $TestCharExactCount.GetNewClosure()
$n = 3
$TestExactly3 = $TestCharExactCount.GetNewClosure()
# Count occurences
$2s = $IDs.Where($TestExactly2).Count
$3s = $IDs.Where($TestExactly3).Count
# Multiplly counts for final result
return $2s * $3s
param(
[string[]]$IDs
)
:IDSearch
for($i = 0; $i -lt $IDs.Count - 1; $i++){
for($j = $i + 1; $j -lt $IDs.Count; $j++){
$HammingDistance = Get-HammingDistance -a $IDs[$i] -b $IDs[$j]
if($HammingDistance -eq 1){
$ID1,$ID2 = $IDs[$i,$j]
break IDSearch
}
}
}
$sharedChars = for($charIdx = 0; $charIdx -lt $ID1.Length;$charIdx++){
if($ID1[$charIdx] -eq $ID2[$charIdx]){
$ID1[$charIdx]
}
}
return -join $SharedChars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.