# All those duplicate questions deserve duplicate code to show them off

All those questions that are duplicates... Ignored and marginalized by society. It is just not... right. We have to do something. There surely must be love for them too.

They feel appreciated if a piece of code outputs a link to a duplicate question. But the duplicate questions are not so easily impressed. They are swept out off their feet only when the code when duplicated outputs a link to another duplicate question. The more the code can be duplicated and still output these links, the more the questions feel more loved.

Your task is to bring love and appreciation to these Stack Exchange pariahs.

Create a piece of code that when duplicated k times outputs a link to a duplicate question. k represents all the numbers in range [1, N].

Edit I made code size matter because I realized you can write a program that can output as many links as you wanted.

# Rules:

Language:

• any language created prior to the post of this challenge is accepted. You may use a language already used in another answer.
• you may not use external resources (a database etc.)
• any encoding and any characters are allowed (including white spaces, new lines, non-ASCII). Encoding is UTF-8.
• code size does not matter. Size is measured in bytes.
• all duplications must be in the same language

Code duplication:

• clarification: the code must not duplicate itself. Simply put duplicating here means creating another code by copy-pasting the original one at the end of the last one obtained. Each will result in a new code that is run independently from the others.
• all the characters in the original code must be copy-pasted (including trailing new line (if any)). Each time the code pasted must be appended at the end.
• the code must create valid output when duplicated 1 (no duplication), 2, 3, 4, 5... N times.
• It cannot skip a number (e.g. a code that creates valid output only when duplicated 1, 2, 3, 5, 6 times will be considered only for 1, 2, 3 so N = 3)
• each time exactly one link must be output-ed.
• example (for what duplication means, not for valid output)

(python3) Original code (k = 1):

try:
i
except NameError:
i = 100
else:
i = 200

if i == 100:
print("stackoverflow.com/questions/" + str(i),end="")
else:
print(i)


k = 1 outputs stackoverflow.com/questions/100
k = 2 outputs stackoverflow.com/questions/100200
k = 3 outputs stackoverflow.com/questions/100200200

• Non-deleted questions from Programming Puzzles & Code Golf and Stack Overflow that were closed as duplicate prior to the time of the posting of this post are considered for this challenge.
• Helpful query to search for duplicate questions:

is:question duplicate:yes

A valid link output for this question is any of these the two base links

stackoverflow.com/questions/1066589
stackoverflow.com/q/1066589
^~~~~~^
this is referred as the link number in following paragraphs


to which you may add the prefix(es) www. and/or http://. You may also add a trailing /

Please note that after that you must not add anything (like the question title), even if that link results in a redirect to the question.

• You may not use a URL shortner service.
• You may not link to an answer or to another part of the page.
• The questions don't have to be duplicates of the same original or related in any way (don't have to means they can be if you want).
• For each time (for each k) a different question must be linked (two different links to the same question count as the same question)

Multiple Submissions

• You may post multiple answers with the same or different languages. Different posts can output the same link.

# Scoring

• Each link gives 1 point.
• Egoistic bonus: +0.5 points for each link to your own question.
• Forgive me bonus: +0.5 point for each link to a question you voted to close (for whatever reason).
• Judge Jury Executioner bonus: +0.5 point for each link to your own question that you yourself voted to close (for whatever reason).
• now what bonus: +0.5 points for each link to a question closed as a duplicate to a question that has no answers.
• train of thought bonus: +1 point for each link to a question closed as a duplicate to another duplicate question (regardless of the length of the train)
• dead end bonus: +1 point for each link to a question closed as a duplicate of a question that was closed for a reason other than duplicate. (locked questions that exists because they have historical significance also don't count for this bonus).
• George Santayana bonus: +1 point for each link closed as a duplicate of a question by the same user.
• You can't live without me bonus: +1.5 points for each link whose number is prime.
• Queen of the prom bonus: +2 points for a link to a question of a user with all the questions (on the site of the linked question: PPCG or SO) closed as duplicates (at least 3, including the linked one). This bonus cannot be awarded more than once per user (even if you link to all 3 questions of this user, you are awarded the bonus only once, but you can be awarded this bonus again for a link to a question of another user or the same user but on the other site).
• All bonuses are cumulative. (this for instance has the effect that the Judge Jury Executioner bonus will always come with the egoistic and forgive me bonuses).
• You don't love me enough penalty:
• not_enough_penalty = 0.6 for N = 2 (just 2 links)
• not_enough_penalty = 0.8 for N = 3 (just 3 links)
• not_enough_penalty = 1 for N >= 4 (4 or more links)

# Winning Criteria:

• LinkPoints = 1 + bonuses for each link
• Points = Sum(LinkPoints) * not_enough_penalty
• Score = 5 * Points + Votes
• Size = number of bytes of original code (k = 1).
• Score = (256-Size) / 32 * Points + Votes
Score is rounded to two decimals.

• The winner is the answer with the highest score. In the case of a tie the answer with the most votes wins.

• The winner will be awarded two weeks from the posting time of this question. If this question has intense activity at that time I will extend this.

# Post format

• Please specify the language, N - the number of duplication achieved, CodeSize and Points.
• Post the original piece of code.
• For each k in [1..N] post the link output-ed, the bonuses awarded and LinkPoints.
• Please add description where the way the code works is not obvious (for each k if needed) or if the language is not well-known.
• Express the formulas for Points and Score (without Votes, as they will be considered at the end of the challenge).
• I made this a code-golf because I realized you could write a program with a switch that could output as many duplicates as you wanted. Since there were no answers I felt I could edit the question. – bolov Jan 20 '15 at 7:05
• I've removed the code golf tag, since that is intended for pure code size scoring. code challenge is right for this challenge. Also, why the need to specify encoding as UTF-8? In some cases that seems a bit punishing (in particular APL, which uses it's single-byte code page, but whose characters are well away from the ASCII range because it's older than ASCII). – Martin Ender Jan 20 '15 at 9:04
• @MartinBüttner golf tag: ok thanks. UTF-8 I didn't know that. I was trying to take measures against cheating (don't know how you can cheat with the encoding, but you guys are very creative :p). I removed this restriction. – bolov Jan 20 '15 at 9:48
• To me, this sounds like users could create duplicate questions, then close them, solely for this challenge. – mbomb007 Jan 20 '15 at 20:24
• @mbomb007 Non-deleted questions from Programming Puzzles & Code Golf and Stack Overflow that were closed as duplicate prior to the time of the posting of this post are considered for this challenge. That's why I posted this rule from the beginning. – bolov Jan 20 '15 at 22:03

# C++, 212 bytes, 6 links, 10.31 points

#ifndef X
#define Y(N)s##N
#define X(N)Y(N)
#include<cstdio>
int i,j,k[]={2366,117,3818,3450,1047,2933},main;struct S{~S(){j+=k[i++];}};struct G{~G(){printf("stackoverflow.com/q/%d",j);}}g;
#endif
S X(__LINE__);


This code relies on the order of destructor to make it work (which seems to be well defined in this case), mainly because the preprocessor allows us to put a "prologue code" before the duplications, but not "epilogue code" because we don't know where does it end. But destructors run in reverse order, so we could put the final code (the print part) at the start as well.

The k array records the differences of successive link numbers. For now I just take links from the oldest pages. "6 links" seems to give the maximum score.

Total score: (256 - 212)/32 × 7.5 = 10.31

• Which compiler are you using? I think main runs before the destructors, and it will crash... – jimmy23013 Jan 20 '15 at 18:53
• @user23013: Works fine on the default clang on Mac OS X. – kennytm Jan 20 '15 at 19:16
• @bolov: Thanks, amended score. – kennytm Jan 20 '15 at 19:18

# Tcl, 155 bytes, 15 links, 55.23 points

[proc f args {puts stackoverflow.com/q/[lindex {2366 2483 6301 9751 10798 13731 14599 16064 16233 16550 16704 18584 20146 22708 25376} [llength \$args]]}]f


There is a trailing space.

Score = (256 - 155) / 32 * 17.5 = 55.23

The score can probably be improved by using another set of questions with more bonuses.

## JavaScript (NodeJS) - 236 characters, including trailing newline

l=root.l||1;f=require('fs');t=(f.readFileSync(__filename)+'').split('\n');d="ge3oe gk05n gj341 gg8ah gfnar ga9i3 g602y g5mwi g2b9i fu75d g4lu0 4v1".split(' ');if(++l==t.length)console.log('https://stackoverflow.com/q/'+parseInt(d[l-2],36))


It uses a hardcoded list of question IDs, encoded in base 36. It reads its own source code, and only prints if it's on the last line of the file.

It results in a total of 12 questions, most closed by me:

Score: 11.25

• Doesn't this output all the links rather than only one? – feersum Jan 20 '15 at 13:10
• No; only one at a time. Test it! – Scimonster Jan 20 '15 at 13:10
• I did...and multiple links were printed. Are you claiming that if I paste this 4 times, it will somehow print only one link? – feersum Jan 20 '15 at 13:17
• Oh, now i see. Deleting while i fix. – Scimonster Jan 20 '15 at 13:18
• Works now, though it cost me plenty of points, mainly due to an increased filesize. – Scimonster Jan 20 '15 at 20:09

## STATA - 252 characters (including trailing newline) N = the number of duplicates on stackoverflow.com

Ignore the trailing space. I didn't know how to adjust this properly. Someone help me format this reasonably.

First this code tries to increment a counter variable. If that fails, it generates a new local variable and sets it equal to 2. Then it decrements it and creates a new variable to keep track of whether or not the page has the phrase " as duplicate by <a" in it. Until a line contains that phrase, the following is run:

Create a local variable to hold the url (using the counter as the question number). Copy the file to the local file a and replace it. Filter a (and move to b the result) by replacing ">" with ">\n" and replace b if necessary. Then read in b, clearing current data (i.e. dropping the d variable) with a string variable representing each line. If the phrase appears in any line, d becomes at least 1, thus ending the loop.

The last line displays the url and continues onto the next line because of the /// comment.

Thus, when k>1, the last line of the first part becomes

cap diu' /// cap loc \c'++ 

which is equivalent to:

cap diu' cap loc \c'++ 

which would throw a syntax error if the capture (cap) command were not used to capture the return code and prevent execution of the line, thus not printing the url unless it is the last of the k copies of the code.

cap loc \c'++
if _rc>0{
loc c=2
}
loc \c'--
g d=0
while d<1{
loc u="http://stackoverflow.com/q/\c'"
copy \u' "a",replace
filef "a""b",f(>)t(>\n)r
infix str l 1-9999 using "b",clear
egen d=max(strpos(l," as duplicate by <a"))
loc \c'++
}
cap di\u' ///


Possible better approach (explanation coming soon):

cap so d
if _rc>0{
loc c=9761
}
loc f="http://stackoverflow.com/"
loc u="f'search?page=c'&tab=newest&q=duplicate%3ayes"
infix str l 1-9999 using u',clear
g d="f'q/"+regexs(1) if regexm(l,f="/questions([0-9]+)")
loc c'--
cap l d in 1

• To format code, please indent them by 4 spaces, or click the {} button on the toolbar. – kennytm Jan 21 '15 at 7:03