1
\$\begingroup\$

Your task is to write a self referential program similar to a quine. The objective is to write a program that will generally print to stdout twice whatever the input is. But when it receives the input of "Tell me about your source" it should output its source (like a quine). Also if it receives the query "tell me about your length". It should output its length in utf-8 characters. Like always all standard loopholes are disabled. This is code golf in any language of your choosing.

Sample Input

2

Sample Output

4

Sample Input

Tell me about your source

Sample Output

x

Sample Input

Tell me about your length

Sample Output

1

Clarifications: The input will always be valid your program is always going to receive valid input. Your code is not required to recognize invalid input.

\$\endgroup\$
5
  • \$\begingroup\$ This is an example of a type of challenge to avoid. It also has clarity issues - what if the input is neither a numeric nor one of the special strings? \$\endgroup\$
    – user45941
    Commented Jun 21, 2016 at 20:39
  • \$\begingroup\$ You say it should print "twice the input". Will the input always be an integer if not the other two strings? \$\endgroup\$
    – mbomb007
    Commented Jun 21, 2016 at 20:39
  • \$\begingroup\$ Welcome to Programming Puzzles and Code Golf! As others have said, this challenge could use a bit of clarification. I recommend posting future challenges to the Sandbox where they can get meaningful feedback before being posted to the main site. \$\endgroup\$ Commented Jun 21, 2016 at 20:46
  • \$\begingroup\$ @TimmyD i have added the clarifications you asked for. Let me know if it now satisfies your requirements. \$\endgroup\$ Commented Jun 23, 2016 at 23:07
  • \$\begingroup\$ And this is not necessarilly just a generalized quine as it is not just about being able to print f(source code) but print various different transformations depending on input as well as maintaining some kind of functionality when not being a quine variant. Also technically quines have no input. \$\endgroup\$ Commented Jun 24, 2016 at 0:38

1 Answer 1

1
\$\begingroup\$

Javascript - 93 92 89 bytes

Defines a function f. Not sure of a better way to return.

f=n=>{y="Tell me about your ";x="f="+f;return n==y+"source"?x:n==y+"length"?x.length:2*n}
\$\endgroup\$
1
  • \$\begingroup\$ You could use `f=${f}`.length to avoid the x variable, and you could write `${y="Tell me about your "}source` to inline the y variable declaration, at which point you only have an expression, and you can then remove the {return}. \$\endgroup\$
    – Neil
    Commented Jun 22, 2016 at 12:28

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