Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
5  
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. – FryAmTheEggman yesterday
    
@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... – Super Chafouin yesterday
2  
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. – FryAmTheEggman yesterday
3  
I'd recommend that programs should be at least 6 characters, just so nobody tries, say, Bubblegum. – Sp3000 yesterday
1  
@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. – Martin Ender yesterday

10 Answers 10

Javascript ES6, 44 bytes

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

Output:

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

Still working on golfing, but it works for now.

share|improve this answer
11  
+1 for having another face: =_= – Cyoce yesterday
1  
Can't you do $=_=>`(\^\_\^\)${($+'').slice(3)};$()`;$() (it actually looks even nicer because now it looks like you're waking up a sleeping face). :) – Martin Ender yesterday

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

share|improve this answer
    
pretty sneaky, using the ^ control char... +1 – Easterly Irk yesterday

CJam, 13 11 bytes

"(_)"
_p'^*

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

"(_)"             Push string
      _p          Duplicate and print repr with newline
        '^*       Join string with '^'
share|improve this answer

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.

share|improve this answer
    
Welcome to the site! – DJMcMayhem yesterday

CJAM, 16 15 bytes

Try it here.

{"^(_)"(*}_~sss
share|improve this answer

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”(^_^)

share|improve this answer

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!

share|improve this answer

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

share|improve this answer

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;co%s.log(a,uneval(a),`(${'^'}_${'^'})`)";console.log(a,uneval(a),`($(^_^)_${'^'})`)
share|improve this answer

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
share|improve this answer
    
My first attempt at a quine! – Luis Mendo 1 hour ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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