Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A lipogram is a block of words that omits a particular symbol. Right now, I am avoiding our fifth symbol of 26 that commonly show up. You should know by now what I am omitting. If not, look up "lipogram" and you will know.

Your Task

With a char, a blank, and a following string (blanks may show up in this; with only ASCII 32-126 chars) in input, output falsy if this char is in input string, truthy if not. This char that you must look for will always fit in two spans: "A" to "Z" or "a" to "z" (ASCII 65-90, 97-122). Do not distinguish capitals and non-capitals. Also, don't worry about blanks or punctuation symbols. Both programs and functions satisfy. Also, you may split input char and string into two args for programs or functions, and string as first arg is okay.

Illustrations

Truthy

e This is a lipogram.
a You need to consider other letters too.
E Capitals also count.

Falsy

e This sentence is not a lipogram (for e).
t This particular letter is surprisingly hard.
A You don't need to care about any non-alphabetic symbols.

Non-lipogrammed version

A lipogram is a series of words that leaves out a letter. I left out the letter "e" above.

Your task is to take a character and a string (which may include spaces) as input, separated by a space or newline, and output falsy if the character is in the string, and truthy otherwise. You may assume the string is composed solely of printable ASCII characters (char codes 32-126). The character will always be in the English alphabet, and there is no difference between lowercase and uppercase. The character will not be a space or symbol. You may write a program or a function. For either, you may take the character and string as separate arguments, and the string may come first.

share|improve this question
    
For full programs may I take input as separate lines? – muddyfish Feb 22 at 19:40
    
@muddyfish: Yes. – El'endia Starman Feb 22 at 19:41
    
... and string as first arg is ok. – edc65 Feb 22 at 20:56
17  
+1 great lipogram nevertheless – edc65 Feb 22 at 20:56
1  
You should try "and a string as your first arg is okay." or a similar configuration. – mbomb007 Feb 25 at 14:42

43 Answers 43

C, 42 bytes

#define f(c,s)!strchr(s,c)&!strchr(s,c^32)
share|improve this answer
8  
Codegolfing in C, Ubercodegolfing. – Ander Biguri Feb 23 at 9:45

Javascript ES6 34 26 23 Bytes

x=>!/^(.).*\1/i.test(x)

shaved 8 bytes thanks @MartinBüttner

share|improve this answer
8  
Wow, I didn't know that /i affected \1! – Neil Feb 22 at 22:17

05AB1E, 7 6 4 3 bytes

Code:

l`-

Explanation:

l     # Convert both elements to lowercase
 `    # Flatten the array
  -   # Loop over the second line of text and substract each char from the first character
        For example: "abcde""ba"- would result in "cde"

Try it online!

Truthy is when the current letter is outputted. Falsy is when nothing is outputted.

share|improve this answer
    
So - effectively does a complement operation? – 2012rcampion Feb 23 at 2:15
    
@2012rcampion Yes, that is correct. But only when both values are not integers. – Adnan Feb 23 at 12:44

TeaScript, 5 3 bytes

AµN

Aha \o/! I forgot about implicit input! TeaScript will automatically insert x. (the input) at the beginning. I can then check if it has the other input (in variable µ) and so a NOT (N). I guess TeaScript's best advantage here is its implicit input

Try it online

Explanation

  A µ  N
x.A(y).N  // At compile time

x.A // input, has...
(y) // second input
N   // Logical NOT
share|improve this answer
    
Wow. Much built-in. That reminds me, Japt has this same built-in... cuts another two bytes off :) – ETHproductions Feb 23 at 1:57

Bash, 16 11 bytes

grep -iv $1

-i is the case-insensitive flag, -v inverts (checks for a non-match).

Character must be provided as a command line argument, and the test string on STDIN.

Reduced by 5 bytes with @DigitalTrauma's help!

Sample runs:

llama@llama:~$ echo 'This is a lipogram' | ./lipogram.sh e
This is a lipogram.
llama@llama:~$ echo 'This sentence is not a lipogram (for e).' | ./lipogram.sh e
share|improve this answer
    
Why not read the sentence from STDIN? grep -iv $1. I don't see anything wrong with mixing STDIN and command-line args as input methods - I done it before - but perhaps there is a meta precedent I have missed... – Digital Trauma Feb 22 at 20:19
    
@DigitalTrauma I considered that, but figured it'd be a bit sketchy. Perhaps a topic to be discussed on meta. – Doorknob Feb 22 at 20:21
2  
    
@Dennis Ah, okay, thanks! – Doorknob Feb 22 at 20:26
1  
Can we get any more ^D users to comment on this answer? @Downgoat - are you there? ;-) – Digital Trauma Feb 22 at 21:30

Japt, 12 6 4 bytes

!VoU

Test it online!

@Downgoat's TeaScript answer reminded me that Japt has exactly the same built-in, cutting off a final two bytes.

How it works

       // Implicit: U = input char, V = input string
VoU    // Keep only the chars in V that are equal to U, ignoring case.
!      // Take logical NOT. Returns true if no matches were found, false otherwise.
share|improve this answer
    
Wow. Impressive. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Feb 22 at 20:10
    
@CᴏɴᴏʀO'Bʀɪᴇɴ Thanks to a built-in I had forgotten about, it's now even shorter :) – ETHproductions Feb 23 at 1:57
6  
um wait no that's too short – Cᴏɴᴏʀ O'Bʀɪᴇɴ Feb 23 at 1:57

JavaScript (ES6), 29 bytes

(c,s)=>!RegExp(c,'i').test(s)
share|improve this answer
4  
You can curry the answer as c=>s=>!RegExp(c,"i").test(s), saving a byte. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Feb 22 at 19:54
    
c=>s=>!s.match(c,'i') is 21. :) – ETHproductions Feb 22 at 20:03
    
@ETHproductions match only takes one argument. The second argument logs a console warning in Firefox 39 or later, and won't work in Firefox 47 at all. – Neil Feb 22 at 22:15
    
@Neil I'm using Firefox 44, and it seems to work perfectly fine. – ETHproductions Feb 22 at 22:18
    
@ETHproductions Sure, but I have no reason to believe it works in other browsers, and it will also stop working in Firefox soon. – Neil Feb 22 at 22:47

CJam, 6 byte

lel(&!

Try it online! lel

Explanation

l  e# Read a line of input.
el e# Convert to lower case.
(  e# Pull off the first character.
&  e# Set intersection with the rest of the input.
!  e# Logical NOT.
share|improve this answer

Python 3, 36

Having to ignore case is surprisingly expensive.

lambda a,b:a.lower()not in b.lower()

Takes the arguments as (char, string)

share|improve this answer

Perl, 11 + 1 = 12 bytes

$_=lc!~lc<>

Requires the -p switch and takes input as $string\n$letter

$ perl -pe'$_=lc!~lc<>' <<< $'this is a lipogram\ne'
1

How it works:

            # -p auto reads input into $_ and auto prints at the end
   lc       # lowercase $_
     !~     # Check against regex
       lc<> # Read next line and lowercase it. '=~' will expect the rValue to be
            # a regex and therefore the result from 'lc<>' will be treated as such
$_=         # Assign result ('1' or '') to $_ which will be printed
share|improve this answer

Pyth, 8 7 bytes

-rz0rw0

Explanation

 rw0    -  input().lower()
-       - ^ - V
    rw0 -  input().lower()

Thanks @FryAmTheEggman for telling me I can use - instead of !}

Try it here

share|improve this answer

O, 8 bytes

{_.@_-=}

An anonymous function that takes a character and a string.

Try it online.

Explanation

{_.@_-=}

{      }
 _        Lowercase string
  .       Duplicate
   @      Rotate stack
    _     Lowercase character
     -    Remove all instances of the character
      =   Compare to original
share|improve this answer
    
Why does this need to be a function? Why not just have it be a program? – phase Feb 24 at 6:22
    
@phase I couldn't figure out what char was split. At any rate, I'm pretty sure it's shorter as a function anyways. – quartata Feb 24 at 16:02

Java, 63 bytes.

boolean f(String s,char c){return!s.matches("(?i:.*"+c+".*)");}
share|improve this answer
    
You could also write a lambda expression (s,c)->!s.matches("(?i:.*"+c+".*)") which is shorter – RAnders00 Feb 22 at 22:41
1  
It wouldn't be a proper method though, you have to put String and char somewhere. – shooqie Feb 23 at 15:56

MATL, 5 bytes

kikm~

Try it online!

k        % take first input (letter) implicitly. Convert to lowercase
ik       % take second input (text). Convert to lowercase
m        % ismember function
~        % negate
share|improve this answer

Seriously, 6 bytes

,ù,ùíu

Try it online!

Takes input as 'string'\n'char'

Explanation:

,ù,ùíu
,ù      get string (lowercase)
  ,ù    get char (lowercase)
    íu  1-based index (0 if not found)
share|improve this answer
    
Wouldn't something like ,ù,ùìuY work? (That's supposed to be the I that does indexOf but I don't remember which one does that) – quintopia Feb 23 at 6:09

Julia 0.3, 22 bytes

c->s->c&95∉[s...]&95

uppercase is a long word.

How it works

f(c)=g(s)=c&95∉[s...]&95

f(c)=                     Define a function that takes a character c and returns...
     g(s)=                  a function g that takes a string s and...
          c&95                Compute lo bitwise AND of c and 95.
                              This casts the character c to uppercase.
               [s...]         Yield the list of the characters of the string s.
                     &95      Compute lo bitwise AND of each chararacter and 95.
                              This casts the characters of s to uppercase.
              ∉               Return a Boolean, signaling non-membership.
share|improve this answer

Retina, 11

iA`^(.).*\1

I'm not sure what counts as truthy / falsy in Retina, this will echo the line if it is a lipogram for the given character, and it will return the empty string if it isn't.

This will also work for multiline input.

Try it online!

share|improve this answer
    
An empty string is falsy, so that counts. – El'endia Starman Feb 22 at 19:31

Minkolang 0.15, 10 bytes

$or7Z0Z,N.

Try it here.

Explanation

$o            Read in whole input as characters
  r           Reverse stack
   7Z         Lowercase everything
     0Z       Pop top of stack (a) and count how many 'a's are in the stack
       ,      'not' the top of stack
        N.    Output as number and stop.
share|improve this answer

Rust, 75 bytes

|c:char,s:&str|!s.to_lowercase().contains(c.to_lowercase().next().unwrap())

Biggest score means I win, right? >_<

Try it here.

share|improve this answer

Jelly, 8 bytes

ḢO^O&95P

Try it online!

How it works

ḢO^O&95P  Main link. Input: S (string)

Ḣ         Pop the first character of S.
 O        Ordinal; compute its code point.
  ^O      XOR it with the code points of the remaining characters.
    &95   AND each result with 95.
       P  Take the product of the results.
share|improve this answer
    
Wait, jelly isn't winning? There must be a way to golf it down further! – Generic User Feb 22 at 21:30
    
Not when strings are involved... – Dennis Feb 22 at 21:52
    
This must be rectified. – CalculatorFeline Feb 22 at 22:08

CJam, 10 bytes

{el\ele=!}

An anonymous function (block) that takes a character (not a string!) and a string.

Try it online.

Explanation

{el\ele=!}

{        }
 el\el      lowercase both args
      e=    count occurrences of the character
        !   logical not
share|improve this answer

PowerShell, 36 32 30 29 25 bytes

param($a,$b)$b-notmatch$a

Uses the -notmatch operator, and simply outputs True or False.

share|improve this answer

Python, 34 bytes

lambda c,s:c not in s+s.swapcase()

Checks for character c being in string s, ignoring case by appending a case-swapped copy of s to s. The negation is done with not, which looks lengthy but I don't see better. This is same length:

lambda c,s:(c in s+s.swapcase())<1

You can't omit the parens or else Python will interpet the expression as a chained three-value inequality of form _ in _ < _.

Python 3.5 should allow 33 bytes via set conversions, though I can't test it now.

lambda c,s:{*c}-{*s+s.swapcase()}
share|improve this answer

Pyke, 7 bytes

Dl3+R{!

Explanation:

D       -     eval_or_not(input()).lower()
 l3     -    ^.swapcase()
   +    -   ^+^
    R   -  rotate 2
     {  -  ^ in ^
      ! - not ^
share|improve this answer

JavaScript ES6, 41 40 bytes

x=>!~x.slice(2).search(RegExp(x[0],"i"))

Takes the entire string as an argument. I cannot save bytes by accepting two different arguments because then my answer would melt into the other ES6 answer :(

share|improve this answer
    
I win this time, ES6. ;) Your anonymous function syntax is no match for my not in. – Morgan Thrapp Feb 22 at 19:47
    
@MorganThrapp Gahh, foiled again! – Cᴏɴᴏʀ O'Bʀɪᴇɴ Feb 22 at 19:47
    
that's ok I got this, You move @MorganThrapp. – Shaun H Feb 22 at 21:14

R, 26 bytes

 function(x,y)!grepl(y,x,T)

x is the string, y is the letter, the T in the call to grepl makes it case insensitive.

share|improve this answer

Jolf, 6 7 bytes

So. Many. Sixes. SMS? Well, try it here nonetheless. Replace with \x7f.

⌂ MiI'i
⌂_M      match with flags
   i     the input
    I    with another input
     'i  using i as a flag
share|improve this answer

Ruby, 17 bytes

->c,s{/#{c}/i!~s}
->c,s{  # lambda with two arguments
/#{c}/  # turn the input character into a regexp w/ interpolation
i       # case insensitive
!~      # does not match
s       # input string
}
share|improve this answer

Batch, 53 bytes

@set s=%2
@call set t=%%s:%1=%%
@if %s%==%t% echo 1

Accepts input as two command-line arguments. (Quote the second argument if necessary.) Outputs 1 on success, nothing if the first argument is (insensitively) found in the second.

share|improve this answer

Mathematica, 33 32 bytes

StringFreeQ[##,IgnoreCase->1>0]&

I love it when ## can be used. Input is string, then char.

Or, a case sensitive version: (11 bytes:)

StringFreeQ

Yep, just a builtin.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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