Write code to determine the accepted answer

14

2

Post an answer to this question that evaluates any answer to this question and determines whether it wins.

Who wins:

  • Winner is the answer that wins according to the most answers at 1700 UTC, Sunday, March 2nd.
  • You are welcome to and encouraged to change your own answer as the contest progresses. Please do not change others'.
  • Ties are determined by the shortest code.
  • Regardless of how much sockpuppeting you might normally do, if something's fishy, I'm gonna disqualify you.
  • I will not accept my own answer, but I will use it to evaluate yours.

Rules:

  • Your calculation must provide a numeric score for any arbitrary answer (to make it easy, the input to your algorithm is either the id of the answer or the markdown of the answer on the page).
  • Your score must have at least one winner, and it must be possible for an answer besides yours to win.
  • Your algorithm cannot use something very specific to your answer, nor can username or timestamps be used at all. I will be the final judge of what "very specific" means, but I encourage community policing and public shaming.
  • Your code must compile, run, and give a score given any answer.
  • Please include a link to a way to execute your code if it is not listed on Ideone. See below.

Ideone languages

Not that Charles

Posted 2014-02-12T04:00:35.667

Reputation: 1 905

1Any special reason for the "Please only contribute one answer" restriction? If I develop two very different algorithms with two very different criteria, can't I post both? – Victor Stafusa – 2014-02-12T05:47:10.173

@Victor I guess you're right. I can ease up on that rule, but I will shut folks down for stacking the deck. – Not that Charles – 2014-02-12T06:11:34.537

Should the winner correctly determine that it is itself the winner? I.E, if answers A, B and C says that D is the winner, but D says that A is the winner, is D the winner even if it is a wrong answer? – Victor Stafusa – 2014-02-12T06:23:26.417

@Victor The winner doesn't have to be correct. That would be way too hard. – Not that Charles – 2014-02-12T06:44:04.867

Since when does Ideone allow network access? – nyuszika7h – 2014-02-19T14:09:30.340

Answers

6

R, 1 char

1

You can supply the id of an answer as a command line argument if you wish. :) Link to ideone.

Further elaboration

Since it is not practical for an answers to execute other answers (different languages, etc.) and evaluate them based on their result the only remaining way I can see for them to give a score is to use some code metric.

I have noticed that all other answers so far give a higher score to shorter programs. I believe this is the shortest code possible so it should rank high in the result of other answers.

How and what answer my code gives for other answers seams to be less relevant. The only important aspect is that others rank my answer high.

Andris

Posted 2014-02-12T04:00:35.667

Reputation: 406

LOL -- Very clever! I like it. – jvriesem – 2015-09-11T01:31:20.513

What? How does this even make sense? – cat – 2016-04-07T16:02:17.707

Please elaborate. – rahulroy9202 – 2014-02-19T03:49:42.953

1@rahulroy9202 Updated answer with my reasoning. – Andris – 2014-02-19T12:13:55.243

2:D good point. Your assumptions are logical. Unless someone figures out a way to print 1 with no code at all. :D – rahulroy9202 – 2014-02-19T12:18:36.807

@rahulroy9202 I think it is not possible to post a blank code block so even if this is possible in a language you could not post the "code" here. :D – Andris – 2014-02-19T12:27:10.273

try <code></code> inside answer and my code will read it as 0 char answer. :D – rahulroy9202 – 2014-02-19T12:28:57.003

@Andris <pre></pre> – Timtech – 2014-02-19T15:42:29.543

3

R, 1 char

0

Following up on @Andris's answer, there are now two codes that have a single character: Andris's and mine. Since we tie in the eyes of the other answers, neither of us have "won" outright, so my answer won't "win". :-)

jvriesem

Posted 2014-02-12T04:00:35.667

Reputation: 291

2

Ruby, 368 char

require 'json'
require 'open-uri'
v='body';w="#{v}_markdown";s='comments'
x=if(d=JSON.parse(open("http://api.stackexchange.com/2.2/answers/#{ARGV[0]}?site=codegolf&filter=!%29r%28UkmOhmCPjXru-TDty").read)['items'][0]).include?(s) then d[s].map{|c|c[w].length*[1,c[w].index('`')||1,c[w].index('\n')||1].max}.reduce(:+) else -2 end
puts d['score']*150+5*(d[v].match(/<(..).*?\1.*?\1/m))[0].ord+x-$~.end(0)

Good luck!

Not that Charles

Posted 2014-02-12T04:00:35.667

Reputation: 1 905

2

JavaScript- 190 char

Assumption: The first code block is the answer.

var ans=$('.answer'),s=999,sa;
for(i=0;i<ans.length;i++){
    var x =  ans[i].getElementsByTagName('code');   
    var z = x[0].innerHTML.replace(/\s/g,'').length;
    if(s>z){
        s=z;
        sa=ans[i];
        }    
}
console.log(sa);

Can be tested in browser console. It assumes the shortest answer to be the correct answer.

How to execute- On Chrome/Firefox open console while on this page and paste code and execute.

rahulroy9202

Posted 2014-02-12T04:00:35.667

Reputation: 315

It also works in the IE 11 console :) – ComFreek – 2014-02-19T14:04:10.503