Source code GO!

18

3

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.

Arnaud

Posted 2016-09-13T02:13:05.927

Reputation: 8 231

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 – 2016-09-13T02:55:22.123

@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... – Arnaud – 2016-09-13T03:04:26.373

@SuperChafouin no, but it's possible in 5 characters. – Rɪᴋᴇʀ – 2016-09-13T03:07:11.037

3While 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 – 2016-09-13T03:07:38.657

3

I'd recommend that programs should be at least 6 characters, just so nobody tries, say, Bubblegum.

– Sp3000 – 2016-09-13T03:54:46.607

2@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 – 2016-09-13T06:57:33.083

@Sp3000 I don't think it would work, since (^_^) is alerady explicitly forbidden. – Erik the Outgolfer – 2016-09-13T12:11:38.283

@EriktheGolfer \x30\xeb\x97\xaa (4 bytes) outputs (^_^) in Bubblegum – Sp3000 – 2016-09-13T12:51:16.557

@Sp3000 Is it valid DEFLATE or LZMA 2? – Erik the Outgolfer – 2016-09-13T12:53:12.647

@EriktheGolfer Neither - if it's not a valid compression scheme Bubblegum defaults to base 96 encoding – Sp3000 – 2016-09-13T12:53:44.607

@Sp3000 I let you post it as an answer, although I don't think it's valid at all. You would need a filler byte, because the 5 bytes will be modified, not modified or added or both. Maybe a trailing newline would help here. – Erik the Outgolfer – 2016-09-13T12:59:55.720

@EriktheGolfer I wasn't intending on posting it, I'm just demonstrating that Fry's initial question needs an answer. – Sp3000 – 2016-09-13T13:04:51.577

@all added minimum source code size requirement. – Arnaud – 2016-09-13T13:47:55.487

@MartinEnder You're right, I spoke a bit too harshly in my comment. I think my second sentence could have been better ended with "this can be done easily". I more meant it as a warning that posts may devolve into generalised quines with basic restricted source workarounds. – FryAmTheEggman – 2016-09-13T14:21:25.160

Answers

14

Javascript ES6, 44 bytes

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

Output:

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

Still working on golfing, but it works for now.

Mama Fun Roll

Posted 2016-09-13T02:13:05.927

Reputation: 7 234

12+1 for having another face: =_= – Cyoce – 2016-09-13T04:56:08.580

2Can't you do $=_=>\(^_^)${($+'').slice(3)};$()`;$()` (it actually looks even nicer because now it looks like you're waking up a sleeping face). :) – Martin Ender – 2016-09-13T15:14:37.500

10

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

James

Posted 2016-09-13T02:13:05.927

Reputation: 54 537

pretty sneaky, using the ^ control char... +1 – Rɪᴋᴇʀ – 2016-09-13T02:50:43.640

7

CJam, 13 11 bytes

"(_)"
_p'^*

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

"(_)"             Push string
      _p          Duplicate and print repr with newline
        '^*       Join string with '^'

Sp3000

Posted 2016-09-13T02:13:05.927

Reputation: 58 729

3

CJAM, 16 15 bytes

Try it here.

{"^(_)"(*}_~sss

Arnaud

Posted 2016-09-13T02:13:05.927

Reputation: 8 231

3

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.

SCB

Posted 2016-09-13T02:13:05.927

Reputation: 261

Welcome to the site! – James – 2016-09-13T07:13:39.443

3

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),`($(^_^)_${'^'})`)

ETHproductions

Posted 2016-09-13T02:13:05.927

Reputation: 47 880

3

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!

user44712

Posted 2016-09-13T02:13:05.927

Reputation:

2

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

Jonathan Allan

Posted 2016-09-13T02:13:05.927

Reputation: 67 804

2

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

cyber_zodiac

Posted 2016-09-13T02:13:05.927

Reputation: 21

1

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! :-)

Master_ex

Posted 2016-09-13T02:13:05.927

Reputation: 526

1

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

Luis Mendo

Posted 2016-09-13T02:13:05.927

Reputation: 87 464

1My first attempt at a quine! – Luis Mendo – 2016-09-14T17:10:33.197