Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Programming Exercise #7: Quine (https://forums.graalonline.com/forums/showthread.php?t=134259237)

Tolnaftate2004 05-19-2010 07:59 AM

Programming Exercise #7: Quine
 
Hello all, and welcome to the return of Programming Exercises! If people still like this, maybe I'll do more.

Your mission, should you choose to accept it, is to write a quine. What is a quine you might ask? Well, a quine is a bit of self-replicating code. In particular, it is a code that produces its own source code as its only output.

Write as short a quine as you can!

This is unlike any previous exercise, but you may also want to take a look at exercises #1, #2, #3, #4, #5, and #6 for previous discussions or for fun.

e: Now open for suggestions for the difficulty of PE#8.

cbk1994 05-19-2010 08:17 AM

PHP Code:

function onCreated() {
  
temp.lines.loadLines("weapons/weaponQuine.txt");
  
lines.saveLines("data/output.txt"false);


Do I win?

Tolnaftate2004 05-19-2010 08:22 AM

Quote:

Originally Posted by cbk1994 (Post 1577298)
Do I win?

I had a feeling this would be the first post. :) Very clever.

Let's try to avoid joining classes, using public functions, and using file I/O. The script should be self-contained and independent of filename and other files.

Deas_Voice 05-19-2010 12:22 PM

urgh, i can only come up with infinite-code :(

Edit:
could just post it here for others to see~
PHP Code:

function onCreated() {
  echo(
"
    function onCreated() {
    echo(/"
function onCreated() {
      
/*infinity echos here*/ 
      
}/");
    }
  "
);



fowlplay4 05-19-2010 04:14 PM

PHP Code:

function onCreated() { temp.'"'temp."function onCreated() { temp.q = '%s'; temp.s = %s%s%s; temp.s = format(temp.s, temp.q, temp.q, temp.s, temp.q); echo(temp.s); }"temp.format(temp.stemp.qtemp.qtemp.stemp.q); echo(temp.s); } 


DeCeaseD 05-19-2010 06:17 PM

Don't get this at all.. you should make programming exercises for people who are at a more average level. x_x

fowlplay4 05-19-2010 07:00 PM

Quote:

Originally Posted by DeCeaseD (Post 1577349)
Don't get this at all.. you should make programming exercises for people who are at a more average level. x_x

There's not much to it, write code that outputs itself.

xAndrewx 05-19-2010 07:04 PM

which helps out the graal community in so many ways!! o_o

Fulg0reSama 05-19-2010 08:24 PM

It helps polish the experienced scripters skills.

salesman 05-19-2010 08:37 PM

So by not posting anything, everyone completed the exercise in a way? ez

coreys 05-19-2010 09:40 PM

Quote:

Originally Posted by salesman (Post 1577382)
So by not posting anything, everyone completed the exercise in a way? ez

Quote:

Originally Posted by wikipedia
In some languages, an empty source file is a fixed point of the language, producing no output. Such an empty program, submitted as "the world's smallest self reproducing program", once won the "worst abuse of the rules" prize in the Obfuscated C contest.[1]

:)

DrakilorP2P 05-19-2010 11:15 PM

Probably the most awkward approach possible.

PHP Code:

function quine() {
temp.q=function(s){temp.o="";temp.i=0;for(i=0;i<s.length();++i){temp.c=s.substring(i,1);if(c=="\n")o@="\\n";elseif(c=="\"")o@="\\\"";elseif(c=="\\")o@="\\\\";else o@=c;}return o;};
temp.s="function quine() {\ntemp.q=function(s){temp.o=\"\";temp.i=0;for(i=0;i<s.length();++i){temp.c=s.substring(i,1);if(c==\"\\n\")o@=\"\\\\n\";elseif(c==\"\\\"\")o@=\"\\\\\\\"\";elseif(c==\"\\\\\")o@=\"\\\\\\\\\";else o@=c;}return o;};\ntemp.s=\"STR\";\ntemp.p=temp.s.pos(\"STR\");\nreturn temp.s.substring(0,temp.p)@temp.q(temp.s)@temp.s.substring(temp.p+3);\n}";
temp.p=temp.s.pos("STR");
return 
temp.s.substring(0,temp.p)@temp.q(temp.s)@temp.s.substring(temp.p+3);



DeCeaseD 05-20-2010 12:44 AM

Quote:

Originally Posted by Fulg0reSama (Post 1577379)
It helps polish the experienced scripters skills.

And how exactly do experienced scripters get more experience through doing things they can obviously do? If anything, these exercises should be helping newer scripters learn.

fowlplay4 05-20-2010 01:29 AM

Quote:

Originally Posted by DeCeaseD (Post 1577432)
And how exactly do experienced scripters get more experience through doing things they can obviously do? If anything, these exercises should be helping newer scripters learn.

They're more so mental exercises, obviously there's no real practical use to quine's in the Graal world unless you wanted to make some over the top self-replicating virus.

I.e: Reads level links, leaves a mark, moves on to the new levels, and dies upon entering a marked level while wreaking whatever havoc using any side functions it has. The script should be able to remain in the level, and if re-uploaded the replication process begins again.

The newer scripters could at least attempt the exercises, and maybe even do research of their own before giving up.

Bell 05-20-2010 02:24 AM

Think of it as a scripters puzzle game. They do it for fun.

coreys 05-20-2010 03:26 AM

Assuming you've never approached this problem in the particular language, then it helps sharpen problem solving-skills.

DrakilorP2P 05-20-2010 03:46 AM

Quote:

Originally Posted by DeCeaseD (Post 1577432)
And how exactly do experienced scripters get more experience through doing things they can obviously do? If anything, these exercises should be helping newer scripters learn.

If you've got any ideas for learning exercises how about you make a thread of your own? :)

Tolnaftate2004 05-20-2010 05:48 AM

Quote:

Originally Posted by fowlplay4 (Post 1577336)
PHP Code:

function onCreated() { temp.'"'temp."function onCreated() { temp.q = '%s'; temp.s = %s%s%s; temp.s = format(temp.s, temp.q, temp.q, temp.s, temp.q); echo(temp.s); }"temp.format(temp.stemp.qtemp.qtemp.stemp.q); echo(temp.s); } 


This is very nice.

DeCeaseD 05-20-2010 08:13 AM

Quote:

Originally Posted by DrakilorP2P (Post 1577492)
If you've got any ideas for learning exercises how about you make a thread of your own? :)

Well, if I was as great at scripting as some of you are, I wouldn't have a problem doing so. But obviously my knowledge of scripting prevents me from doing so.

cbk1994 05-20-2010 01:02 PM

Quote:

Originally Posted by DeCeaseD (Post 1577509)
But obviously my knowledge of scripting prevents me from doing so.

Then please stay out of the scripting forum if all you're going to do is criticize others for trying to hone their skills. Clearly level collabs are also a waste of time, right?

DeCeaseD 05-20-2010 08:44 PM

Quote:

Originally Posted by cbk1994 (Post 1577523)
Then please stay out of the scripting forum if all you're going to do is criticize others for trying to hone their skills. Clearly level collabs are also a waste of time, right?

Yeah, I'm going to stay out of the scripting forums for giving my opinion. Clearly my opinion has nothing to do with criticizing. I simply stated that I lack the knowledge to be able to make anything of a "scripting exercise". So, exactly what are you talking about?? :noob:

fowlplay4 05-20-2010 09:02 PM

Next exercise plx.

cbk1994 05-20-2010 10:13 PM

Quote:

Originally Posted by DeCeaseD (Post 1577568)
Yeah, I'm going to stay out of the scripting forums for giving my opinion. Clearly my opinion has nothing to do with criticizing. I simply stated that I lack the knowledge to be able to make anything of a "scripting exercise". So, exactly what are you talking about?? :noob:

Cool, now get out.

cbk1994 05-20-2010 11:21 PM

Quote:

Originally Posted by SKJF91 (Post 1577598)
You're like a little whining girl trying to act cool, please come back when your testicles separate more then 1/2 centimeter from your 1 1/2 inch *****. thank you. (in other words, why are you insulting someone for not being as 'good of a scripter' as you? especially when you're honestly not even that good)

I wouldn't insult someone for being a poor scripter. Did you even read the thread?

Quote:

Originally Posted by DeCeaseD (Post 1577349)
Don't get this at all.. you should make programming exercises for people who are at a more average level. x_x

Quote:

Originally Posted by DeCeaseD (Post 1577432)
And how exactly do experienced scripters get more experience through doing things they can obviously do? If anything, these exercises should be helping newer scripters learn.

His criticism of this exercise when he clearly does not understand how scripting works (noted by his statement "doing things they can obviously do") is why I'm telling him to get out. His cynicism is not doing anything to help people who have an interest in learning to script or those who wish to improve their scripting. If anything, it's discouraging others from creating similar challenges.


Sweet irony.
Quote:

(in other words, why are you insulting someone for not being as 'good of a scripter' as you? especially when you're honestly not even that good

coreys 05-21-2010 05:07 AM

Quote:

Originally Posted by fowlplay4 (Post 1577336)
PHP Code:

function onCreated() { temp.'"'temp."function onCreated() { temp.q = '%s'; temp.s = %s%s%s; temp.s = format(temp.s, temp.q, temp.q, temp.s, temp.q); echo(temp.s); }"temp.format(temp.stemp.qtemp.qtemp.stemp.q); echo(temp.s); } 


Shortened :)

PHP Code:

function onCreated(){temp.s="function onCreated(){temp.s=\"%s\";temp.s=format(temp.s,temp.s);echo(temp.s);}";temp.s=format(temp.s,temp.s);echo(temp.s);} 

(It may not be -exactly- the same, but I think the lack of escaped quotes in the output is acceptable)

I propose the next exercise be a function generate prime numbers (with an arbitrary upper limit).

fowlplay4 05-21-2010 05:55 AM

Quote:

Originally Posted by coreys (Post 1577680)
Shortened :)

PHP Code:

function onCreated(){temp.s="function onCreated(){temp.s=\"%s\";temp.s=format(temp.s,temp.s);echo(temp.s);}";temp.s=format(temp.s,temp.s);echo(temp.s);} 

(It may not be -exactly- the same, but I think the lack of escaped quotes in the output is acceptable)

I propose the next exercise be a function generate prime numbers (with an arbitrary upper limit).

That was what I originally had, but it wasn't a true replication so I had go to the way I did with the quote variable. Ideally you should be able to paste your output, apply and have it still working.

Fulg0reSama 05-21-2010 05:56 AM

Quote:

Originally Posted by Bell (Post 1577462)
Think of it as a scripters puzzle game. They do it for fun.

This kind of fun makes my head hurt, I think I'll go back to playing with a rock and a stick

Tolnaftate2004 05-21-2010 06:06 AM

Quote:

Originally Posted by coreys (Post 1577680)
(... but I think the lack of escaped quotes in the output is acceptable)

It is not. (You can however take advantage of the fact that s maps to temp.s after definition.)

Quote:

Originally Posted by coreys (Post 1577680)
I propose the next exercise be a function generate prime numbers (with an arbitrary upper limit).

Noted, but it's a pretty trivial calculation.

fowlplay4 05-21-2010 06:28 AM

My new shorter one.. only real difference is that format takes place in the echo.

PHP Code:

function onCreated(){q='"';s="function onCreated(){q='%s';s=%s%s%s;echo(format(s,q,q,s,q));}";echo(format(s,q,q,s,q));} 


coreys 05-22-2010 06:14 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1577689)
Noted, but it's a pretty trivial calculation.

*shrug* it's a worthwhile exercise I think. Although the real trick would be getting it to generate prime numbers 'concurrently' (not really concurrent, but as close as you can get to it, using scheduleEvent() for example) :P

Tolnaftate2004 05-24-2010 07:03 AM

I think we can go shorter (without resorting to global variables)...


All times are GMT +2. The time now is 05:44 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.