Pangram checker
BBC BASIC
<lang bbcbasic> FOR test% = 1 TO 2
READ test$ PRINT """" test$ """ " ; IF FNpangram(test$) THEN PRINT "is a pangram" ELSE PRINT "is not a pangram" ENDIF NEXT test% END DATA "The quick brown fox jumped over the lazy dog" DATA "The five boxing wizards jump quickly" DEF FNpangram(A$) LOCAL C% A$ = FNlower(A$) FOR C% = ASC("a") TO ASC("z") IF INSTR(A$, CHR$(C%)) = 0 THEN = FALSE NEXT = TRUE DEF FNlower(A$) LOCAL A%, C% FOR A% = 1 TO LEN(A$) C% = ASCMID$(A$,A%) IF C% >= 65 IF C% <= 90 MID$(A$,A%,1) = CHR$(C%+32) NEXT = A$</lang>
- Output:
"The quick brown fox jumped over the lazy dog" is not a pangram "The five boxing wizards jump quickly" is a pangram
String manipulation is expensive, especially in loops, so it may be better to buffer the string and use character values:
DEFFNisPangram(text$) LOCAL size%,text%,char%,bits% size%=LENtext$ IF size%<27 THEN =FALSE:REM too few characters DIM text% LOCAL size%:REM BB4W and RISC OS 5 only $text%=text$:REM buffer the string FOR text%=text% TO text%+size%-1:REM each character char%=?text% OR 32:REM to lower case IF 96<char% AND char%<123 THEN bits%=bits% OR 1<<(char%-97):REM set ordinal bit IF bits%=&3FFFFFF THEN =TRUE:REM all ordinal bits set NEXT text% =FALSE