8
\$\begingroup\$

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>

\$\endgroup\$

15 Answers 15

3
\$\begingroup\$

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
\$\endgroup\$
11
\$\begingroup\$

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?"))

\$\endgroup\$
  • \$\begingroup\$ Nice abuse of JSFuck logic! \$\endgroup\$ – Matthew Roh Apr 1 '17 at 23:36
9
\$\begingroup\$

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")
\$\endgroup\$
  • \$\begingroup\$ You didn't capitalize the P. ;) \$\endgroup\$ – darrylyeo Apr 1 '17 at 15:14
  • \$\begingroup\$ @darryleo It is supposed to be. \$\endgroup\$ – Matthew Roh Apr 1 '17 at 15:14
  • \$\begingroup\$ The P in Plz send teh codez!, I mean. \$\endgroup\$ – darrylyeo Apr 1 '17 at 15:17
  • \$\begingroup\$ Oh wait now z is wrong. facepalm \$\endgroup\$ – Matthew Roh Apr 1 '17 at 15:21
4
\$\begingroup\$

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!

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

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).

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

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.

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

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.

\$\endgroup\$
  • \$\begingroup\$ You can save 5 bytes by avoiding str, and you by removing the space after print: repl \$\endgroup\$ – math junkie Apr 2 '17 at 0:47
  • \$\begingroup\$ @math_junkie That creates the error of concatenating an integer with a string \$\endgroup\$ – Anthony Pham Apr 2 '17 at 0:49
  • \$\begingroup\$ See the link in my above comment \$\endgroup\$ – math junkie Apr 2 '17 at 0:54
  • \$\begingroup\$ 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 \$\endgroup\$ – officialaimm Apr 2 '17 at 14:05
  • \$\begingroup\$ You can save two more with a lambda: lambda n,b=ord('b')-ord('a'):["+"+`b`,`-b`+" flag comment"][n=="Plz send teh codez!"] \$\endgroup\$ – math junkie Apr 2 '17 at 14:28
2
\$\begingroup\$

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

\$\endgroup\$
  • 1
    \$\begingroup\$ Save 4 bytes with an array lookup: TIO \$\endgroup\$ – math junkie Apr 2 '17 at 14:59
  • 1
    \$\begingroup\$ Save 4 more by using + instead of int: TIO \$\endgroup\$ – math junkie Apr 2 '17 at 15:00
  • \$\begingroup\$ @math_junkie Great ideas! \$\endgroup\$ – L3viathan Apr 2 '17 at 15:01
2
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ You can remove several spaces, like between if "p", codez!" in, etc. \$\endgroup\$ – mbomb007 Apr 3 '17 at 21:18
  • \$\begingroup\$ 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. \$\endgroup\$ – Julian Wolf Apr 3 '17 at 21:55
1
\$\begingroup\$

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".

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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?

\$\endgroup\$
1
\$\begingroup\$

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.
\$\endgroup\$
  • 1
    \$\begingroup\$ Well since you are already using p (and it's defined as case-insensitive), you don't need the .upper() \$\endgroup\$ – Anthony Pham Apr 1 '17 at 21:52
  • 1
    \$\begingroup\$ You need to output +1 for input that does not contain Plz send teh codez! \$\endgroup\$ – math junkie Apr 2 '17 at 14:31
  • \$\begingroup\$ Thanks for pointing out that, I was unaware of that till now... :D \$\endgroup\$ – officialaimm Apr 2 '17 at 15:27
0
\$\begingroup\$

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

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

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!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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