Created
April 8, 2020 08:22
-
-
Save WimObiwan/217ca92d436a6125b394e29aab52985c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Match([string]$x, [string]$y) { | |
if ($x.Length -ne $y.Length) { return '' } | |
$result = '' | |
@(0..($x.Length - 1)) | %{ | |
if ($x[$_] -eq $y[$_]) { | |
$result += '*' | |
} elseif ($y.Contains($x[$_])) { | |
$result += '?' | |
} else { | |
$result += '.' | |
} | |
} | |
$result | |
} | |
function Right([string]$x, [string]$y) { | |
$m = Match $x $y | |
($m.ToCharArray() -eq '*').Count | |
} | |
function Wrong([string]$x, [string]$y) { | |
$m = Match $x $y | |
($m.ToCharArray() -eq '?').Count | |
} | |
@(0..999) | ?{ | |
(Wrong '147' $_) -eq 1 ` | |
-and (Right '189' $_) -eq 1 ` | |
-and (Wrong '964' $_) -eq 1 ` | |
-and (Right '523' $_) -eq 0 -and (Wrong '523' $_) -eq 1 ` | |
-and (Wrong '286' $_) -eq 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment