Mandoline quine

25

3

Write a quine... from which every other character can be removed it still be a valid quine. You can specify whether to start removing characters at the first or second character.

Scoring criteria (add bonuses/penatly percentages together for total percentage):

  • Answers must be at least 4 characters long
  • Program must contain at least one alphabetical character in its source, so for example, 12345!@#$%^&*() is disqualified
  • +750% if the language used is not Turing-complete (I'm looking at you, HTML!)
  • -15% if the solution does not read its source from anywhere in any form
  • -20% if you can also keep only every 5th character and still form a quine

The score is measured by the number of characters in the first program.

Example (not real programs):

If 123456789abcdef and 13579bdf are both quines, the score is 15. Additionally, if 159d is also a quine, then the final score is 12.

This is code-golf, so lowest score wins.

Jwosty

Posted 2014-03-07T04:37:23.197

Reputation: 3 530

What if a person writes their code so all the removed characters are unnecessary whitespace? – None – 2014-03-07T05:13:29.537

2@hosch250 The original program wouldn't be a quine because it wouldn't print those whitespaces. Same goes for unnecessary comments. – Jwosty – 2014-03-07T05:26:44.467

Guess so. Nice challenge. – None – 2014-03-07T05:27:44.837

@hosch250 hah, I personally am not very good at even writing an answer for this type of thing.... But no matter what challenge you hurl at the people here, several people will have a solution to your insanely hard problem :P – Jwosty – 2014-03-07T05:34:59.453

1Yeah, I have never programed a quine before, and have no idea how to do it without reading the source code in C++. I have seen them in C++ before though! – None – 2014-03-07T05:37:47.747

If you're giving bonuses to markup languages, which don't have an execution model, you must be using a non-standard definition of quine, and you need to include it. – Peter Taylor – 2014-03-07T07:21:57.720

1You state: "-20% if you can also remove every 4 characters and still form a quine". But technically this is not what happens in your example. You mean you can do it a second time? – mmumboss – 2014-03-07T08:17:10.657

@mmumboss: "Remove every 4 characters" is not really grammatical, anyway, but yes, it appears to mean "remove all but every fourth character". – Ilmari Karonen – 2014-03-07T10:23:39.717

4Are the bonuses additive or multiplicative? That is, if my program is 10 chars long and qualifies for both the -15% bonus and the -20% bonus, will its score be 10 * (1 - 0.15 - 0.2) = 6.5 or 10 * (1 - 0.15) * (1 - 0.2) = 6.8? I assumed the latter, but an explicit clarification would be nice. – Ilmari Karonen – 2014-03-07T10:26:57.683

HQ9+ wins this easily. – Ismael Miguel – 2014-03-07T14:02:27.573

@IsmaelMiguel HQ9+ is not Turing complete (or even close), so it gets +750%. Minimum number of letters is 4, so that's 4*750%= 30. Code golf fail. – Kyle Strand – 2014-03-07T19:10:18.383

Still less than most languages can – Ismael Miguel – 2014-03-07T19:58:47.443

I think HQ9+ (Q+++) also qualifies for the 20% bonus... so it scores 24. – Brilliand – 2014-03-07T21:37:29.760

1Wouldn't this be a Mandoline quine, not a Guillotine? Guillotines make one clean, generally fatal, cut and the head rolls away. Mandolines make with the many evenly spaced slices. :) – Jonathan Van Matre – 2014-03-07T21:45:08.990

1@IlmariKaronen I didn't specify, but I consider it to be additive. – Jwosty – 2014-03-08T04:28:05.767

@JonathanVanMatre I like that. I'll go change the title now :) – Jwosty – 2014-03-08T04:29:56.400

Answers

25

PHP, 4 chars − 15% − 20% = 2.72 2.6 points

ABCD

Yes, PHP is a Turing-complete language. Nobody said I have to use any of its actual programming features. ;-)

Edit: Changed the score based on the clarification that bonuses are additive, not multiplicative.

Ilmari Karonen

Posted 2014-03-07T04:37:23.197

Reputation: 19 513

1This is not a proper quine. Still a good answer, though – MilkyWay90 – 2019-04-06T18:21:41.187

This works in ASP, possibly. – Ismael Miguel – 2014-03-07T14:03:33.453

2@n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ I give up. :P – Jwosty – 2014-03-08T04:35:01.233

18Actually, use of PHP's actual programming features is discouraged. – Rhymoid – 2014-03-08T18:21:23.007

14

TI BASIC 4 - 35% = 2.6

I might understand them wrong, but I think I am also eligible for the -15% and the -20% bonusses, meaning I have the lowest possible score.

I can write the program:

123i

which will output 123i where i is of course the imaginary unit. When you remove the 1st and the 3rd character all that remains is 2i which outputs 2i

mmumboss

Posted 2014-03-07T04:37:23.197

Reputation: 570

Not quite... '12i' will output '12i' and '2' will output '2' for a minimum score of 1.95. – intx13 – 2014-03-07T11:33:05.630

Actually, '2i' scores 1.3, and if the empty program is considered a quine, 'i' scores 0.65. – intx13 – 2014-03-07T11:36:24.897

4@intx13: "Answers must be at least 4 characters long." – Ilmari Karonen – 2014-03-07T14:02:55.740

Ah, I missed that! – intx13 – 2014-03-07T18:14:22.937

Beat me to it ;) – Timtech – 2014-03-08T00:40:04.250

13

Python - 95

Great challenge. I thought this was pretty clever, and actually a legit solution!

00;"#";print(open(__file__).read())
0#;XpXrXiXnXtX(XoXpXeXnX(X_X_XfXiXlXeX_X_X)X.XrXeXaXdX(X)X)

qwr

Posted 2014-03-07T04:37:23.197

Reputation: 8 929

Of course a newline is a character... – mbomb007 – 2016-12-13T21:28:31.513

1Nice! Note this technically doesn't work as-is since you end up deleting the newline when making the alternate quine. requires a tad bit of tweaking IOW – Claudiu – 2014-03-07T05:44:38.720

3@Claudiu Well I guess it depends on whether OP considers newline a character. If so, you can just add a newline between each line. 96 chars – qwr – 2014-03-07T05:47:20.217

11

Golfscript, 5 points

{hai}

is a function that, when executed, will run the (non-existing) function hai. It's not executed, however, but rather printed when the program ends - including the outer brackets. Removing each other character yields:

{a}

Lame, I know :-)

John Dvorak

Posted 2014-03-07T04:37:23.197

Reputation: 9 048

@IlmariKaronen Sorry for the very late reply, but it would not, since it would not contain any alphabetic character. – Erik the Outgolfer – 2016-11-25T19:41:03.163

{hai} there! Does one part of the code encode another? If not, then it is not a proper quine by PPCG standards. – MilkyWay90 – 2019-04-06T18:23:42.173

@MilkyWay90 {hai} there! Those rules came way after I answered this question. In fact, I already hadn't remembered having answered this by the time I was fighting against those rules... – John Dvorak – 2019-04-06T18:39:45.883

As to your question proper... I haven't touched quines for several years already, so I don't remember the current definition of proper quines, and I'm not even sure they hadn't changed since I last saw them... – John Dvorak – 2019-04-06T18:41:58.960

@JohnDvorak Okay, thanks for clarifying! – MilkyWay90 – 2019-04-06T20:02:33.427

I believe you qualify for both bonuses, too: your program does not read its own source code, and {} is a quine too. – Ilmari Karonen – 2014-03-07T10:21:10.160

@IlmariKaronen it's hard to tell what counts as reading own source code. Does unevaluating functions count? Does evaluating strings count? As for the other bonus - maybe it's just badly worded, but I read "remove every four characters" as "keep every fifth character", which would leave me with one bracket only (though {ab0} qualifies if 0 can be the one that's kept) – John Dvorak – 2014-03-07T10:40:42.070

It's indeed badly worded, but the example suggests it means "keep every fourth character". Anyway, as you note, {ab0} qualifies either way. – Ilmari Karonen – 2014-03-07T10:44:10.357

It seems {hi} also works, will be shorter (4 chars), and will also qualify for all bonuses. (Seems the script {i evaluates to {i for some reason...) – Claudiu – 2014-03-07T16:59:50.170

@Claudiu {i produces an extra closing curly for me

– John Dvorak – 2014-03-07T19:02:00.030

What about {{}}? – Justin – 2014-03-07T23:20:42.820

8

HQ9+ - 4 * 7.5 * 0.8 = 24 points

Q+++

Still a quine with every second character:

Q+

...and every fifth:

Q

Sorry, I couldn't resist. :)

Smallhacker

Posted 2014-03-07T04:37:23.197

Reputation: 241

7

HTML/Markdown, 4*7.5 = 30

HHHH

I admit this is lame, but it doesn't really go against any rule in the question. Except that HTML/Markdown may not be considered a real programming language.

n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

Posted 2014-03-07T04:37:23.197

Reputation: 5 683

I suppose I didn't specify that programs that can't be split any smaller aren't valid. Revising challenge... – Jwosty – 2014-03-07T05:38:49.700

@Jwosty: then "HHHH" in HTML would win. Note 5555 doesn't work because it has no alphabetic character – Claudiu – 2014-03-07T05:42:02.740

You need an alphabetic character. – qwr – 2014-03-07T05:43:52.590

@qwr: Forgot that when looking at GolfScript. Removed. – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-03-07T05:44:33.347

Hmm... I suppose that this valid :P – Jwosty – 2014-03-07T05:50:41.527

4*7.5 = 30... – Bakuriu – 2014-03-08T09:59:29.157

@Bakuriu: The score is maintained by the participants in this question, not me. – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-03-08T14:05:52.283

5

!/bin/sh

I liked qwr's solution so much, I shamelessly made a port for POSIX shell. Please don't save it into a filename containing spaces.

: '#';cat $0

#c a t   $ 0

Start removing at character number 1, and count newlines as characters. The second quine is of course:

 #;a 0
cat $0

Please upvote qwr's answer instead of this one!

joeytwiddle

Posted 2014-03-07T04:37:23.197

Reputation: 601

3

Bash, 23

Newline is a character!

Some messy comment work, so that when every other character starting from the first is removed, the comment becomes code and the code becomes a comment:

#cRaRtR R$R0R R#
cat $0

After every other character (including the new line) is removed:

cat $0 #ct$

user16402

Posted 2014-03-07T04:37:23.197

Reputation:

it's not a quine if it reads its own source though. – daniero – 2014-04-13T14:58:49.520

@daniero "-15% if the solution does not read its source from anywhere in any form" implies that you are allowed to read the program's source (but you don't get the bonus) – None – 2014-04-13T15:39:52.363

@daniero oh i looked on wikipedia I suppose it is cheating... but it's [tag:code-golf] – None – 2014-04-13T15:44:21.257

I always upvote cats! – Antonio Ragagnin – 2014-04-13T18:29:15.070

2

Brainf**k, 37 - 15% = 31.45

Abusing the Portable Brainfuck Interpreter

+A[B-C<D+E]F-GÿH<I<J<K<L<M<N<O[P.Q>R]

Start removing from the second character.

Timtech

Posted 2014-03-07T04:37:23.197

Reputation: 12 038

When i run this I get B-C<D+E]F-GÿH<I<J<K<L<M<N<O[P.Q>R] as output so it's lacknig some characters. – Sylwester – 2014-03-08T10:57:05.580

Is it Brainfuck, or a particular dialect of Brainfuck that only works on one interpreter? – user253751 – 2014-03-08T10:57:44.063

@immibis It's regular (those capital letters can be spaces or symbols or anything). However, you must use the portable interpreter linked from the answer. – Timtech – 2014-03-08T12:28:09.970

1The first part goes left until it finds the ÿ and the linked interpreter happens to store the code 5000 bytes before the start of the data tape. That's hardly portable Brainfuck. – user253751 – 2014-03-08T12:40:14.600

0

HQ9+T, - 4 * 0.8 = 3.2 points

qqqq

It's a valid quine (ish) and a quine every second and fifth char. I couldn't resist . . . .

Gavriel Feria

Posted 2014-03-07T04:37:23.197

Reputation: 133