Skip to content

Instantly share code, notes, and snippets.

@IISResetMe

IISResetMe/1.ps1 Secret

Last active December 26, 2018 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/94140cf83a5a4fe77aa9ab86ad8cfaf5 to your computer and use it in GitHub Desktop.
Save IISResetMe/94140cf83a5a4fe77aa9ab86ad8cfaf5 to your computer and use it in GitHub Desktop.
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