Files
exercism/powershell/hamming/HammingDifference.ps1
2021-11-26 02:29:57 -06:00

11 lines
273 B
PowerShell

function Get-HammingDifference([string]$A, [string]$B) {
if ($A.Length -ne $B.Length) {
Throw("Left and right strands must be of equal length.")
}
[int] $hamming = 0
0..$A.Length | % { if ($A[$_] -ne $B[$_]) { $hamming++ } }
return $hamming
}