53
\$\begingroup\$

Write a function or program that takes as its input a string and prints a truthy value if the string is a pangram (a sequence of letters containing at least one of each letter in the English alphabet) and a falsey value otherwise.

Case of letters should be ignored; If the string is abcdefghijklmnopqrstuvwXYZ, then the function should still return a truthy value. Note that the string can contain any other characters in it, so 123abcdefghijklm NOPQRSTUVWXYZ321 would return a truthy value. An empty input should return a falsey value.


Test cases

AbCdEfGhIjKlMnOpQrStUvWxYz

==> True


ACEGIKMOQSUWY
BDFHJLNPRTVXZ

==> True


public static void main(String[] args)

==> False


The quick brown fox jumped over the lazy dogs. BOING BOING BOING

==> True

This is code golf. Standard rules apply. Shortest code in bytes wins.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Plus points if your code can check if input is a Pungram. \$\endgroup\$
    – Sainan
    May 17, 2016 at 16:43
  • 14
    \$\begingroup\$ Question name request: Did the quick brown fox jump over the lazy dog? \$\endgroup\$
    – user54200
    Aug 4, 2016 at 11:59

97 Answers 97

3
\$\begingroup\$

Javascript, 110 109 99 95 93 bytes

a=prompt(b=0).toUpperCase();for(i=65;i++<91;)b+=!~a.indexOf(String.fromCharCode(i));alert(!b)

Saved 6 bytes thanks to Thomas Kwa, and 10 thanks in part to ev3.

\$\endgroup\$
4
  • \$\begingroup\$ Would b=0 work for b=[]? \$\endgroup\$
    – user46167
    Dec 11, 2015 at 1:13
  • \$\begingroup\$ Not with this approach. But I may be able to make that work. \$\endgroup\$ Dec 11, 2015 at 1:32
  • \$\begingroup\$ I don't know Javascript, but can you do for(i=65;i++<91;)b+=!~a.indexOf(String.fromCharCode(i));alert(!b)? \$\endgroup\$
    – lirtosiast
    Dec 11, 2015 at 1:40
  • \$\begingroup\$ Wow. That's even shorter than what I just did. \$\endgroup\$ Dec 11, 2015 at 1:50
3
\$\begingroup\$

Rust, 64 bytes

|s:&str|(65u8..91).all(|c|s.to_uppercase().contains(c as char))

You can take a range over chars in Rust,

'a'..'{'

but it's presently useless since you can't iterate over it or collect it or do anything with it. They say arithmetic with characters doesn't make sense, so they won't implement the Add and One traits for it.

Still, lambdas and iterators and type inference keeps it reasonably small.

\$\endgroup\$
3
+100
\$\begingroup\$

APL (Dyalog Extended), 6 bytes

∧/⎕A∊⌈

Try it online!

Explanation:

∧/⎕A∊⌈  ⍝ Monadic function train
      ⌈  ⍝ Convert the input to uppercase
  ⎕A∊   ⍝ For each item in the set of uppercase
         ⍝ letters, determine if it exists in the
         ⍝ uppercased input
∧/       ⍝ And-reduce: test if all letters exist
\$\endgroup\$
3
\$\begingroup\$

Retina, 20 bytes

T`L`l
D`.
C`[a-z]
26

Try it online!

Explained

T`L`l        Transliterate stage. Replaces uppercase letters with lowercase letters.
D`.          Deduplicate stage - keep one copy of every match (meaning every character in this case), discarding suplicates.
C`[a-z]      Count stage - Count lowercase letters
26           (implicit) Count stage - Match the string "26"
             (Since there can't be duplicates, a match means each character occurred once.)
             (output the result of the last stage - 1 for pangrams, 0 for non-pangrams)
\$\endgroup\$
3
\$\begingroup\$

APL (Dyalog Extended), 1̶8̶ 1̶4̶ 12 bytes

{⎕A(∧/∊)⌈⍕⍵}
 ⎕A(∧/∊) ⍝ Check membership in Alphabet array and bitwise reduce by logical AND.
        ⌈ ⍝ Convert to uppercase
         ⍕⍵ ⍝ Encode as character array (handles matrices, empty sets and integers)

Edit: Changed 1⎕C to thanks to rak1507

Edit: Changed 1(819⌶) to 1⎕C thanks to Razetime.

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ I think ⎕C can be used in the latest version instead of 819⌶ \$\endgroup\$
    – Razetime
    Mar 29, 2021 at 6:28
  • \$\begingroup\$ @Razetime Thanks! I didn't know about that. \$\endgroup\$ Mar 29, 2021 at 14:09
  • \$\begingroup\$ ⎕A≡⎕A∩⌈ using ⌈ from extended to uppercase \$\endgroup\$
    – rak1507
    Apr 1, 2021 at 8:18
  • \$\begingroup\$ @rak1507 Very cool solution, but I think it fails the second test case. \$\endgroup\$ Apr 1, 2021 at 23:57
  • \$\begingroup\$ You don't need to support matrices \$\endgroup\$
    – rak1507
    Apr 2, 2021 at 11:59
3
+100
\$\begingroup\$

Vyxal, 6 5 bytes

ɽǍkaƈ

Try it Online!

ɽ   # Convert input to lowercase.
Ǎ   # Remove non-alphabetical characters.
ka  # Push the lowercase alphabet.
ƈ   # Are the set of characters in the two strings the same?
\$\endgroup\$
1
3
\$\begingroup\$

Vyxal r, 5 bytes

⇩kaF¬

Try it Online!

How?

⇩kaF¬
⇩       # Push the input converted to lowercase
 ka     # Push the lowercase alphabet
   F    # Filter - Remove items from the lowercase alphabet that are in the
        # lowercase-converted input.
    ¬   # Logical Not - Returns truthy for an empty list, falsey otherwise.
\$\endgroup\$
2
  • \$\begingroup\$ I managed to get 5 bytes. \$\endgroup\$
    – Deadcode
    Jul 9, 2022 at 17:57
  • \$\begingroup\$ Obligatory "ka can simply be n outside of a context" golfing suggestion for 4 bytes \$\endgroup\$
    – lyxal
    Jul 3, 2023 at 11:01
3
\$\begingroup\$

Thunno 2, 4 bytes

LḳẠƇ

Attempt This Online!

Explanation

LḳẠƇ  # Implicit input
L     # Convert to lowercase
 ḳ    # Sort and uniquify
   Ƈ  # Does this string contain...
  Ạ   # ...the lowercase alphabet?
      # Implicit output
\$\endgroup\$
2
\$\begingroup\$

TeaScript, 12 bytes

Sz.e»xL.I(l©

First TeaScript post since I killed TeaScript :p

Try it online

Ungolfed

Sz.e(#xL.I(l))

Sz   // Lower case alphabet
.e(#   // Loop through alphabet, ensure
       // for every character, below returns true
    xL    // Input lowercased
    .I(l) // Checks if above contains current char
)
\$\endgroup\$
1
  • 1
    \$\begingroup\$ ;-; I feel bad now. TBH I like TeaScript the most. \$\endgroup\$ Dec 10, 2015 at 19:24
2
\$\begingroup\$

JavaScript ES6, 124 114 113 bytes

I'm sure this can be golfed more.

v=(Q,s=[...Array(26)].map((x,i)=>String.fromCharCode(i+97)))=>s.length-1?Q.search(RegExp(s.pop(),"i"))+1&&v(Q,s):1

Generates an anonymous function.

v=(Q,s=[...Array(26)].map((x,i)=>String.fromCharCode(i+97)))=>s.length-1?Q.search(RegExp(s.pop(),"i"))+1&&v(Q,s):1

alert(v(prompt("Enter pangram:")));

\$\endgroup\$
2
  • \$\begingroup\$ @apsillers I think I found the problem. Please test it again (my browser does not support ES6 atm) \$\endgroup\$ Dec 10, 2015 at 19:21
  • \$\begingroup\$ Yep, looks good now! \$\endgroup\$
    – apsillers
    Dec 10, 2015 at 19:30
2
\$\begingroup\$

C, 107 bytes

#include<string.h>
int p(char*i){int a=64;while(++a<91)if(!strchr(i,a)&!strchr(i,a+32))return 0;return 1;}
\$\endgroup\$
1
  • \$\begingroup\$ 68 bytes \$\endgroup\$
    – Peter
    Jun 7, 2023 at 12:42
2
\$\begingroup\$

ES6, 68 bytes

s=>[..."abcdefghijklmnopqrstuvwxyz"].every(x=>RegExp(x,"i").test(s))

That string looks awfully wasteful, but I don't know any better way.

\$\endgroup\$
2
  • \$\begingroup\$ Maybe using a range of charcodes? \$\endgroup\$
    – Cyoce
    Dec 12, 2015 at 8:51
  • \$\begingroup\$ @Cyoce That got me thinking and I tried a range of base 36 digits but so far it still takes 70 bytes: s=>[...Array(x=9,26)].every(z=>RegExp((++x).toString(36),"i").test(s)) \$\endgroup\$
    – Neil
    Dec 13, 2015 at 0:29
2
\$\begingroup\$

Scala, 59 48 46 bytes

print(('a'to'z'diff(readLine.map(_|32)))==Nil)
\$\endgroup\$
1
  • \$\begingroup\$ Using 32| rather than _|32 will (yield a warning but) shave off one more byte \$\endgroup\$
    – Jacob
    May 17, 2016 at 14:48
2
\$\begingroup\$

C#, 91 bytes

Requires (18 bytes):

using System.Linq;

Actual function (73 bytes):

bool P(string s)=>s.ToUpper().Distinct().Where(x=>x>64&&x<91).Count()>25;

How it works: the function first converts everything to uppercase, then removes all duplicates and only keeps the letters. If count of items in the resulting enumerable exceeds 25 (then it must be 26), it's a pangram.

\$\endgroup\$
2
  • \$\begingroup\$ && can be golfed to &, and bool p(string s)=> can be golfed to s=> \$\endgroup\$ Feb 22, 2018 at 14:28
  • \$\begingroup\$ You can save 8 bytes by removing redundant Where method and moving condition to Count method. \$\endgroup\$ Jan 24, 2020 at 8:50
2
\$\begingroup\$

PlatyPar, 14 bytes

'a'z_,X,F(x;l!

Explanation (stack visualizer feature coming soon!):

               ## Implicit: push the input (as a string) to the stack
'a'z_          ## Push the range of a-z (the alphabet) to the stack
     ,X        ## Invert stack, expand input string into individual characters
       ,       ## Invert again
        F  ;   ## Fold (While stack.length > 1)
         (      ## Rotate left, moving the first letter of the input string to the top
          x     ## remove any occurences of that letter from the alphabet array
            l! ## Negate the length of the array, so if there's nothing left
               ## output true, else output false

If I had a ridiculous "push all letters of the alphabet" function this would be 10...

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Pyke, 6 bytes

l1GR-!

Try it here!

l1     -   input().lower()
  G -  -  set_difference(alphabet,^)
     ! - not ^
\$\endgroup\$
2
\$\begingroup\$

Batch, 126 + 2 = 128 bytes

@set p="%*"
@for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z)do @set q=!p:%%a=!&if !q!==!p! exit/b 1
@exit/b

Requires CMD /V /C <filename> <input string> so I added 2 bytes for the /V. Alternative 87 + 2 + 26 = 115 byte version:

@set p="%*"
@for %%a in (?)do set q=!p:%%a=!&if !q!==%p% exit/b 1
@exit/b

(+26 for the files named a, b, c ... z that need to exist in the current directory.)

\$\endgroup\$
0
2
\$\begingroup\$

Java 8, 69 bytes

s->s.toUpperCase().chars().distinct().filter(c->c>64&c<91).count()>25

Alternatives with same byte count:

s->s.chars().map(c->c&~32).distinct().filter(c->c>64&c<91).count()>25
s->s.chars().map(c->c|32).distinct().filter(c->c>96&c<123).count()>25

Try it online.

Similar to @ProgramFOX' C# answer.

\$\endgroup\$
2
\$\begingroup\$

MathGolf, 11 7 bytes

!▀_▄+▀=

Try it online!

Explanation

MathGolf just got a lowercase operator!, ! is the factorial operator for ints, floats and lists, but now it also works as a lowercase operator for strings.

!          convert input to lowercase
 ▀         get unique characters as string
  _        duplicate
   ▄+      add the lowercase alphabet to the second copy
     ▀=    get unique elements and check that they are unchanged
\$\endgroup\$
2
\$\begingroup\$

PHP, 59 56 bytes

<?=!array_diff(range(a,z),str_split(strtolower($argn)));

Try it online!

Alt version 67 bytes

<?=array_intersect($a=range(a,z),str_split(strtolower($argn)))==$a;

Try it online!

Call with php -nF input is from STDIN.

\$\endgroup\$
2
\$\begingroup\$

Perl 5 -p, 30 28 bytes

@a{lc=~/[a-z]/g}++;$_=26==%a

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ -2 bytes by using the \pL shorthand for \p{L} instead of [a-z] (as I see you already did in your 22 byte module-requiring answer): ++@a{uc=~/\pL/g};$_=%a==26 Try it online! – it ends with its own length now :-) Also, why does this only require -p and not -p0? \$\endgroup\$
    – Deadcode
    Apr 11, 2021 at 20:12
  • \$\begingroup\$ Along with the \pl from @Deadcode's comment, you can use %; as the hash and omit it for another byte! Try it online! \$\endgroup\$ Jul 15, 2022 at 10:36
  • \$\begingroup\$ @Deadcode the reason this gives the right output without -0 is the list is added to throughout each iteration, but only has exactly 26 entries once (in your test, I assume in the last line) and Perl's false is empty string.The whole alphabet in the first line: Try it online!. Coercing the result to int: Try it online! \$\endgroup\$ Jul 15, 2022 at 10:40
2
\$\begingroup\$

GolfScript, 18 bytes

Port of the GS2 answer.

{32|}%[123,97>]\-!

Try it online!

Explanation

{   }%             # Map for every item in input
 32|               # Toggle the 6th bit (turning capitalization on)
      [123,        # Generate exclusive range from '}' (previous 'z') to 0
           97>]    # Select all that are >= 'a'
                   # Yielding the lowercase alphabet
               \-  # Set difference between them
                 ! # Negate the value
\$\endgroup\$
0
2
\$\begingroup\$

Dyalog APL, 13 bytes

∧/⎕A∊1(819⌶)⊢

explanation:

1(819⌶)⊢ ⍝ uppercase
⎕A∊      ⍝ check if all uppercase letters belong to the string
∧/        ⍝ AND reduction of the boolean vector
\$\endgroup\$
2
2
\$\begingroup\$

C# (Visual C# Interactive Compiler), 48 bytes

x=>x.ToUpper().Distinct().Count(c=>c>64&c<91)>25

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Kotlin, 47 bytes

{s:String->('a'..'z').all{s.contains(it,true)}}

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ It seems that both this answer and the other one operate on an existing variable, when the challenge requires that a function be built. \$\endgroup\$
    – Wheat Wizard
    Jan 23, 2020 at 14:09
  • \$\begingroup\$ @PostRockGarfHunter Thanks for letting me know. I've updated the answer by adding a Try it online! link so that the solution can be tested. I hope it's OK like this, as I've seen this approach used by others. \$\endgroup\$ Jan 23, 2020 at 20:28
  • 1
    \$\begingroup\$ @JoKing Thanks, I'll keep that in mind! I've updated my answer. I hope it's OK now. \$\endgroup\$ Jan 27, 2020 at 5:19
2
\$\begingroup\$

Husk, 9 bytes

¦m_⁰…'a'z

Try it online!

Explanation

¦m_⁰…'a'z
    …'a'z inclusive range from a to z
 m_⁰      convert input to lowercase
¦         are all alphabets present in it?
\$\endgroup\$
0
2
\$\begingroup\$

Perl 5 -MList::Util=uniq -p0, 22 bytes

$_=26==uniq uc=~/\pL/g

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Jelly, 7 6 bytes

ŒlØaḟṆ

Try it online!

Unless I'm missing something, this is the first jelly answer here.

-1 thanks to the Jelly gurus (caird/chartz and unrelatedstring) in the JHT chat room. Y'all are poggers.

Explained (old)

ŒlQṢØaẇ → a monadic link. Takes a single string as input. We will call that string "S". The flow value of the chain starts as S.
Œl      → The lower case atom. The flow value of the chain is now S.lowercase()
  Q     → The uniquify atom. The flow value of the chain is now unique_elements(S.lowercase())
   Ṣ    → The sort atom. The flow value is now sorted(unique_elements(S.lowercase()))
    Øaẇ → A nilad-dyad pair of the lower case alphabet atom and the is sublist atom. ẇ requires the needle to search for to be on the left and the haystack to search to be on the right. The flow value is now "abcd...xyz" in sorted(unique_elements(S.lowercase())). This consequently has the effect of testing if S, when sorted and case ignored, has every letter of the alphabet. 

Explanation of the 6 byter coming in maybe 12 hours.

\$\endgroup\$
0
2
\$\begingroup\$

Prolog (SWI), 103 bytes

_^[].
S^[H|T]:-member(H,S),S^T.
\B:-string_lower(B,O),string_codes(O,C),C^`abcdefghijklmnopqrstuvwxyz`.

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Kotlin, 56 bytes

{print(('A'..'Z').all{a->it.toUpperCase().contains(a)})}

Using a list of characters where every character has to be found within the input.

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.