168
\$\begingroup\$

We all know that if you google the word "google" it will break the internet.

Your task is to create a function that accepts one string and returns its length, in the fewest possible Unicode characters.

However, if the given string is google (lowercase), it will cause an error.

For example, g('bing') will return 4 but g('google') will cause an error.

Please provide an example of usage, and the error if possible.

\$\endgroup\$
30
  • 143
    \$\begingroup\$ I googled google, and Google found Google on Google. Myth Busted. \$\endgroup\$
    – Geobits
    Sep 28, 2015 at 16:32
  • 107
    \$\begingroup\$ @Geobits That is simply a test to see if I will google Google, which I will not. :D \$\endgroup\$
    – rybo111
    Sep 28, 2015 at 16:33
  • 7
    \$\begingroup\$ Does the function need to be case sensitive? Should it throw given 'gOOgle'? \$\endgroup\$
    – AXMIM
    Sep 30, 2015 at 22:07
  • 3
    \$\begingroup\$ When I type google into google (the search bar on chrome), a message came up asking if I wanted to go to google. (Now that it is a tld, this makes sense i.e. com.google works). I clicked it and got a dns lookup error. Internet:broken! \$\endgroup\$
    – Craig
    Oct 1, 2015 at 4:18
  • 6
    \$\begingroup\$ I'm voting to reopen this. I have seen no questions about what constitutes an error for this challenge and it already has 154 answers so I don't think it's fair to change the spec. This may not be an example of a good question but it's clear enough. If an answer really comes down to whether or not a certain output is an error it probably just won't get as many upvotes, anyway. \$\endgroup\$
    – Poke
    Aug 1, 2018 at 19:52

166 Answers 166

4
\$\begingroup\$

Common Lisp, 50 48 bytes

(defun g(s)(if(equal s"google")(g s)(length s)))

Ungolfed:

(defun g(s)                ; Define a function g with one argument s
    (if (equal s "google") ; If s == "google",
        (g s)              ; Then recurse!
        (length s)         ; Else, return the length of s in characters
    )
)

Defines a function g that accepts one string as input. If it is not exactly 'google', then it returns the length. Otherwise, it will call itself on the same string, creating an infinite recursive loop and eventually causing a stack overflow error.

Usage (inside an interactive CLISP shell):

>(load "google.lsp")
Finished loading.
>(g "foo")
3
>(g "Lisp is cool!")
13
>(g "google")
*** - Program stack overflow. RESET

This is pretty long compared to the others, but using recursion seemed fitting for Lisp.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ This won't cause a stack overflow in some Common Lisp implementations (CCL and SBCL won't overflow). \$\endgroup\$
    – nanny
    Sep 28, 2015 at 20:57
4
\$\begingroup\$

Javascript ES6, 51 27 25 bytes

Hi, I'm new to code golf so this can probably be golfed much more, but here it goes:

_=>_=="google"?a:_.length

g=_=>_=="google"?a:_.length

g=_=>{if("google"==_)throw Error();return _.length}

and some test:

(_=>_=="google"?a:_.length)("bing")//4
(_=>_=="google"?a:_.length)("google")// Error: a is not defined

g("bing")// returns 4
g("google")// Error: a is not defined

Edit: Added ? to replace if and replace Error with an undefined object.

Edit 2: I realized my byte count was wrong, and removed the g=

\$\endgroup\$
4
\$\begingroup\$

GolfScript, 14 16 Characters

{.,\'google'=!/}

Like many others, simply compares the input to 'google' and divides the length by the inverse of the result.

Example programs:

\$\endgroup\$
1
  • \$\begingroup\$ @Dennis I see your point. In it's original form it wasn't exactly reusable (you couldn't, say apply the code over an a list). Also I didn't realize that you had written a virtually identical answer in CJam well before I posted this (actually I was only vaguely aware of CJam as a language until now). +1 for your solution, too. \$\endgroup\$
    – p.s.w.g
    Sep 30, 2015 at 4:34
4
\$\begingroup\$

Stuck, 16 Bytes

s_l1u"google"=-/

Following a similar method to most people, will cause a divide by 0 error on "google" being input.

\$\endgroup\$
3
\$\begingroup\$

C# .NET, 65 bytes

int g(string s){return(s!="google")?s.Length:(1/int.Parse("0"));}

Test:

Console.WriteLine(g("str"));
Console.WriteLine(g("google"));
\$\endgroup\$
6
  • 1
    \$\begingroup\$ with C# 6.0 you can save a few characters by doing an expression-bodied method: int g(string s)=>s!="google"?s.Length:(1/int.Parse("0")); \$\endgroup\$
    – DLeh
    Sep 28, 2015 at 19:18
  • 3
    \$\begingroup\$ also you could cause an exception by recursing, eventually you'll get a stack overflow int g(string s)=>s!="google"?s.Length:g(s); \$\endgroup\$
    – DLeh
    Sep 28, 2015 at 19:19
  • 1
    \$\begingroup\$ You can make it crash faster by just calling int.Parse(""). Although the infinite recursion strategy would be even shorter. \$\endgroup\$
    – sara
    Sep 29, 2015 at 9:23
  • \$\begingroup\$ @kai Something like "".Length is shorter than int.Parse(""). \$\endgroup\$
    – Bob
    Sep 29, 2015 at 12:41
  • 1
    \$\begingroup\$ @Bob "".Length just returns 0, it doesn't throw. \$\endgroup\$
    – DLeh
    Oct 1, 2015 at 13:03
3
\$\begingroup\$

PHP 5.4+, 40 49 bytes

This one is quite unexpectedly long.

function g($x){echo[strlen($x),[]][$x==google];}

To run it, just pass a value:

g($argv[1]);

Test-cases:

$php google.php googlea
7
$php google.php google
Notice: Array to string conversion in [...][...] on line 1
Array

I'm not sure if this can ve considered an error for this challenge or not.


One could use the over-used boring method:

function g($x){echo strlen($x)/$x==google;}

Which gives me a size of only 43 bytes.


As an alternative, one could use an exit error code, using the exit construct, for also 49 bytes:

function g($x){exit($x==google?strlen($x).'':1);}

All values between 1 and 254 are valid error codes that PHP uses when exiting.

\$\endgroup\$
1
  • \$\begingroup\$ You could use function g($x){echo$x==google?a():strlen($x);} which is 46 bytes (3 bytes shorter) and throws an actual error and not just a warning. Also your second example function g($x){echo strlen($x)/$x==google;} should be: function g($x){echo strlen($x)/($x!=google);}. / has a higher precedence than == and you have to switch it to !=as well to make it work. \$\endgroup\$ Nov 16, 2015 at 22:53
3
\$\begingroup\$

Scala, 48

def g(s:String)=if(s=="google")0/0 else s.length

To call:

 g("bing")      //> res1: Int = 4
 g("google")    //> java.lang.ArithmeticException: / by zero
\$\endgroup\$
1
  • \$\begingroup\$ you can use an anonymous function, and shave off 4 characters. also, it will be more neat, IMHO, to use ??? rather than 0/0. \$\endgroup\$
    – Jacob
    Mar 27, 2016 at 14:55
3
\$\begingroup\$

bash + coreutils, 57 49 38 36 33 bytes

[ "$1" = google ];expr ${#1} / $?

Calling it with google produces expr: division by zero.

The quotes around $1 are required in order to handle the empty string correctly.

The use of ${#1} is shamelessly stolen from Tarod's answer.

\$\endgroup\$
6
  • \$\begingroup\$ Good! But I think you're mixing bash & linux commands. If you want to, check my answer where I'm using bash to count characters. Happy coding! :) \$\endgroup\$
    – Tarod
    Sep 29, 2015 at 21:57
  • \$\begingroup\$ @Tarod You're right, I should have said bash + coreutils. Combining your use of Bash to count the length of the input with my use of expr allows a shorter answer than either though - see my edit. – Ben just now edit \$\endgroup\$
    – Ben
    Sep 29, 2015 at 22:22
  • \$\begingroup\$ Amazing! :D I'm going to upvote you! Good job, Ben! :) \$\endgroup\$
    – Tarod
    Sep 30, 2015 at 6:08
  • \$\begingroup\$ BTW, I think you should set a new title for your answer. Just 'bash'. \$\endgroup\$
    – Tarod
    Sep 30, 2015 at 11:55
  • \$\begingroup\$ I don't think so - expr seems to be part of coreutils. \$\endgroup\$
    – Ben
    Sep 30, 2015 at 13:16
3
\$\begingroup\$

O, 20 characters

{."google"={@}{.e}?}

Sample run:

bash-4.3$ java xyz.jadonfowler.o.O <( echo '{."google"={@}{.e}?} :f "yahoo" f o' )
5

bash-4.3$ java xyz.jadonfowler.o.O <( echo '{."google"={@}{.e}?} :f "google" f o' )
java.lang.ArrayIndexOutOfBoundsException: Can't pop from empty stack!
        at xyz.jadonfowler.o.Stack.pop(O.java:980)
        at xyz.jadonfowler.o.O.parse(O.java:407)
        at xyz.jadonfowler.o.CodeBlock.run(O.java:1031)
        at xyz.jadonfowler.o.O.parse(O.java:735)
        at xyz.jadonfowler.o.CodeBlock.run(O.java:1031)
        at xyz.jadonfowler.o.O.parse(O.java:99)
        at xyz.jadonfowler.o.O.runFile(O.java:37)
        at xyz.jadonfowler.o.O.main(O.java:20)
java.lang.ArrayIndexOutOfBoundsException: Can't pop from empty stack!
        at xyz.jadonfowler.o.Stack.pop(O.java:980)
        at xyz.jadonfowler.o.O.parse(O.java:425)
        at xyz.jadonfowler.o.O.runFile(O.java:37)
        at xyz.jadonfowler.o.O.main(O.java:20)
\$\endgroup\$
3
\$\begingroup\$

Scala, 36 34 30 29 characters

s=>(Set(s)-"google").max.size

Calling this function on "google" produces java.lang.UnsupportedOperationException: empty.max

\$\endgroup\$
4
  • \$\begingroup\$ Nice idea! However, I'm afraid it does not compile, one must declare s's type: (s:String)=>... When I copy-paste it to scala's REPL I get <console>:1: error: ';' expected but '=>' found. \$\endgroup\$
    – Jacob
    Mar 27, 2016 at 14:58
  • \$\begingroup\$ @Jacob it compiles if the type of s can be inferred from the context, e.g.: val s: String => Int = s=>(Set(s)-"google").max.size. \$\endgroup\$
    – Ben
    Mar 27, 2016 at 21:57
  • \$\begingroup\$ If you want us to use it like that, you must add val s:String=>Int= to your answer. The answer should be a valid Scala expression as-is. \$\endgroup\$
    – Jacob
    Mar 28, 2016 at 2:06
  • \$\begingroup\$ @Jacob it is a valid Scala expression as-is: an anonymous function is a perfectly valid self-contained answer. Valid Scala expressions aren't only those that can be pasted into the Scala REPL without context. The question asks for a function that takes a string and returns an integer: in contexts in which such a function is expected, the answer will compile. However, feel free to take this to Meta. \$\endgroup\$
    – Ben
    Mar 28, 2016 at 8:48
3
\$\begingroup\$

Matlab, 50 51 bytes

Thanks to @rayryeng for removing 1 byte.

This uses an anonymous function, and exploits the fact that the error function with an empty input issues no error.

It's noteworthy that the error given for input 'google' is meta: it's an error using the error function.

@(s)eval('error(find(strcmp(s,''google''))),numel(s)')

Examples:

>> @(s)eval('error(find(strcmp(s,''google''))),numel(s)')
ans = 
    @(s)eval('error(find(strcmp(s,''google''))),numel(s)')
>> ans('abcd')
ans =
     4

>> @(s)eval('error(find(strcmp(s,''google''))),numel(s)')
ans = 
    @(s)eval('error(find(strcmp(s,''google''))),numel(s)')
>> ans('google')
Error using error
The message must be specified as either a string or a message structure.
Error in @(s)eval('error(find(strcmp(s,''google''))),numel(s)')
\$\endgroup\$
3
  • \$\begingroup\$ You could potentially save a byte if you used strcmp! \$\endgroup\$
    – rayryeng
    Oct 1, 2015 at 15:22
  • \$\begingroup\$ Slight change to your error statement... still an isequal there! \$\endgroup\$
    – rayryeng
    Oct 1, 2015 at 16:38
  • \$\begingroup\$ @rayryeng Oops... I should have pasted the new thing from scratch! Corrected, thanks \$\endgroup\$
    – Luis Mendo
    Oct 1, 2015 at 16:41
3
\$\begingroup\$

Perl 6, 19 bytes

{.comb/!/^google$/}

.comb returns list of characters in string (which in numeric context is a number of characters, I use this instead of .chars because it's shorter). Because there is nothing before a period, Perl 6 assumes you wanted to call a method on $_. This is divided by a negated match on regex ^google$ with implicit $_ variable. If it matches, the value becomes 0, and Perl 6 errors because of a division by zero.

Example:

> {.comb/!/^google$/}("qwerty")
6
> {.comb/!/^google$/}("google")
Attempt to divide 6 by zero using div
  in any interactive at src/Perl6/Compiler.nqp line 62
\$\endgroup\$
3
\$\begingroup\$

Java, 84 68 37 bytes

b->b.equals("google")?1/0:b.length();

This is a java.util.function.Function<String, Integer> that divides by 0 if b is the string google.

\$\endgroup\$
3
\$\begingroup\$

Julia, 25 bytes

x->length(x)[x!="google"]

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Vyxal, 7 bytes

‛»Ǒ≠/÷L

Try it Online!

‛»Ǒ≠/÷L
‛»Ǒ     # "google"
   ≠    # ↑ != input
    /   # split input into ↑ even pieces. If input is "google", this will be 0, consequently causing an error
     ÷L # Get the length of the item
\$\endgroup\$
1
  • \$\begingroup\$ You might want to clarify that it's length(^) / (^ != ^^) instead of (length(^) / ^) != ^^. \$\endgroup\$
    – Wezl
    Feb 22, 2021 at 16:02
3
\$\begingroup\$

05AB1E, 10 bytes

Code:

g“Š¹“¹Q</Ä

Explanation:

g           # Take the length of the implicit input
 “Š¹“       # Compressed version of "google"
     ¹Q     # Take the first input again and check if equal to "google"
       <    # Decrement on the bool
        /   # Divide the length by the value
         Ä  # Take the abstract value of the result
            # This is then implicitly printed

Try it online!. When the input is google, nothing is printed due to a division by zero exception.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ *absolute value \$\endgroup\$
    – Oliver Ni
    Feb 6, 2017 at 2:08
3
\$\begingroup\$

Japt, 16 14 bytes

U¥`goog¤`?Δ:Ul

Throws reference error on input of "google". Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Nice! Two tips: 1) "google" can be compressed to goog¤, wrapped in backticks. 2) == can be compressed to ¥. \$\endgroup\$ Nov 26, 2015 at 15:36
  • \$\begingroup\$ Totally ignored compression. I have only scratched the surface of your language @ETHproductions, and thought this may be a great starting point for it. The \u<hex> shorthands are easily missable, better put it inside the docs. \$\endgroup\$
    – noisyass2
    Nov 27, 2015 at 2:24
  • \$\begingroup\$ I've added a section on Unicode shortcuts in the online interpreter. @ThomasKwa You are correct. I've edited the post. \$\endgroup\$ Dec 4, 2015 at 17:14
3
\$\begingroup\$

Vyxal, 8 bytes

ɽ‛»¾=ßṀL

Assumptions

  • Program itself is the function g
  • Program takes exactly one input

"Google" being in the code page dictionary allows for a 3 byte representation: ‛»¾

If input is equal to "google", case insensitive, will attempt to call a triad with too few arguments, else compute length.

Try it Online!

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

CoffeeScript 43 bytes

(g)->return g.length if g!="google";throw-1

Makes an anonymous function that throws -1 if the string is "google", and returns it's length otherwise. Not as obfuscated as I wanted, though.

Link to the online testing environment.

Another variation, 1 byte longer:

(g)->if g!="google"then g.length else throw-1
\$\endgroup\$
1
  • \$\begingroup\$ Nah, too late. There is already a better answer in CoffeeScript... \$\endgroup\$ Sep 28, 2015 at 18:15
2
\$\begingroup\$

Lua, 42 Bytes

This challenge has made me realize how hard it is to cause an error in Lua.

x=io.read()print(x~="google"and #x or t())

Takes an input and if that input isn't google than print the length of the input, if not call a function t which doesn't exist, throwing an error.

\$\endgroup\$
2
  • \$\begingroup\$ Can shave off one byte by removing the space before the '#x'. \$\endgroup\$
    – ouflak
    Nov 22, 2018 at 16:27
  • \$\begingroup\$ Can shave off two more bytes on top of that by saying 'or~x' instead of 'or t()'. Throws a conversion error. \$\endgroup\$
    – ouflak
    Nov 22, 2018 at 16:38
2
\$\begingroup\$

Prolog – 32 bytes

"google"*_:-x.
X*Y:-length(X,Y).

Defines a predicate (*)/2 that throws ERROR: */2: Undefined procedure: x/0 for the input "google":

?- "bing" * Length.
Length = 4.

?- "google" * Length.
ERROR: */2: Undefined procedure: x/0
   Exception: (8) x ? no debug
\$\endgroup\$
3
  • \$\begingroup\$ Ha nice! I tried a Prolog one and only got 56 chars (I'm a beginner). What does the * do? \$\endgroup\$
    – whitfin
    Oct 6, 2015 at 8:21
  • 1
    \$\begingroup\$ @zackehh *, +, ... are valid names for predicates. They have to be written in infix notation and are quite handy for golfing because you can omit the parentheses and the comma for a predicate with two argument. a(A,B):-A is B.A*B:-A is B.: 3 bytes saved for every invocation. \$\endgroup\$
    – Kijewski
    Oct 6, 2015 at 11:22
  • 1
    \$\begingroup\$ learn something new every day, thanks! ;) \$\endgroup\$
    – whitfin
    Oct 6, 2015 at 15:11
2
\$\begingroup\$

rs, 31 bytes

^(google)|(.*)$/((^^\2))^^(1\1)

In rs, ^^ is the length and repetition operator. Used in the unary form, it will get the length of the following text (^^\2). Used in binary form, it will repeat the LHS RHS times ((^^\2))^^(1\1).

Take the input bing. The input is not google, so the second group will match, not the first. Once the substitutions take place, the result is ((^^bing))^^(1). ^^ gets the length to result in (4)^^(1), and the result gets repeated 1 time to result in 4.

However, if the input is google, the first group will match. That will result in ((^^))^^(1google) after substitutions. ^^ will just get the length of the empty string (0), so the result after ^^ is applied will be (0)^^(1google). Now the repetition operator can do its work...or not. See it will try to repeat 0 1google times. As 1google isn't a number, the output will be:

Traceback (most recent call last):
  File "c callback", line 6, in <module>
  File "<string>", line 5, in <module>
  File "<string>", line 167, in main
  File "<string>", line 125, in run
  File "<string>", line 72, in expand
ValueError: invalid literal for int() with base 10: '1google'

Live demo. (Put the input text in the box at the bottom left.)

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

PHP error via a warning(), 62, 52 46 bytes

I feel dirty for these, but it isn't about pretty:

function g($s){echo$s!=google?strlen($s):g();}

This will give "Warning: Missing argument 1 for g()" when you insert 'google', thought that was funny.

function g($s){echo$s!=google?strlen($s):die(err);}

function g($s){if($s!=google){return strlen($s);}die(error);}

PHP error as string, 46 bytes

function g($s){echo$s!=google?strlen($s):err;}

String dont have to be quoted (but should be!)


You can run these via the commandline using g($argv[1]);, or via an older PHP version's register_globals method as an GET g($_GET['string']) or whichever :)

\$\endgroup\$
9
  • \$\begingroup\$ If it is to play a bit 'dirty', you could use err instead, since it is a common abbreviature \$\endgroup\$ Sep 29, 2015 at 14:14
  • \$\begingroup\$ You mean instead of the string 'error'? I wan't too sure about wether to count those bytes, so I just left it there, it's about the logic anyways. \$\endgroup\$
    – Martijn
    Sep 29, 2015 at 14:16
  • \$\begingroup\$ It is. But hey, everybody knows what err means, and you save 2 bytes! Some used undefined variables to show errors. Why can't you use an abbreviation!? \$\endgroup\$ Sep 29, 2015 at 14:24
  • \$\begingroup\$ I guess your right, changed it. Still thinking of another method. I could simply call a undefined function, would safe me even more, but I tough of that as cheating \$\endgroup\$
    – Martijn
    Sep 29, 2015 at 14:57
  • 1
    \$\begingroup\$ That's quite a funny alternative! I wouldn't have though of that! \$\endgroup\$ Sep 30, 2015 at 9:10
2
\$\begingroup\$

C# 4.0, 51 bytes

int g(string s){return s.Length/(s!="google"?1:0);}

Sample:

string userInput = Console.ReadLine();
Console.WriteLine(g(userInput));

Output:

// "pogi" 4
// "google" DivideByZeroException was unhandled
\$\endgroup\$
2
\$\begingroup\$

C++14, 47 bytes

[](auto s){return s=="google"?throw:s.size();};

This is a generic lambda expression in C++14. It simply checks if the argument (string) is "google" and calls terminate if it is - else it returns the length of the string.

It can be called as such:

[](auto s){return s=="google"?throw:s.size();}("some_string"s);

Zereges has a very similar answer here written in C++11. Since this was C++14 it was O.K. by him for me to post this.

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

Befunge-93, 59 characters

<+1\_v#+1:~
vp00$<
<*_v#:\
v_v>$"google"*****-!#
< >00g.@>1

Befunge has no way to actually throw an error, so I just push an "infinite" number of 1s onto the stack. An error will happen somewhere eventually...

Explanation

Anyway, this works by reading in the input and simultaneously keeping track of its length.

<+1\_v#+1:~

This length is stored at location 0,0.

vp00$<

The remaining numbers are multiplied together.

<*_v#:\

This is then compared to the product of "google".

v_v>$"google"*****-!#

If they are the same (i.e., if their difference is zero), then the "error" is thrown. Otherwise, the value stored at 0,0 is retrieved and outputted.

< >00g.@>1
\$\endgroup\$
2
\$\begingroup\$

PHP 5.4, 81 bytes

<?function g($s){eval('if(isset('.($s==google?"$s":'$s').'))print strlen($s);');}
// following added for easy testing, not included in bytes count
g($argv[1]);

Everyone's favourite error when searching for Google! Didn't work out quite as obfuscated as I'd hoped...

Usage:

php 58891.php 'test'
4
php 58891.php 'google'
# error
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Just thought I'd point this out: the challenge ID is 58891, not 85591. Otherwise, good job! \$\endgroup\$
    – clapp
    Oct 6, 2015 at 1:59
  • 1
    \$\begingroup\$ @ConfusedMr_C hah, good spot! I'd like to say I did that deliberately, but that would definitely be a lie! \$\endgroup\$ Oct 6, 2015 at 4:43
2
\$\begingroup\$

OCaml 42 bytes

This does exactly what is asked1: it returns a function which returns the length of its (string) argument, except when the argument is "google", in which case it fails with:

Exception: Division_by_zero.

function"google"->0/0|s->String.length s;;

It doesn’t provide any way to actually call that function, though. In order to do that, you could either write:

(function"google"->0/0|s->String.length s)"some string";;

or you could, you know, give it a name.

let f=function"google"->0/0|s->String.length s;;
f"bing";;

Unpacked, this would give:

(* let f be function with one argument. *)
let f = function
    (* If the argument matches exactly "google", return 0/0 *)
    | "google" -> 0 / 0
    (* If no previous cases were a match, give your argument the name 'string'. *)
    (* and return its length. *)
    | string   -> String.length string
;;
(* Call f with "bing" as it’s argument. *)
f "bing";;

The type of 0 / 0 is int, so the function is correctly typed as string -> int.


  1. Well, I must admit I have not checked these pesky Unicode details.
\$\endgroup\$
0
2
\$\begingroup\$

O, 17 bytes

{e\"google"=L@N?}

To use this function:

"wow" {e\"google"=L@N?} ~

Explanation:

e\               Get the length of the string and swap it on the stack
  "google"=      Compare the string
               ? If
            L@    True (it is google): Rotate top three elements on the stack, throwing an underflow error
              N   False (it is not google): do nothing
                   Length is printed out automatically
\$\endgroup\$
2
\$\begingroup\$

PARI/GP, 21 19 bytes

x->#x/(x!="google")

Example:

? g = x->#x/(x!="google")
%1 = (x)->#x/(x!="google")
? g("bing")
%2 = 4
? g("google")
  ***   at top-level: g("google")
  ***                 ^-----------
  ***   in function g: #x/(x!="google")
  ***                    ^--------------
  *** _/_: impossible inverse in dvmdii: 0.
  ***   Break loop: type 'break' to go back to GP prompt
break> 
\$\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.