forked from TheAlgorithms/Julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pangram.jl
55 lines (42 loc) · 1.2 KB
/
pangram.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
ispangram(input)
Program to determine the sentence is pangram or not.The program will return true if it is pangram and false if it is not.A full description of the algorithm can be found on [exercism](https://exercism.org/tracks/julia/exercises/pangram)
# Arguments:
- `input`: The sentence to find if its pangram or not.
# Examples/Tests
```julia
julia> ispangram(Pack my box with five dozen liquor jugs)
true
julia> ispangram(The quick brown fox jumps over the lazy dog)
true
julia> wordcount(hello world!!!)
false
```
# Algorithm:
```julia
for letter in input
if 'A' <= letter <= 'Z'
x &= ~(1<<(letter-'A'))
elseif 'a' <= letter <= 'z'
x &= ~(1<<(letter-'a'))
end
x == 0 && return true
end
```
# References:
(https://exercism.org/tracks/julia/exercises/pangram)
```
# Contributed by:- [Ihjass Thasbekha](https://github.com/Ihjass)
"""
function ispangram(input)
x = 2^26 - 1
for letter in input
if 'A' <= letter <= 'Z'
x &= ~(1 << (letter - 'A'))
elseif 'a' <= letter <= 'z'
x &= ~(1 << (letter - 'a'))
end
x == 0 && return true
end
return false
end