How to resolve the algorithm Pangram checker step by step in the Julia programming language
How to resolve the algorithm Pangram checker step by step in the Julia 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 Julia programming language
The code uses the Julia programming language, and it implements a function that checks if a given string is a pangram in a given alphabet. A pangram is a sentence that contains every letter of the alphabet at least once.
The function makepangramchecker
takes as input an alphabet, which is a string containing all the letters of the alphabet. It first converts the alphabet to uppercase and then creates a set of the letters.
The function then defines a nested function called ispangram
that takes a string as input. The function first checks if the length of the string is greater than or equal to the length of the alphabet. If it is not, then the string cannot be a pangram.
If the length of the string is greater than or equal to the length of the alphabet, then the function checks if all of the letters in the alphabet are present in the string. It does this by iterating over the letters in the alphabet and checking if each letter is present in the string. If all of the letters are present, then the string is a pangram.
The makepangramchecker
function then returns the ispangram
function.
The code then creates a list of test sentences and uses the is_english_pangram
function to check if each sentence is a pangram. The function is called with the string 'a':'z'
as the argument, which means that it will check if the sentence is a pangram in the English alphabet.
The output of the code is:
The sentence "Pack my box with five dozen liquor jugs." is a pangram.
The sentence "The quick brown fox jumps over a lazy dog." is a pangram.
The sentence "The quick brown fox jumps\u2323over the lazy dog." is not a pangram.
The sentence "The five boxing wizards jump quickly." is not a pangram.
The sentence "This sentence contains A-Z but not the whole alphabet." is not a pangram.
Source code in the julia programming language
function makepangramchecker(alphabet)
alphabet = Set(uppercase.(alphabet))
function ispangram(s)
lengthcheck = length(s) ≥ length(alphabet)
return lengthcheck && all(c in uppercase(s) for c in alphabet)
end
return ispangram
end
const tests = ["Pack my box with five dozen liquor jugs.",
"The quick brown fox jumps over a lazy dog.",
"The quick brown fox jumps\u2323over the lazy dog.",
"The five boxing wizards jump quickly.",
"This sentence contains A-Z but not the whole alphabet."]
is_english_pangram = makepangramchecker('a':'z')
for s in tests
println("The sentence \"", s, "\" is ", is_english_pangram(s) ? "" : "not ", "a pangram.")
end
You may also check:How to resolve the algorithm Combinations and permutations step by step in the VBScript programming language
You may also check:How to resolve the algorithm Increasing gaps between consecutive Niven numbers step by step in the Go programming language
You may also check:How to resolve the algorithm The Twelve Days of Christmas step by step in the Quackery programming language
You may also check:How to resolve the algorithm Read a configuration file step by step in the PHP programming language
You may also check:How to resolve the algorithm Plasma effect step by step in the Java programming language