Pangram checker: Difference between revisions

Added uBasic/4tH version
imported>Thebeez
(Added uBasic/4tH version)
 
(12 intermediate revisions by 11 users not shown)
Line 261:
A←'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ⍝ or ⎕ucs 64 + ⍳26, or just ⎕a in Dyalog
 
Panagram←Pangram ← {∧/ ∨⌿ 2 26⍴(a,A) ∊ ⍵}
PanagramPangram 'This should fail'
0
PanagramPangram 'The quick brown fox jumps over the lazy dog'
1
</syntaxhighlight>
Line 575:
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
 
<syntaxhighlight lang="gwbasic"> 100 P$ = "11111111111111111111111111"
110 FOR Q = 1 TO 3
120 READ S$
130 GOSUB 200"IS PANGRAM?
140 PRINT MID$ ("NO YES ",P * 4 + 1,4)S$
150 NEXT Q
160 END
170 DATA"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG."
180 DATA"THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG."
190 DATA"THE FIVE BOXING WIZARDS JUMP QUICKLY."
200 P = 0:L = LEN (S$): IF NOT L THEN RETURN
210 F$ = "00000000000000000000000000"
220 FOR I = 1 TO L
230 C = ASC ( MID$ (S$,I,1)):C = C - 32 * (C > 95): IF C > 64 AND C < 91 THEN J = C - 64:F$ = MID$ (F$,1,J - 1) + "1" + MID$ (F$,J + 1):P = F$ = P$: IF P THEN RETURN
240 NEXT I
250 RETURN</syntaxhighlight>
{{out}}
<pre>
YES THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.
NO THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG.
YES THE FIVE BOXING WIZARDS JUMP QUICKLY.
</pre>
==={{header|BaCon}}===
This can be done in a one-liner.
Line 704 ⟶ 726:
 
ready.</pre>
 
==={{header|Chipmunk Basic}}===
The [[#Applesoft BASIC|Applesoft BASIC]] solution works without any changes.
 
==={{header|FreeBASIC}}===
Line 888 ⟶ 913:
<pre>NOT A PANGRAM</pre>
 
==={{header|uBasic/4tH}}===
<syntaxhighlight lang="basic">Proc _ShowPangram ("The quick brown fox jumps over the lazy dog.")
Proc _ShowPangram ("QwErTyUiOpAsDfGhJkLzXcVbNm")
Proc _ShowPangram ("Not a pangram")
 
End
 
_ShowPangram ' demonstrate the Pangram() function
Param (1)
Print Show (a@);Tab (50);Show (Iif (FUNC(_Pangram (a@)), "A pangram", "Not a pangram"))
Return
 
_Pangram
Param (1) ' pangram candidate
Local (3)
 
b@ = 0 ' reset the bitmap
 
For d@ = 0 To Len(a@) -1 ' parse the string
c@ = Peek (a@, d@) ' get current character
If (c@ > Ord ("A") - 1) * (c@ < Ord ("Z") + 1) Then c@ = c@ + 32
If (c@ > Ord ("a") - 1) * (c@ < Ord ("z") + 1) Then b@ = OR(b@, 2^(c@ - Ord ("a")))
Next ' update the bitmap
Return (b@ = 67108863) ' all bits set?</syntaxhighlight>
{{Out}}
<pre>The quick brown fox jumps over the lazy dog. A pangram
QwErTyUiOpAsDfGhJkLzXcVbNm A pangram
Not a pangram Not a pangram
 
0 OK, 0:156</pre>
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">sub isPangram$(t$, l1$)
Line 1,630 ⟶ 1,685:
 
<code>&amp;!</code> is the “but-not” or set difference operator.
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
func pangr s$ .
len d[] 26
for c$ in strchars s$
c = strcode c$
if c >= 97 and c <= 122
c -= 32
.
if c >= 65 and c <= 91
d[c - 64] = 1
.
.
for h in d[]
s += h
.
return s
.
repeat
s$ = input
until s$ = ""
print s$
if pangr s$ = 26
print " --> pangram"
.
print ""
.
input_data
This is a test.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumped over the lazy dog.
QwErTyUiOpAsDfGhJkLzXcVbNm
</syntaxhighlight>
 
=={{header|EDSAC order code}}==
Line 1,975 ⟶ 2,064:
"The quick brown fox jumps over the lazy dog." is a pangram.
</pre>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn IsPangram( pangramString as CFStringRef ) as BOOL
NSUInteger i, count
BOOL result
CFStringRef lcPanStr = fn StringLowerCaseString( pangramString )
CFMutableSetRef mutSet = fn MutableSetWithCapacity( 0 )
count = len(lcPanStr)
for i = 0 to count - 1
if ( fn CharacterSetCharacterIsMember( fn CharacterSetLowercaseLetterSet, fn StringCharacterAtIndex( lcPanStr, i ) ) )
MutableSetAddObject( mutSet, fn StringWithFormat( @"%c", fn StringCharacterAtIndex( lcPanStr, i ) ) )
end if
next
if fn SetCount( mutSet ) >= 26 then result = YES else result = NO
end fn = result
 
 
CFStringRef testStr, trueStr, falseStr
CFArrayRef array
 
trueStr = @"Is a pangram"
falseStr = @"Not a pangram"
 
array = @[¬
@"My dog has fleas.",¬
@"The quick brown fox jumps over the lazy do.",¬
@"The quick brown fox jumped over the lazy dog.",¬
@"The quick brown fox jumps over the lazy dog.",¬
@"Jackdaws love my big sphinx of quartz.",¬
@"What's a jackdaw?",¬
@"Watch \"Jeopardy!\", Alex Trebek's fun TV quiz game.",¬
@"Pack my box with five dozen liquor jugs.",¬
@"This definitely is not a pangram.",¬
@"This is a random long sentence just for testing purposes."]
 
for testStr in array
if ( fn IsPangram( testStr ) )
NSLog( @"%13s : %@", fn StringUTF8String( trueStr ), testStr ) else NSLog( @"%s : %@", fn StringUTF8String( falseStr ), testStr )
end if
next
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Not a pangram : My dog has fleas.
Not a pangram : The quick brown fox jumps over the lazy do.
Not a pangram : The quick brown fox jumped over the lazy dog.
Is a pangram : The quick brown fox jumps over the lazy dog.
Is a pangram : Jackdaws love my big sphinx of quartz.
Not a pangram : What's a jackdaw?
Is a pangram : Watch "Jeopardy!", Alex Trebek's fun TV quiz game.
Is a pangram : Pack my box with five dozen liquor jugs.
Not a pangram : This definitely is not a pangram.
Not a pangram : This is a random long sentence just for testing purposes.
</pre>
 
 
 
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Pangram_checker}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for storage and transfer purposes more than visualization and edition.
 
'''Solution'''
 
[[File:Fōrmulæ - Pangram checker 01.png]]
 
'''Test cases'''
 
[[File:Fōrmulæ - Pangram checker 02.png]]
 
[[File:Fōrmulæ - Pangram checker 03.png]]
 
[[File:Fōrmulæ - Pangram checker 04.png]]
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Pangram checker 05.png]]
In '''[https://formulae.org/?example=Pangram_checker this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Go}}==
Line 2,067 ⟶ 2,231:
write(" a panagram.")
end</syntaxhighlight>
 
=={{Header|Insitux}}==
 
<syntaxhighlight lang="insitux">
(function pangram? sentence
(let prepped (-> sentence lower-case to-vec))
(all? prepped (map char-code (range 97 123))))
 
(pangram? "The five boxing wizards jump quickly.")
</syntaxhighlight>
 
=={{header|Io}}==
Line 2,232 ⟶ 2,406:
 
=={{header|K}}==
{{works with|Kona}}
<syntaxhighlight lang="k">lcase : _ci 97+!26
ucase : _ci 65+!26
Line 2,242 ⟶ 2,417:
panagram "Panagram test"
0</syntaxhighlight>
 
{{works with|ngn/k}}
<syntaxhighlight lang=K>isPangram:0=#(`c$"a"+!26)^_:
 
isPangram"This is a test"
0
isPangram"The quick brown fox jumps over the lazy dog."
1</syntaxhighlight>
 
=={{header|Kotlin}}==
Line 2,780 ⟶ 2,963:
no - no a
</pre>
 
=={{header|Phixmonti}}==
<syntaxhighlight lang="Phixmonti">include ..\Utilitys.pmt
 
def pangram?
lower "abcdefghijklmnopqrstuvwxyz" swap remove len not nip
enddef
 
"The quick brown fox jumps over the lazy dog." pangram?
"This is a test" pangram?
"NOPQRSTUVWXYZ abcdefghijklm" pangram?
"abcdefghijklopqrstuvwxyz" pangram?
 
pstack</syntaxhighlight>
{{out}}
<pre>
[1, 0, 1, 0]
 
=== Press any key to exit ===</pre>
 
=={{header|PHP}}==
Line 3,152 ⟶ 3,354:
return pan
</syntaxhighlight>
 
=={{header|RPL}}==
====Structurally programmed====
{| class="wikitable" ≪
! RPL code
! Comment
|-
|
# 0h SWAP 1 OVER SIZE '''FOR''' j
DUP j DUP SUB NUM
'''IF''' DUP 97 ≥ OVER 122 ≤ AND '''THEN''' 32 - '''END'''
'''IF''' DUP 65 ≥ OVER 90 ≤ AND '''THEN'''
2 SWAP 65 - ^ R→B ROT OR SWAP
'''ELSE''' DROP '''END'''
'''NEXT''' DROP # 3FFFFFFh ==
≫ ‘<span style="color:blue">PANG?</span>’ STO
|
<span style="color:blue">PANG?</span> ''( "sentence" → boolean ) ''
alpha = 0; loop for j = 1 to length(sentence)
c = ascii(sentence[j])
if c lowercase then make it uppercase
if c in ("A".."Z") then
alpha &= 2^(c-65)
end loop
return alpha & 3FFFFFFh
|}
====Idiomatically optimized for HP-28S====
{| class="wikitable" ≪
! RPL code
! Comment
|-
|
# 7FFFFFEh RCLF OVER NOT AND STOF SWAP
1 OVER SIZE '''FOR''' j
DUP j DUP SUB NUM
DUP 97 ≥ 95 63 IFTE - 1 MAX 28 MIN SF
'''NEXT''' DROP RCLF OVER AND ==
≫ ‘<span style="color:blue">PANG?</span>’ STO
|
<span style="color:blue">PANG?</span> ''( "sentence" → boolean ) ''
clear flags 1 to 28
loop for j = 1 to length(sentence)
c = ascii(sentence[j])
reduce c to a value between 1 and 28 and set related flag
return 1 if all flags between 2 and 27 are set
|}
To run on more recent models, the following sequence in line 2
RCLF OVER NOT AND STOF
must be replaced by
RCLF DUP 2 GET 3 PICK NOT AND 2 SWAP PUT STOF
and <code>RCLF</code> in the last line by <code>RCLF 2 GET</code>.
"The quick brown fox jumps over the lazy dog" <span style="color:blue">PANG?</span>
"The quick brown fox jumped over the lazy dog" <span style="color:blue">PANG?</span>
{{out}}
<pre>
2: 1
1: 0
</pre>
 
=={{header|Ruby}}==
Line 3,565 ⟶ 3,829:
=={{header|Wren}}==
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "./str" for Str
 
var isPangram = Fn.new { |s|
Anonymous user