plz send teh codez!

8

1

Note to Moderators and editors: This post's title is for effect and should not be changed. The misspelling is intentional and part of the challenge.

Backstory

The (stereo)typical bad SO question asks something along the lines of "plz send teh codez!" In other words, it asks someone to do the work for the asker and provide a complete solution to a one-time problem. I quote this question on Meta.SE:

...its about a specific category of questions which consist of absolutely no research, no effort, and simply ask for the complete solution to a problem. These types of questions generally tend to assume that Stack Overflow is a free coding service...

So what is your actual challenge? Its simple:

Your program or function, etc. must take input as a string (from STDIN, parameter, etc.) and if the string contains Plz send teh codez! output -1 flag comment (downvote, flag as off-topic, and comment about how bad a question it is.) Otherwise output +1 (you are upvoting).

But wait… there's more!

Your program must not contain 5 or more of these character sets:

  • All special characters (anything not a space, newline (0x0a), case-insensitive alphabet, or digit)
  • Any digit (0-9)
  • Any of pzcm (case-insensitive)
  • Any of hten (case-insensitive)
  • Any of qwryuioasdfgjklxvb
  • Any of QWRYUIOASDFGJKLXVB

To be clear, you can only use up to 4 of those charsets.

Spaces, tabs and newlines are not restricted in any way, but they still are included in your byte count

Final restriction

Your program must contain Unicode ONLY in the range of 0x20 (space) to 0x7e (~), as well as 0x0a (LF newline) and 0x09 (tab). This is to exclude code golfing languages and give traditional languages a change or at least level the playing field.

Notes:

  • This is , the shortest answer in bytes wins!
  • Input can be from STDIN, a function parameter, command-line parameter, etc. but not a variable.
  • Output can be to STDOUT, a function return value, or even an error/exception. Can include a trailing newline.
  • Traditional languages are encouraged to compete because this challenge bans a lot of golfing languages by excluding high Unicode characters. C might even have a chance of winning!
  • Any questions? Comment below!

If it's too hard…

You can ignore the character sets in your answer, but it then becomes non-competitive.

NOTE: You can now use up to 4 character sets. You're welcome.

You can use this snippet to check if your code is valid:

let f = code => {
  let sets = Array(6).fill(false);
  code = code.replace(/\s/g, "");
  code = code.replace(/\d/g, _ => (sets[0] = true, ""));
  code = code.replace(/[pzcm]/gi, _ => (sets[1] = true, ""));
  code = code.replace(/[hten]/gi, _ => (sets[2] = true, ""));
  code = code.replace(/[qwryuioasdfgjklxvb]/g, _ => (sets[3] = true, ""));
  code = code.replace(/[QWRYUIOASDFGJKLXVB]/g, _ => (sets[4] = true, ""));
  if (code) sets[5] = true;
  return sets.reduce((a, b) => a + b, 0);
}
<textarea oninput="var x=f(value);O.innerHTML='You\'re using '+x+' charset'+(x===1?'':'s')+(x>4?', which is too many.':'. Nice job!')"></textarea><br>
<p id=O></p>

programmer5000

Posted 2017-04-01T14:17:18.613

Reputation: 7 828

Answers

3

CJam, 50 49 48 bytes

q"Plz send teh codez!"#)"- flag comment""+"?(T)@

Doesn't use digits or the capital letters set.

Try it online!

Explanation

q                       e# Push the input
"Plz send teh codez!"#  e# Find index of "Plz send teh codez!" in the input (-1 if not found)
)                       e# Increment the index
                        e# Check the truthiness of the index:
 "- flag comment"       e#   If truthy (i.e. it appeared in the input), push this string
 "+"                    e#   If falsy (it wasn't in the input), push this string
?                       e# 
(                       e# Uncons from left, removes the first character of the string and 
                        e#  pushes it on the stack
T)                      e# Push 0, and increment it to 1
@                       e# Bring third-from-top stack element to the top
                        e# Implicit output of stack contents

Business Cat

Posted 2017-04-01T14:17:18.613

Reputation: 8 927

11

JavaScript (ES6), 60 bytes

x=>/Plz send teh codez!/.test(x)?~x+' flag comment':'+'+-~[]

Everything was straightforward, except avoiding using 1 anywhere. I use ~x to get -1 (since if x contains Plz send teh codez!, it's not a valid number and therefore ~x will give -1), and -~[] to get 1 (since if x is e.g. '7', -~x will be 8, so we can't rely on x).

Test snippet

let f =
x=>/Plz send teh codez!/.test(x)?~x+' flag comment':'+'+-~[];

console.log(f("Hello, Plz send teh codez!"))
console.log(f("Hello, Plz send teh codez?"))

ETHproductions

Posted 2017-04-01T14:17:18.613

Reputation: 47 880

Nice abuse of JSFuck logic! – Matthew Roh – 2017-04-01T23:36:17.350

9

JS (JSFuck), 37959 bytes

Here's a gist, since PPCG hates long codes.

Only uses special characters. :P

Heres the original code:

alert(prompt().includes("Plz send teh codez!")?"-1 flag comment":"+1")

Matthew Roh

Posted 2017-04-01T14:17:18.613

Reputation: 5 043

You didn't capitalize the P. ;) – darrylyeo – 2017-04-01T15:14:04.337

@darryleo It is supposed to be. – Matthew Roh – 2017-04-01T15:14:49.190

The P in Plz send teh codez!, I mean. – darrylyeo – 2017-04-01T15:17:39.280

Oh wait now z is wrong. facepalm – Matthew Roh – 2017-04-01T15:21:12.590

4

C, 102 bytes

i;f(char*s){i=strstr(s,"Plz send teh codez!");printf("%+d%s",i?'a'-'b':'b'-'a',i?" flag comment":"");}

Doesn't use any digit or any of QWERTYUIOASDFGHJKLXVBN. Try it online!

betseg

Posted 2017-04-01T14:17:18.613

Reputation: 8 493

4

Retina, 56 bytes

(?!.*Plz send teh codez).+

.+
-$#+ flag comment
^$
+$#+

Try it online!

Uses special characters, the two case insensitive letter sets and other lower-case letters.

First we remove the entire input if it doesn't contain Plz send teh codez. If there is any input left we replace it with -1 flag comment, avoiding the digit with $#+. $+ refers to the last capturing group which is $0 (the entire match) sind there are no capturing groups. $#+ then gives the number of captures, which is always 1.

Finally, if the string is still empty (i.e. we cleared it in the first stage), we replace it with +1 (again using $#+ for the 1).

Martin Ender

Posted 2017-04-01T14:17:18.613

Reputation: 184 808

2

C#, 77 bytes

x=>x.Contains("Plz send teh codes!")?$"{'x'-'y'} flag comment":$"+{'x'/'x'}";

Not being able to use digits is such a pain.

apk

Posted 2017-04-01T14:17:18.613

Reputation: 121

2

Python 2, 95 94 87 Bytes

Uses special characters and all lowercase lowers (plus three char sets and except for "p", which is case insensitive) for a total of four characters sets used.

b=ord('b')-ord('a')
print["+"+`b`,`-b`+" flag comment"][input()=="Plz send teh codez!"]

Try it online! Thanks to @math_junkie for saving 8 bytes! Thanks to @officialaimm for saving two bytes!


a=ord     

Let a be the ord() built-in function.

b=str(a('b')-a('a'))

This is really b=1.

print["+"+b, "-"+b+" flag comment"][input()=="Plz send teh codez!"]

If the statement in the second pair of brackets is true, print the second string in the first pair of brackets. Otherwise, print the first one.

Anthony Pham

Posted 2017-04-01T14:17:18.613

Reputation: 1 911

You can save 5 bytes by avoiding str, and you by removing the space after print: repl

– math junkie – 2017-04-02T00:47:22.717

@math_junkie That creates the error of concatenating an integer with a string – Anthony Pham – 2017-04-02T00:49:03.443

See the link in my above comment – math junkie – 2017-04-02T00:54:20.253

you can save 2 bytes by removing a=ord and actually using ord... seems like its saving, but its not... I had the same :D – officialaimm – 2017-04-02T14:05:32.160

You can save two more with a lambda: lambda n,b=ord('b')-ord('a'):["+"+`b`,`-b`+" flag comment"][n=="Plz send teh codez!"] – math junkie – 2017-04-02T14:28:31.723

Also, I think you need to check whether the input string contains "Plz send teh codez!". "Plz send teh codez!"in n is a quick fix for one extra byte – math junkie – 2017-04-02T14:32:57.900

2

Python 2/3, 81 76 68 bytes

lambda x:["+%s","-%s flag comment"]["Plz send teh codez!"in x]%+True

Uses:

  • All special characters (anything not a space, newline (0x0a), case-insensitive alphabet, or digit)
  • Any of pzcm (case-insensitive)
  • Any of hten (case-insensitive)
  • Any of qwryuioasdfgjklxvb

Doesn't use:

  • Any of QWRYUIOASDFGJKLXVB
  • Any digit (0-9)

-8 bytes thanks to math_junkie

L3viathan

Posted 2017-04-01T14:17:18.613

Reputation: 3 151

1

Save 4 bytes with an array lookup: TIO

– math junkie – 2017-04-02T14:59:10.510

1

Save 4 more by using + instead of int: TIO

– math junkie – 2017-04-02T15:00:37.507

@math_junkie Great ideas! – L3viathan – 2017-04-02T15:01:37.977

2

Python 3, 115 bytes

if"p".upper()+"lz send teh codez!"in input():print("-"+str(len('a'))+" flag comment")
else:print("+"+str(len('a')))

It doesn't use numbers or upper case letters.

Try it online

just_floating

Posted 2017-04-01T14:17:18.613

Reputation: 41

You can remove several spaces, like between if "p", codez!" in, etc. – mbomb007 – 2017-04-03T21:18:26.987

Assigning str(len('a')) to a variable can save you a few more. Splicing the number into the strings directly rather than calling str might also be advantageous. – Julian Wolf – 2017-04-03T21:55:25.243

1

Python 3.5 (137 102 98 87 85 94 Bytes)

Uses small-case letters(3 charsets) + special characters(1 charset) = 4 charsets

i was almost planning to avoid whitespaces as well but the indentation in python forced me to keep one newline so i left the whitespaces as they were.

i=str(ord('b')-ord('a'))
print(['+'+i,'-'+i+' flag comment']['Plz send teh codez!'in input()])

Try it online!

  • saved 35 bytes!!!!: apparently i had forgotten the existence of upper() function before(silly me!!)
  • saved 4 bytes: reduced i=input() to just input()
  • saved 11 bytes!!!: Thanks to Anthony-Pham (used 'P' since it is valid in charset)
  • saved 2 bytes: (removed a=ord; learnt that shortening a function is not always a good idea! :D)
  • added 9 bytes: Thanks to math-junkie for pointing out that I was not displaying +1 for strings with no 'Plz send teh codez!' before.

officialaimm

Posted 2017-04-01T14:17:18.613

Reputation: 2 739

1Well since you are already using p (and it's defined as case-insensitive), you don't need the .upper() – Anthony Pham – 2017-04-01T21:52:24.997

1You need to output +1 for input that does not contain Plz send teh codez! – math junkie – 2017-04-02T14:31:42.277

Thanks for pointing out that, I was unaware of that till now... :D – officialaimm – 2017-04-02T15:27:00.803

1

Common Lisp, 81 bytes

Special + lower case + 2 mixed-case = 4 charsets

(format t"~:[+~s~;-~s flag comment~]"(search"Plz send teh codez!"(read-line))(*))

Ungolfed

(format t "~:[+~s~;-~s flag comment~]"
        (search "Plz send teh codez!" (read-line))
        (*))

Explanation

(read-line)

Accepts a line of input from *standard-input* (STDIN, by default).

(search "Plz send teh codez!" ...)

Scans through the second argument (the read in line) for the index where the first argument starts. Returns either this index or nil (false) if it could not be found.

(*)

Multiplication in lisp is defined to take an arbitrary number of arguments, including none- in that case it always returns 1.

(format t "~:[+~s~;-~s flag comment~]" ...)

#'format is similar to fprintf or sprintf in C. It's first argument, t, designates the output as *standard-output* (STDOUT, by default). The next argument is the format string. "~" is used like "%" in printf- the character(s) following it designate a formatting operation.

"~:[<a>~;<b>~]" is the conditional formatting operation. It takes an argument and continues with <a> if the argument was nil (false). Any other value, like t (true) or a number (for example), has it continue with <b>. The third argument to format (the first, after t and the format string) is the search, so <a> will be chosen if the search fails (and <b> otherwise).

In this case, the <a> (nil/false) branch prints "+~s". "~s" converts a format argument to a string and prints out its characters. The fourth argument to format (the second, after t and the format string) is (*) or 1, so we get "+1" printed.

The <b> branch is similar: "-~s flag comment". It also uses the fourth (second) argument to fill in its "~s", so it prints out "-1 flag comment".

djeis

Posted 2017-04-01T14:17:18.613

Reputation: 281

1

sh + sed, 72 bytes

Uses character sets: 1, 3, 4, 5.

let ""
sed "s/.*Plz send teh codez!.*/-$? flag comment/
tz
s/.*/+$?/
:z"

At first, I wanted to go with pure sed, but I had no idea how to avoid using digits. So I used sh just for that. let "" has an exit status of 1, since it can't be evaluated as an arithmetic expression.

z is just a label and can be replaced with any other character.

Maxim Mikhaylov

Posted 2017-04-01T14:17:18.613

Reputation: 571

1

Mathematica, 265 bytes

This was hard.

t[s_,n_]:=ToString@s~StringTake~{n};If[StringFreeQ[#,t[Head[a^b],i=-I I]<>"l"<>(s=t[RSolve[f[a+i]==f@a-i/Sqrt@a,f@a,a],(i+i+i+i)^(e=i+i+i)+i+e])<>" send teh "<>(k=t[i/Sin@x,e])<>"ode"<>s<>"!"],"+"<>t[i,i],"-"<>t[i,i]<>" flag "<>k<>"o"<>(n=Head[a b]~t~e)<>n<>"ent"]&

Readable version:

t[s_, n_] := ToString@s~StringTake~{n}; 
If[StringFreeQ[#, 
   t[Head[a^b], i = -I I] <> 
    "l" <> (s = 
      t[RSolve[f[a + i] == f@a - i/Sqrt@a, f@a, 
        a], (i + i + i + i)^(e = i + i + i) + i + e]) <> 
    " send teh " <> (k = t[i/Sin@x, e]) <> "ode" <> s <> "!"], 
  "+" <> t[i, i], 
  "-" <> t[i, i] <> " flag " <> k <> "o" <> (n = Head[a b]~t~e) <> n <>
    "ent"] &

Uses special characters, hten, qwryuioasdfgjklxvb and QWRYUIOASDFGJKLXVB. Mathematica without special characters would be basically impossible, and almost all string-related functions include String in their name, so that really limits the choice here…

To get the other character sets, we need a few tricks. Firstly, to get 1 we take the negative of the square of the imaginary number I: i = -I I. Later we also define 3 by e = i+i+i.

The letter P was fairly straightforward: Mathematica treats a^b internally as Power[a,b], so all we need to do is take the head of this (Power), turn it into a string, and take the first (aka ith) letter. (We'll be turning things into strings and taking the nth letter a lot, so we define t[s_,n_]:=ToString@s~StringTake~{n}.) The letter m is similar: take the head of a b, which is Times, and get the third (aka eth) letter.

The letter c is slightly harder: we use the trigonometric identity 1/Sin[x] == Csc[x] (or rather i/Sin[x] since we can't use 1), and take the third letter of Csc[x].

The really hard part is the z. To make a z, we use the HurwitzZeta function (yes, really). We get that by solving the recurrence relation RSolve[f[a + i] == f@a - i/Sqrt@a, f@a, a], which yields the string

"                             1            1
 {{f[a] -> C[1] + HurwitzZeta[-, a] - Zeta[-]}}
                              2            2"

of which the 68th character is z. We get the number 68 as 4^3 + 4.

This could probably be golfed further: the Hurwitz zeta stuff is pretty much copied from the Mathematica documentation, and there's probably a shorter way of getting 68 — or we could use another method entirely for the z. Any suggestions?

Not a tree

Posted 2017-04-01T14:17:18.613

Reputation: 3 106

0

Swift (non-competitive) - 64 bytes

print(x.contains("Plz send teh codez!") ?"-1 flag comment":"+1")

Unfortunately used 5 charsets, couldn't make it without them... Suggestions are welcome!

Mr. Xcoder

Posted 2017-04-01T14:17:18.613

Reputation: 39 774

0

Groovy, 78 bytes

{a="a".length();it.contains("Plz send teh codez!")?-a+" flag comment":"+"+a}

Doesn't use the numbers or the uppercase sets.

Just a straightforward use of the ternary operator. "a".length() is a workaround to get 1

staticmethod

Posted 2017-04-01T14:17:18.613

Reputation: 191