6
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ @Mr.Xcoder if there aren't any answers, then you can return falsey or error. \$\endgroup\$ – Nissa Dec 15 '17 at 15:10
  • \$\begingroup\$ Sandbox. \$\endgroup\$ – user202729 Dec 15 '17 at 15:12
  • 3
    \$\begingroup\$ Can 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? \$\endgroup\$ – Mr. Xcoder Dec 15 '17 at 15:13
  • \$\begingroup\$ @Mr.Xcoder and they're formatted. Actually, I'd suggest just replacing the request with STDIN on your TIO links. \$\endgroup\$ – Nissa Dec 15 '17 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.