Am I outgolfed by Dennis?



According to legend, almost everyone is outgolfed by Dennis. If not, they will be.

Now I'm curious if I'm one of those 'almost everyone'.

You will be given a link to an answer in the format of[QUESTION ID]/[QUESTION NAME]/#[ANSWER ID].

Find the length of the code, which we will assume as the last number on the first line (markdown wise) of the answer in the link.

Then, search for Dennis' answers, and do the same.

Now compare the input's and Dennis' answers code length, and if it is out-golfed (meaning one or more answer of Dennis' is shorter than that of the input answer), output a truthy value, and if not, a falsy value.

If there is no answer belonging to Dennis on the same question as the answer, output a falsy value.


  • Link : true
  • Link : false (At least for now, tell me when it changes)


  • You may use any form of truthy/falsy value.
  • The question of the answer you're given will always be .
  • The question may not have an answer of Dennis', but the inputted answer will never belong to Dennis.

  • You may assume there is always a number on the first line of the answer.

Matthew Roh

Posted 2017-05-10T10:39:55.847

Reputation: 5 043

3Can we assume there will always be an answer by Dennis on the given question, and that the given answer will not be Dennis' answer? – Skidsdev – 2017-05-10T10:42:08.413

@Mayube No, and yes. – Matthew Roh – 2017-05-10T10:42:34.940

Do we need to handle paging or can we assume both answers will be on the same page if there are multiple pages of answers? – Shaggy – 2017-05-10T10:42:45.510

@Shaggy former. – Matthew Roh – 2017-05-10T10:43:06.450

@SIGSEGV If there is no answer by Dennis do we output false because Dennis has not outgolfed the answer? – Skidsdev – 2017-05-10T10:43:43.693

@Mayube Yes.... – Matthew Roh – 2017-05-10T10:44:27.500



Python 3.6 + requests + bs4 - 363 358 bytes

import bs4,re,requests
while i:
 for a in A:
  if "Dennis"in a(class_="user-details")[-1].text:d=min(c,d)
  if a["data-answerid"]==n:y=c
 i=A and i+1;

Prints True or False.

Note: does not currently work on the second link because of invalid HTML produced by this answer (the em and strong tags are terminated in the wrong order at the end of the second line, and causes the parser to miss the username block). Try it on this link instead.

Using the API - 401 380 bytes

import requests,re
while i:
 r=requests.get(f"{q}/answers?site=codegolf&filter=withbody&page={i}").json();i=r["has_more"]and i+1
 for a in r["items"]:
  if a["owner"]["user_id"]==12012:d=min(d,c)
  if a["answer_id"]==A:y=c

Note that this also fails on the second link, but because one answer started with This may be foul play. instead of the header...


Posted 2017-05-10T10:39:55.847

Reputation: 1 319

Consider using the Stack Exchange API to get answer data instead via JSON parser, just make sure filter=withbody is in your GET request in order to obtain the answer body to grab the byte count

– Value Ink – 2017-05-10T19:57:30.747

With the API version, you used a twice (once to set the answer ID, and another when iterating r["items"], which would lead to incorrect behavior. Also, you don't need to set the pagesize (it will default to 30). c=int('(\d+) bytes').group(1)) should give you a more accurate retrieval of bytecount and is shorter, and if it still fails, (\d+)\s*bytes does the trick but is a bit longer. Finally, i=r["has_more"]and i+1 is shorter than your ternary conditional. – Value Ink – 2017-05-10T21:23:24.017

Actually, forget about the regex match. I forgot to account for adding the answer body in the function call so that part is longer. The other suggestions are still valid, though. – Value Ink – 2017-05-11T01:19:13.407

@ValueInk Thanks, bit shorter now. Looks like we need a golfing language just for the API, its calls are sooo long... – matsjoyce – 2017-05-11T07:28:56.130

Perhaps. But honestly there's also the fact that you have a nice HTML parser, plus the fact that you're given the question URL by default. If the input were two numbers instead, there would be quite a bit of overhead for getting the page for the codegolf question as well. – Value Ink – 2017-05-11T19:58:05.973

True, but it turns into parsing SE's HTML oddities vs long but safe(r) API calls. Its amusing that both fail on the same link though... – matsjoyce – 2017-05-12T08:55:11.693


Ruby, 314 315 308+20 = 334 335 328 bytes

Uses the flags -n -rjson -ropen-uri. +1 byte from fixing a minor bug.

-7 bytes by discovering the open-uri Ruby default library.

j=r!=[]&&j+1)while j

Value Ink

Posted 2017-05-10T10:39:55.847

Reputation: 10 608