18
\$\begingroup\$

Let's use augmented reality to hunt small creatures hidden in source-code. Write a quine program that outputs its own code source, except for 5 consecutive characters that will be modified and that will display a PCG-mon : (^_^)

The 5 consecutive characters can be positioned anywhere in the source code (from position 0 to n-5, n being the source code length). The source code must have a minimum length of 5 characters. The string (^_^) or any of its substring of length >=2 must not appear in initial source code, only in output.

Example of valid submission:

  • source code my source code, output my (^_^)e code

Invalid:

  • source code (^_^) copy;, output (^_^) (^_^)

Winning criteria

The shortest code in bytes wins.

\$\endgroup\$
  • 5
    \$\begingroup\$ Not to be overly negative, but this is a generalised quine and a do x without y problem. In a language with a general quining method, this is rather dull. You also haven't specified what should happen if your source code is 5 bytes or fewer. \$\endgroup\$ – FryAmTheEggman Sep 13 '16 at 2:55
  • \$\begingroup\$ @Fry I don't think it's possible to display the 5 characters (^_^) with a source code with less than 5 characters ? maybe with specific encoding... \$\endgroup\$ – Arnaud Sep 13 '16 at 3:04
  • 3
    \$\begingroup\$ While I'm not certain that it is possible in this case, it is rather trivial to create a program that prints more bytes than it contains. For example, the Pyth program G produces the output abcdefghijklmnopqrstuvwxyz. \$\endgroup\$ – FryAmTheEggman Sep 13 '16 at 3:07
  • 3
    \$\begingroup\$ I'd recommend that programs should be at least 6 characters, just so nobody tries, say, Bubblegum. \$\endgroup\$ – Sp3000 Sep 13 '16 at 3:54
  • 2
    \$\begingroup\$ @FryAmTheEggman The line between a dull and an interesting generalised quine is rather fine. My meta answer is mostly referring to quines where the only viable solution is to obtain a string representing the entire source code and then processing that string. If there are solutions that can get away without constructing the full source code at some point, I think that usually already allows for interesting solutions (e.g. the currently leading CJam answer). As for the do X without Y, the restriction on substrings seems necessary to avoid trivial (quine) solutions. \$\endgroup\$ – Martin Ender Sep 13 '16 at 6:57

11 Answers 11

14
\$\begingroup\$

Javascript ES6, 44 bytes

$=_=>`$=(\^\_\^\)${($+'').slice(5)};$()`;$()

Output:

$=(^_^)=(\^\_\^\)${($+'').slice(5)};$()`;$()

Still working on golfing, but it works for now.

\$\endgroup\$
  • 12
    \$\begingroup\$ +1 for having another face: =_= \$\endgroup\$ – Cyoce Sep 13 '16 at 4:56
  • 2
    \$\begingroup\$ Can't you do $=_=>`(\^\_\^\)${($+'').slice(3)};$()`;$() (it actually looks even nicer because now it looks like you're waking up a sleeping face). :) \$\endgroup\$ – Martin Ender Sep 13 '16 at 15:14
10
\$\begingroup\$

Vim, 33, 27 keystrokes

qqqqqS(<C-v>94_<C-v>94)q@q<esc>hh"qPq@q

Note that <C-v> means ctrl+v, and is byte 0x16 and <esc> is the escape character, and is byte 0x1B.

This just uses a slightly modified version of my Golf you a quine for great good! answer.

Outputs:

(^_^)S(^V94_^V94)q@q^[hh"qPq@q

This is valid since ^V is the way vim represents <C-v> and ^[ is the way vim represents <esc>.

The basic idea, is just to input the text (^_^) by its code points so we can avoid putting those characters in the source code. In insert mode, <C-v>number will insert the ASCII character of "number". However, since the challenge says:

The string (^_^) or any of its substring of length >=2 must not appear in initial source code, only in output.

This answer abuses the "substring" rule by only entering the codepoints of the ^ characters, and entering (, _, and ) directly.

Here's a gif that lets you see this solution in action, and puts the source code and output side by side for comparison:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ pretty sneaky, using the ^ control char... +1 \$\endgroup\$ – Rɪᴋᴇʀ Sep 13 '16 at 2:50
7
\$\begingroup\$

CJam, 13 11 bytes

"(_)"
_p'^*

Online interpreter (-2 bytes thanks to @MartinEnder).

"(_)"             Push string
      _p          Duplicate and print repr with newline
        '^*       Join string with '^'
\$\endgroup\$
3
\$\begingroup\$

Python, 115 111 107 bytes

def f():s='def f():s=%r;print s%%s.replace(s[:5],"^".join("(_)"))';print s%s.replace(s[:5],"^".join("(_)"))

Call f() and the output is:

def f():s='(^_^)():s=%r;print s%%s.replace(s[:5],"^".join("(_)"))';print s%s.replace(s[:5],"^".join("(_)"))

Inspired in part by this answer to a similar question.

\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! \$\endgroup\$ – DJMcMayhem Sep 13 '16 at 7:13
3
\$\begingroup\$

CJAM, 16 15 bytes

Try it here.

{"^(_)"(*}_~sss
\$\endgroup\$
3
\$\begingroup\$

JavaScript (ES6), 91 bytes

There's already a JavaScript answer, but there's not a non-source-reading JS answer:

a="a=%s;co%s.log(a,uneval(a),`(${'^'}_${'^'})`)";console.log(a,uneval(a),`(${'^'}_${'^'})`)

This is based on my non-source-reading answer to Golf you a quine for great good!. Outputs

a="a=%s;co%s.log(a,uneval(a),`(${'^'}_${'^'})`)";co(^_^).log(a,uneval(a),`(${'^'}_${'^'})`)

This can easily be modified by moving around the second %s in the string. For example,

a="a=%s;console.log(a,uneval(a),`($%s_${'^'})`)";console.log(a,uneval(a),`(${'^'}_${'^'})`)

outputs

a="a=%s;console.log(a,uneval(a),`($%s_${'^'})`)";console.log(a,uneval(a),`($(^_^)_${'^'})`)
\$\endgroup\$
2
\$\begingroup\$

Jelly, 22 bytes

“4094959441b³ỌØV”ṘVabc

Available at TryItOnline

Uses the built-in payload capable quine “ØV”ṘV
The abc on the end is just filler to be replaced
converts the integer into base 100, resulting in [40,94,95,94,41]
casts to characters, resulting in (^_^)
So the whole result is “4094959441b³ỌØV”(^_^)

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

Go (golang), 131 bytes

This challenge must have an answer in Go!

package main;import"fmt";func main(){a:="package main;import\"fmt\";func(%c_%[1]c)(){a:=%q;fmt.Printf(a,94,a)}";fmt.Printf(a,94,a)}

Try it online!

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

C# 5.0, 715 bytes

I know, this is huge. Just wanted to add a C# solution.

/*^()_*/using System.CodeDom;namespace System{class P{static void Main(){var b="/*^()_*/using System.CodeDom;namespace System{{class P{{static void Main(){{var b={0};var f=new string(new[]{{b[3],b[2],b[5],b[2],b[4]}});var w=new IO.StringWriter();CodeDom.Compiler.CodeDomProvider.CreateProvider(\"CSharp\").GenerateCodeFromExpression(new CodePrimitiveExpression(b),w,null);Console.WriteLine(b.Replace(\"[4]}}}}}}}}\",f),w);Console.ReadKey();}}}}}}";var f=new string(new[]{b[3],b[2],b[5],b[2],b[4]});var w=new IO.StringWriter();CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp").GenerateCodeFromExpression(new CodePrimitiveExpression(b),w,null);Console.WriteLine(b.Replace("[4]}}}}",f),w);Console.ReadKey();}}}

The output is:

/*^()_*/using System.CodeDom;namespace System{class P{static void Main(){var b="/*^()_*/using System.CodeDom;namespace System{{class P{{static void Main(){{var b={0};var f=new string(new[]{{b[3],b[2],b[5],b[2],b[4]}});var w=new IO.StringWriter();CodeDom.Compiler.CodeDomProvider.CreateProvider(\"CSharp\").GenerateCodeFromExpression(new CodePrimitiveExpression(b),w,null);Console.WriteLine(b.Replace(\"[4]}}}}}}}}\",f),w);Console.ReadKey();}}}}}}";var f=new string(new[]{b[3],b[2],b[5],b[2],b[4]});var w=new IO.StringWriter();CodeDom.Compiler.CodeDomProvider.CreateProvider("CSharp").GenerateCodeFromExpression(new CodePrimitiveExpression(b),w,null);Console.WriteLine(b.Replace("(^_^)}}",f),w);Console.ReadKey();}}}

Available at Ideone.com

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

MATL, 14 bytes

')_`_*i't&Dwqh

Produces the output ')_`_*i'(^_^)h.

Try it online!

Explanation

')_`_*i'  % Push this string
t&D       % Duplicate and get string representation (i.e. enclose with quotes)
w         % Swap
q         % Subtract 1. Transforms ')_`_*i' into the code points of '(^_^)h'
h         % Concatenate. Automatically casts code points to chars. Implicitly display
\$\endgroup\$
  • 1
    \$\begingroup\$ My first attempt at a quine! \$\endgroup\$ – Luis Mendo Sep 14 '16 at 17:10
1
\$\begingroup\$

Bash, 178 bytes

Q='#(8_8)
printf "Q=\47"
echo -n "$Q"|sed -r "s~(_|\()8~\1^~g"
echo -e "\x27"
tail<<<"$Q" -n4'
printf "Q=\47"
echo -n "$Q"|sed -r "s~(_|\()8~\1^~g"
echo -e "\x27"
tail<<<"$Q" -n4

Pfff, I am not good at quines :/ Any suggestion to golf it more is more than 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.