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f7++*0p6:*:*f+1p6:*:*d+2pnf4*1-::1'3:*fb++*0p6:*:*7+2p1'3:*1+*2pnf4*2-1'3:*fc++*0pn95*:::1'4'3*f-3-*0p1'4'3*a-*0p1'4'3**0p6:*:*1+1pn87*1'4'3*b-*0pnac*2-:1'4'3*6-*0p1'4'3*3+*0pnf4*3-1'4'3*1-*0pn88*2-6:*:*5-1pnc9*1-6:*:*2+1pnb4*:6:*:*3+1p6:*:*6+1pn88*6:*:*9+1pnd4*1-6:*:*e+1pnc8*2-:1'3:**1p1'3:**2pnd7*2+6:*:*4+2pn75*6:*:*6+2pn>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Try it online!
This making this was a hellfest.
How this works:
The program is a bunch of put statements that assembles a Program B around itself which then prints half of the source byte shifted twice.
The program is actually 2 copies of a 1300 byte program, this is so it's ensured that the whole 1300 byte program always gets ran as a whole.
Better explanation:
Every Befunge-98 quine needs to contain symbols such a @
or q
and ,
Problem: None of those symbols are a good starting point especialy since @
and q
terminate the program instantly.
Solution: Get rid of those characters in the source code
Problem: How?
Solution: Use p
(put) commands to modify the source code to include the required characters which will print the contains of the source code shifted by one byte and not use the g
command which is cheating.
Problem: (sigh when will these end)
A put command pops 3 values n x y
which determine character, x-coord, y-coord however when the initialization of these values is split in half it can write bad characters in the beginning source code making it useless for quining.
Solution: (last one I promise)
Use 2 copies of the source code, the latter one being the "correct one" this accidentally fixes another problem which is that a put statement (p command + the constant initializers) which is split in half will not get executed, this is fixed by having 2 copies of each statement.
Last thing this needs to work is how do we make the whole source code out of a half?
Answer:
This is visual proof of why two copies of a string byte shifted == Two copies of a byte shifted string. That means we can take a half of the code, byte shift it, then print it twice (OR take half of the code, byte shift it, print, repeat [That's what actually happens])
How this is implemented:
Assume 0123456789abcdef is the source
Befunge Pseudocode:
0123456789abcv;;"123456789abcdef" < go this way <--
>PS'0, repeat 2x ^
PS means Print Stack (not a real instruction).
We push half of the source code in reverse onto the stack using ""
then we print the stack and then we fetch ('
command) the first character 0
which we move in front of the '
and print it last which causes the byte shift, then we repeat the cycle once more to print the second copy.
One technicality to deal with are the symbols inside the source, this can cause trouble if we write it while executing the source code, I circumvented this by adding more put statements which take care of it externally.
This makes the code look something like this:
Explanation:
Green Highlight: Code that takes care of adding characters into the source
Grey Letters (probs poor visibility sorry): Code that gets added by green code
Red Highlight: Code that moves first character of the second half of source code into the Blue area.
Blue Highlight: See Red Highlight
Orange Highlight: Code that makes sure we terminate after we wrote 2 byte shifted copies by putting a @
(terminate) command into the Yellow Area.
Arrows should hopefully make it clearer how the code flow goes.
Here comes the last tough part:
Where do babies source code come from?
Short answer: C# Magic
Long answer: 100+ Befunge code snippets made by hand compiled by C# code.
I manually wrote about 100 constant initializers (a piece of befunge code that pushes a certain number to stack) by hand and then used a custom C# program to compile it into the 1300 byte Befunge output, which I then copy pasted twice and made the final program.
Are you still here? Great thank you for reading! (or at least scrolling to the end)
I hope my bad jokes were fun and not annoying.
Note: No put statement in this code creates a g command which would be cheating.
EDIT: I have verified the code using the following Javascript code in TIO using developer tools
setInterval(()=>{document.getElementById("code").value =
document.getElementById("output").value;
document.getElementById("run").click();}, 2000);
2
Well that's upsetting: https://codegolf.meta.stackexchange.com/a/14104/9365
– Dom Hastings – 2018-04-25T19:07:00.0033@DomHastings You've had months to post that. – mbomb007 – 2018-04-25T19:13:00.473
@DomHastings Oh well, sorry. I guess we both had the same idea. I have by no means stole your idea though, that would be a false claim. – IQuick 143 – 2018-04-25T19:17:53.603
1@mbomb007 I have indeed! I'd kinda forgotten about the items in the sandbox, but there you go! :) – Dom Hastings – 2018-04-25T19:18:28.453
1@IQuick143 Yeah no problem, I wasn't implying that at all! Life has been busy lately and I'd forgotten it was even in the sandbox until I saw your post! – Dom Hastings – 2018-04-25T19:20:50.440
1Is [exactly 2 char] allowed? (seems not to avoid stack-based language
AB
) – l4m2 – 2018-04-25T19:31:47.243@l4m2 It states more than 2 char because your code would actually print it's reverse which is kinda not the point, also if my expectation is correct some language allows for pushing two characters in stack and then emptying the stack by just 2 characters which Would fulfil a reverse quine challenge but not this one (technically). tl;dr I didn't mean to allow exactly 2 char but if you have a reason why I'm willing to listen. – IQuick 143 – 2018-04-25T19:37:26.090
2@IQuick143 I think >2 characters is a good requirement for the reason you stated – dylnan – 2018-04-25T20:00:42.440
1
In tcl, I couldonly do one step:
– sergiol – 2018-04-25T22:01:53.433puts [string index [set c [read [open $argv0]]] end][string range $c 0 end-1]
https://tio.run/##NcoxCsAgDEbhq/yDa8GeRzKIBhFKlJiW3j5th47v41k53OdpC2mZdmnoUvl@iw0FSTlXpDFZELK2KxIRWCr9u2ZpjFAQP952cvcHI'd recommend mentioning the standard valid quine rules
– Jo King – 2018-04-25T22:48:50.5401
<marquee>my code</marquee>
– Magic Octopus Urn – 2018-04-25T23:11:37.007Possible duplicate of Create a rotating quine
– jimmy23013 – 2018-04-26T07:34:46.597Retracted my close vote. The other question is in essence bowling if someone finds a solution. – jimmy23013 – 2018-04-26T07:38:15.010
5
Would this count as a 'rotating quine'? ;p
– Kevin Cruijssen – 2018-04-26T07:48:14.850@jimmy23013 5083 is such a problem but code-bowling version – l4m2 – 2018-04-26T11:11:22.800
sorry no for it div the repeat part length – l4m2 – 2018-04-26T11:12:20.617
@jimmy23013 I checked if a challenge like this one exists and saw the one you linked but this is a different challenge. The point of this one is that your program must survive byte shifting while remaining functional while the mentioned one requires only rotating 2 or more whole parts. – IQuick 143 – 2018-04-26T12:49:01.970
Currently working on a non-cheating Funge-98 Quine. Progress: ~25% – IQuick 143 – 2018-05-01T07:00:42.537
1Well, it's easy to think of languages this is impossible in... Any BF-like program doesn't work, because you can shift to arrive at an unbalanced bracket. Same for JS if you have
=
or parentheses or brackets. More widely stated: a program cannot contain any character that cannot also be the first character. That rules out so many... – mbomb007 – 2018-05-02T18:41:59.6933@mbomb007 Finding a language that this is possible in is a part of the challenge – IQuick 143 – 2018-05-02T19:56:26.203
Slowly getting there, currently writing a C# program to generate the final source code in Befunge-98 – IQuick 143 – 2018-05-04T05:50:46.093