14
\$\begingroup\$

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

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Any 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? \$\endgroup\$ Feb 12, 2014 at 5:47
  • \$\begingroup\$ @Victor I guess you're right. I can ease up on that rule, but I will shut folks down for stacking the deck. \$\endgroup\$ Feb 12, 2014 at 6:11
  • \$\begingroup\$ 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? \$\endgroup\$ Feb 12, 2014 at 6:23
  • \$\begingroup\$ @Victor The winner doesn't have to be correct. That would be way too hard. \$\endgroup\$ Feb 12, 2014 at 6:44
  • \$\begingroup\$ Since when does Ideone allow network access? \$\endgroup\$ Feb 19, 2014 at 14:09

4 Answers 4

6
\$\begingroup\$

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.

\$\endgroup\$
8
  • \$\begingroup\$ Please elaborate. \$\endgroup\$ Feb 19, 2014 at 3:49
  • 1
    \$\begingroup\$ @rahulroy9202 Updated answer with my reasoning. \$\endgroup\$
    – Andris
    Feb 19, 2014 at 12:13
  • 2
    \$\begingroup\$ :D good point. Your assumptions are logical. Unless someone figures out a way to print 1 with no code at all. :D \$\endgroup\$ Feb 19, 2014 at 12:18
  • \$\begingroup\$ @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 \$\endgroup\$
    – Andris
    Feb 19, 2014 at 12:27
  • \$\begingroup\$ try <code></code> inside answer and my code will read it as 0 char answer. :D \$\endgroup\$ Feb 19, 2014 at 12:28
3
\$\begingroup\$

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". :-)

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ It also works in the IE 11 console :) \$\endgroup\$
    – ComFreek
    Feb 19, 2014 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.