Anonymous user
Pangram checker: Difference between revisions
Added uBasic/4tH version
(Consolidate BASICs) |
imported>Thebeez (Added uBasic/4tH version) |
||
(14 intermediate revisions by 11 users not shown) | |||
Line 258:
=={{header|APL}}==
<syntaxhighlight lang="apl">
a←'abcdefghijklmnopqrstuvwxyz' ⍝ or ⎕ucs 96 + ⍳26 in GNU/Dyalog
A←'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ⍝ or ⎕ucs 64 + ⍳26, or just ⎕a in Dyalog
0
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 657 ⟶ 679:
NEXT text%
=FALSE</pre>
==={{header|Commodore BASIC}}===
<syntaxhighlight lang="gwbasic">10 rem detect model for title display
20 mx=peek(213): if mx=21 or mx=39 or mx=79 then 50:rem pet, vic, c64
30 mx=peek(238): if mx=39 or mx=79 then 50: rem c128
40 mx=39:color 4,1:rem assume plus/4 or c-16
50 if mx=21 then poke 36879,30:rem fix color on vic-20
60 print chr$(147);chr$(14);chr$(18);"**";:for i=2 to (mx-15)/2:print " ";:next
70 print "Pangram Checker";
80 for i=(mx-15)/2+16 to mx-2: print " ";: next: print "**"
100 read s$
110 if len(s$)=0 then end
120 gosub 1000:print
130 print "'"s$"' is";
140 if p=0 then print " not";
150 print " a pangram."
160 goto 100
500 data "The quick brown fox jumps over the lazy dog."
510 data "The quick brown fox jumped over the lazy dog."
520 data "The five boxing wizards jump quickly."
530 data
900 rem pangram checker
1000 if f=0 then f=1:dim seen(25),a(2):a(0)=65:a(1)=97:a(2)=193:goto 1020
1010 for i=0 to 25:seen(i)=0:next
1020 for i=1 to len(s$)
1030 : c=asc(mid$(s$,i))
1040 : for a = 0 to 2
1050 : if c>=a(a) and c<=a(a)+25 then seen(c-a(a))=seen(c-a(a))+1
1060 : next a
1070 next i
1080 p=-1
1090 for i=0 to 25
1100 : if seen(i)=0 then p=0:i=25
1110 next i
1120 return</syntaxhighlight>
{{Out}}
<pre>** Pangram Checker **
'The quick brown fox jumps over the lazy dog.' is a pangram.
'The quick brown fox jumped over the lazy dog.' is not a pangram.
'The five boxing wizards jump quickly.' is a pangram.
ready.</pre>
==={{header|Chipmunk Basic}}===
The [[#Applesoft BASIC|Applesoft BASIC]] solution works without any changes.
==={{header|FreeBASIC}}===
Line 841 ⟶ 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,583 ⟶ 1,685:
<code>&!</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,928 ⟶ 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}}
'''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]]
[[File:Fōrmulæ - Pangram checker 05.png]]
=={{header|Go}}==
Line 2,020 ⟶ 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,185 ⟶ 2,406:
=={{header|K}}==
{{works with|Kona}}
<syntaxhighlight lang="k">lcase : _ci 97+!26
ucase : _ci 65+!26
Line 2,195 ⟶ 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,733 ⟶ 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,105 ⟶ 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,518 ⟶ 3,829:
=={{header|Wren}}==
{{libheader|Wren-str}}
<syntaxhighlight lang="
var isPangram = Fn.new { |s|
|