3
\$\begingroup\$

Inspired by Input ∩ Source Code.


Task

  • Your task is to determine whether the input is a permutation of the source code.

Input

  • A string. Input is flexible; it should be able to handle the character encoding used for the source code.

Output

  • You may only have two possible outputs, one when the input is a permutation of the source code, and one when it is not. Those outputs maybe be of any length (including 0) but must be distinct, consistent, and deterministic.

Specs

  • Similar to challenges, the program/function may not read its own source code and 0-byte solutions are not allowed.

Example

If your source code is ppcg, then an input of cpgp or ppcg would be a permutation of the source code while cpg or cggp or caqp or cpaqr would not be.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ Do I need to consider new lines too? \$\endgroup\$
    – Rod
    Aug 17, 2016 at 14:54
  • 6
    \$\begingroup\$ This is a generalised quine of this question. IMO that makes it borderline dupe. \$\endgroup\$ Aug 17, 2016 at 15:06
  • 1
    \$\begingroup\$ Closed a few seconds before I hit the 'post' button. Ah well, here it is anyway. Javascript, 71 bytes: i=>([...i].sort().reduce((a,b)=>(a<<5)-a+b.charCodeAt(0),0)&4095)==2337 \$\endgroup\$
    – Arnauld
    Aug 17, 2016 at 16:08
  • 1
    \$\begingroup\$ The "duplicate" asks to check if two strings are equal up to permutation. In this challenge one of those strings is the source code of the program you are using for the task. How can it be a duplicate? Does any of those answers work here, even with some modifications? \$\endgroup\$
    – Luis Mendo
    Aug 17, 2016 at 16:35
  • 1
    \$\begingroup\$ @LuisMendo because there are no viable solutions to this challenge except combining the language's standard generalised quine with the shortest solution from the other challenge. There's no good way to solve this except by tacking the string processing problem onto a normal quine, so this challenge doesn't add anything new. \$\endgroup\$ Aug 17, 2016 at 20:26

1 Answer 1

1
\$\begingroup\$

Python 2.7, 135 112 bytes

print sorted(list(input()))==sorted(list('\''*7+'\\'*3+'print sorted(list(input()))==sorted(list(*7+*3+*2))'*2))
\$\endgroup\$
2
  • \$\begingroup\$ Is newline a character? \$\endgroup\$
    – Leaky Nun
    Aug 17, 2016 at 15:11
  • \$\begingroup\$ In the meantime can you use ; to eradicate newlines? We're discussing about newlines \$\endgroup\$
    – Leaky Nun
    Aug 17, 2016 at 15:12

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