Quining, but with Windows files!

9

Write a quine, that when run, creates itself in the current directory, in a source file named itself. We will be using Windows in this, so the file name (and therefore quine) must have the following limitations:

  • None of these characters \ / : ? * < > |
  • Fewer than 211 255 characters

Limitations and assumptions

  • Your code must be a full program (It's going to be run after all).

  • No copying from the source file.

  • You can assume that there isn't another file with your Quine as its name (as it would produce Quine (1)).

  • Errors are allowed (as long as they don't get into the source code

This is , shortest code in bytes wins!

Edit

Maybe I wasn't clear, the file with the name of the quine has to actually contain the quine. My bad.

Thunda

Posted 2017-02-07T06:58:26.620

Reputation: 1 151

What are the limitations on non-ASCII characters in the program? (On Windows, this might quite possibly depend on what language version of Windows is installed; I forget the exact rules and whether they've changed over time.) – None – 2017-02-07T15:11:09.790

Why fewer than 211 bytes? That's kind of an arbitrary restriction... – mbomb007 – 2017-02-07T19:19:19.500

@mbomb007 Max filename size, I believe. – Addison Crump – 2017-02-07T19:20:09.067

1

@VoteToClose It's 255. http://stackoverflow.com/a/265782/2415524

– mbomb007 – 2017-02-07T19:22:02.747

@mbomb007 Typo, perhaps? – Addison Crump – 2017-02-07T19:23:04.220

Why do we have to make it for windows? – theonlygusti – 2017-02-08T08:16:50.927

@theonlygusti because i use windows – Thunda – 2017-02-08T14:20:11.053

Answers

6

Vitsy, 10 27 bytes

'rddd++&"rdd8++a[v}v1-D);].

If : was allowed, I could shorten this to 11 bytes. :(

Explanation:

'rddd++&"rdd8++a[v}v1-D);].
'                           Capture all instructions as a string until encountering
                              ' again, looping if necessary.
 r                          Reverse the current stack (output is top-down).
  ddd++                     Push char literal ' to the stack.
       &                    Push a new stack to the stack stack.
        "                   Same as ', but " specific.
         r                  Reverse the current stack.
          dd8++             Push char literal " to the stack.
               a            Push 10 to the stack.
                [        ]  Loop forever.
                 v          Capture the top value as a variable.
                  }         Take the bottom item of the stack and put it on the top.
                   v        Dump the variable to the stack.
                    1-      Subtract 1.
                      D     Duplicate the top item.
                       );   Pop n; if n is 0, exit the loop.
               a[v v1-D);]  This is a makeshift for loop with 10 iterations.
                          . Pop the top stack as n, and the second stack as o. 
                              Write a file called "n" with the contents of "o".

The two stacks will be identical at the end. On some Java versions, this may throw a FileNotFoundException due to different implementations of the FileInputStream class.

Previous answer before edit:

&'rddd++}.

Explanation:

&           Push a new stack to the stack stack.
 'rddd++    Modified standard quine.
        }   Move the ' to the right place.
         .  Pop the top stack as n, and the second stack as o. Write a file called
                 "n" with the contents of "o". (Quine name, no content)

Because I might as well, here's a diagram of the steps that occur within the stacks (each stack is represented by []):

Initial state: [[]]

&              [[], []]
                  Push a new stack to the stack stack.

 '             [[], ["r", "d", "d", "d", "+", "+", "}", ".", "&"]]
                  This stack state occurs because ' will loop around the line
                    until finding the next '.

  r            [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r"]]
                  Reverses the top (last) stack.

   ddd         [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r", 13, 13, 13]
                  Push thirteen thrice.

      ++       [[], ["&", ".", "}", "+", "+", "d", "d", "d", "r", "'"]
                  Because char ' is 39 = 13 + 13 + 13.

        }      [[], [".", "}", "+", "+", "d", "d", "d", "r", "'", "&"]]
                  Takes the bottom item, then puts it on the top.

         .     []
                  Writes a file with content from the second-to-top stack and the
                    name as the concatenation of all elements in the top stack,
                    with top member priority (backwards from my representation).

I'm actually not sure how this works right; minute changes cause this to break. For example, placing the & in various other locations should work just as well, but it causes ClassCastExceptions, IOExceptions, and ArrayOutOfBoundsExceptions depending on where you put it. I might need to do some bugfixing.

Addison Crump

Posted 2017-02-07T06:58:26.620

Reputation: 10 763

1+1 for Push a new stack to the stack stack. – Pavel – 2017-02-07T20:46:29.827

1+1 from me if you can push a new stack stack to a stack stack stack, otherwise forget it! ... Kidding +1, I laughed too. – Magic Octopus Urn – 2017-02-07T22:04:05.240

2@carusocomputing What if I told you I can with o? ;) – Addison Crump – 2017-02-07T22:04:43.927

Sigh unzip... – Magic Octopus Urn – 2017-02-07T22:07:43.350

@Pavel I have added a stack diagram to demonstrate the creation of stacks within the stack stack, along with the manipulation of individual stacks within the stack stack to make sure that the stacks are stacked correctly. – Addison Crump – 2017-02-07T22:21:51.117

1Uhm... I think that the generated file is supposed to contain the code (i.e. its content should be equal to its filename) – Leo – 2017-02-07T22:41:48.077

@Leo The challenge does not mention this anywhere, I don't think... If that's a requirement, I'll alter it. It'll be a pretty steep bytecount change. – Addison Crump – 2017-02-07T22:46:19.527

See revised edit – Thunda – 2017-02-08T07:57:11.957

@VoteToClose Even after the edit, it's still half the next answer. – Thunda – 2017-02-08T14:20:48.200

@Thunda No - this puts the source code in the output file as well. Both the stacks are filled at the end with identical contents, which means that the content matches the name, and, as they are both quines, they are all the same. – Addison Crump – 2017-02-08T14:26:49.263

5

Node.js, 56 52 bytes

function f(){require('fs').writeFile(f+='f()',f)}f()

This prints the warning

DeprecationWarning: Calling an asynchronous function without callback is deprecated.

If you want the all-green, it costs 4 bytes to change writeFile to writeFileSync.

Patrick Roberts

Posted 2017-02-07T06:58:26.620

Reputation: 2 475

2

Lua, 96 bytes.

s="s=%qs=string.format(s,s)f=io.open(s)f.write(f,s)"s=string.format(s,s)f=io.open(s)f.write(f,s)

Typed this on my phone, should work, but I'll test it when I get to a computer.

ATaco

Posted 2017-02-07T06:58:26.620

Reputation: 7 898

12I think at the very least you'll need to change sting.format to string.format twice. – Peter Taylor – 2017-02-07T08:28:44.480

@PeterTaylor you don't like Sting, do you? – KeyWeeUsr – 2017-02-07T14:08:31.987

5@KeyWeeUsr, I have nothing against him personally, and in fact he helped pay for my upbringing, but I think that the Lua standard library was probably designed for general usability by people familiar with similar APIs rather than specifically for Police fans. – Peter Taylor – 2017-02-07T14:54:01.017

1

C, 134 bytes

s[255];fd;char p[255]="s[255];fd;char p[255]=%c%s%c;main(){sprintf(s,p,34,p,34);creat(s,0);}";main(){sprintf(s,p,34,p,34);creat(s,0);}

MD XF

Posted 2017-02-07T06:58:26.620

Reputation: 11 605

The source here contains * so it doesn't look like it's allowed according to the rules. – Value Ink – 2017-05-23T22:57:17.393

@ValueInk Fixed. Thanks for pointing that out! – MD XF – 2017-05-23T23:10:14.487