Jump to content

Pangram checker: Difference between revisions

→‎{{header|PowerShell}}: Add a HashSet version
(→‎{{header|Ada}}: Other solution : Using quantified expressions)
(→‎{{header|PowerShell}}: Add a HashSet version)
Line 2,073:
=={{header|PowerShell}}==
Cyrillic test sample borrowed from Perl 6.
{{works with|PowerShell|42}}
<lang PowerShell>
function Test-Pangram ( [string]$Text, [string]$Alphabet = 'abcdefghijklmnopqrstuvwxyz' )
Line 2,080:
$Alphabet = $Alphabet.ToLower()
$IsPangram = @( $Alphabet.ToCharArray(). | Where-Object { $Text.Contains( $_ ) } ).Count -eq $Alphabet.Length
return $IsPangram
Line 2,095:
True
</pre>
A faster version can be created using .Net HashSet to do what the F# version does:
{{works with|PowerShell|2}}
<lang PowerShell>
functionFunction Test-Pangram ( [string]$Text, [string]$Alphabet = 'abcdefghijklmnopqrstuvwxyz' )
{
{
$TextalSet = [Collections.Generic.HashSet[char]]::new($TextAlphabet.ToLower())
$AlphabettextSet = [Collections.Generic.HashSet[char]]::new($AlphabetText.ToLower())
 
$alSet.ExceptWith($textSet) # remove text chars from the alphabet
$IsPangram = ( $Alphabet.ToCharArray() | Where { $Text.Contains( $_ ) } ).Count -eq $Alphabet.Length
 
return $alSet.Count -eq 0 # any alphabet letters still remaining?
return $IsPangram
}
}
Test-Pangram 'The quick brown fox jumped over the lazy dog.'
Test-Pangram 'The quick brown fox jumps over the lazy dog.'
Test-Pangram 'Съешь же ещё этих мягких французских булок, да выпей чаю' 'абвгдежзийклмнопрстуфхцчшщъыьэюяё'
</lang>
{{out}}
<pre>
False
True
True
</pre>
 
=={{header|Prolog}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.