Declare a Code Golf Winner

6

Normally, I'd open with some flavor text here about being bored and/or lazy but looking through the questions that would be far from original. So instead I'm going to open with a meta and self-referential flavor text describing this lack of originality that then describes itself and how meta and self-referential it is.

Challenge

Write a program that takes in the ID for some question on PPCG, and uses the SE API to grab the answers and select the winner.

You may assume that it is a question, and the following answer format:

# Language, [<s>XXX</s>] YYY bytes

[Thanks to @user1 for saving XX bytes!]
[Thanks to @user2 for saving YY bytes!]

print "badly formatted but easier to tally like this"

To clarify:

  • It might have 1 or more attributions or crossed out past scores, and it might not.
  • The attributions and crossed-out scores are not necessarily correlated; one can appear without the other.
  • If there are no attributions, then the code will start 2 newlines after the heading.

Anyway, you can either extract the length in the beginning or count the length of the code at the end. For the former, only use the last score. For the latter, don't count the attributions. You can assume that the two will match up.

Your program should spit out the ID for the answer with the fewest bytes. Your program should also do this in the fewest bytes possible, as the shortest answer in bytes will win.

Note: yes, I have seen Write code to determine the accepted answer, but that challenge has submissions voting on the winner whereas this is code golf with a specific task and an explicit winner independent of other answers.

Nissa

Posted 2017-12-15T14:36:01.180

Reputation: 3 334

@Mr.Xcoder if there aren't any answers, then you can return falsey or error. – Nissa – 2017-12-15T15:10:34.993

Sandbox. – user202729 – 2017-12-15T15:12:22.810

3Can you please add some test cases (as pointed out in the sandbox, a comment you might have chosen to ignore) --- Might be somewhat hard, because nearly no answers use that format, given that Try it online! or Explanation... are usually among the last lines? – Mr. Xcoder – 2017-12-15T15:13:28.823

@Mr.Xcoder and they're formatted. Actually, I'd suggest just replacing the request with STDIN on your TIO links. – Nissa – 2017-12-15T15:21:13.690

No answers