How to resolve the algorithm Pangram checker step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pangram checker step by step in the AWK programming language
Table of Contents
Problem Statement
A pangram is a sentence that contains all the letters of the English alphabet at least once. For example: The quick brown fox jumps over the lazy dog.
Write a function or method to check a sentence to see if it is a pangram (or not) and show its use.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Pangram checker step by step in the AWK programming language
Source code in the awk programming language
#!/usr/bin/awk -f
BEGIN {
allChars="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
print isPangram("The quick brown fox jumps over the lazy dog.");
print isPangram("The quick brown fo.");
}
function isPangram(string) {
delete X;
for (k=1; k<length(string); k++) {
X[toupper(substr(string,k,1))]++; # histogram
}
for (k=1; k<=length(allChars); k++) {
if (!X[substr(allChars,k,1)]) return 0;
}
return 1;
}
# usage: awk -f pangram.awk -v p="The five boxing wizards dump quickly." input.txt
#
# Pangram-checker, using associative arrays and split
BEGIN {
alfa="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ac=split(alfa,A,"")
print "# Checking for all",ac,"chars in '" alfa "' :"
print testPangram("The quick brown fox jumps over the lazy dog.");
print testPangram(p);
}
{ print testPangram($0) }
function testPangram(str, c,i,S,H,hit,miss) {
print str ##
split( toupper(str), S, "")
for (c in S) {
H[ S[c] ]++
#print c, S[c], H[ S[c] ] ##
}
for (i=1; i<=ac; i++) {
c = A[i]
#printf("%2d %c : %4d\n", i, c, H[c] ) ##
if (H[c]) { hit=hit c } else { miss=miss c }
}
print "# hit:",hit, "# miss:",miss, "." ##
if (miss) return 0
return 1
}
You may also check:How to resolve the algorithm Greatest common divisor step by step in the Action! programming language
You may also check:How to resolve the algorithm Ultra useful primes step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the Scala programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Hough transform step by step in the Racket programming language