PPCG's Unanswered Questions

9

This dear StackExchange site has so many challenges, and so many good answers. But what about the challenges that were never answered?

Task

Write a program or a function that will print a pseudo-random open unanswered (as in, a question with exactly zero answers) challenge from PPCG. All possible challenges should be produced with the same probability.

Input

  • No input will be taken.

Output

  • Must only be the title, tags and the link which should be separated by newlines.
    • The title must be exactly like it is in the challenge.
    • The tags don't have a strict output format but must include all tags.
    • The link may or may not include the question-name after the question id and must lead to the challenge.
  • May or may not be translated to a human readable format.
    • & to &
  • Leading and trailing whitespace is allowed.

Examples

Encode a steganographic encoder into a package
code-challenge,unicode,steganography
https://codegolf.stackexchange.com/questions/65159/encode-a-steganographic-encoder-into-a-package

Simple predictive keyboard CG
code-golf
https://codegolf.stackexchange.com/questions/76196/simple-predictive-keyboard-cg

Scoring

As this is , shortest answer in bytes wins.

totallyhuman

Posted 2017-05-11T21:19:21.280

Reputation: 15 378

8I'm getting really sick of [tag:stack-exchange-api] challenges. – Rɪᴋᴇʀ – 2017-05-11T21:27:03.923

3@Riker Uhm... thanks for your feedback? I really don't know why you would downvote for that reason but more power to you, I guess. – totallyhuman – 2017-05-11T21:28:07.300

6I didn't downvote for that. I downvoted because I think the question is boring. Also, would closed questions need to have the equal probability of being outputted? – Rɪᴋᴇʀ – 2017-05-11T21:29:30.507

Thank you for expressing concerns with the question even after disliking it. – totallyhuman – 2017-05-11T21:33:42.843

1

While I don't feel as strongly about it as @Riker, there does seem to have be a lot of API-related challenges lately; so much so that I managed to get myself blocked from using the API for ~21 hours!

– Shaggy – 2017-05-11T22:09:13.573

I will admit I got this idea after seeing the sudden influx of API questions. – totallyhuman – 2017-05-11T22:10:05.763

At this rate, we'll have to ask SE for an unthrottled "sanbox" API to work with on all these challenges! :D – Shaggy – 2017-05-11T22:31:33.440

4Interestingly enough, this challenge will show up during testing, but once I answer it, it won't show up in testing anymore. – HyperNeutrino – 2017-05-11T22:45:59.283

I suggest, to avoid hammering the API with multiple requests and having people hit the throttle trying to retrieve all unanswered that you add a minimum number of answers that we should work with that can be retrieved with a single API request, i.e. <=100. – Shaggy – 2017-05-12T09:19:17.433

I also suggest that translating the output to "human readable format" be removed from the question as it adds an unnecessary (in my opinion) extra complication to the challenge that not all languages will be able to handle while remaining competitive. I think there's a post on Meta that covers this, I'll see if I can dig it out. – Shaggy – 2017-05-12T09:22:09.000

1Note your example list is now wrong as the Tetris challenge has been answered :D – Blue – 2017-09-15T08:52:42.947

Answers

7

JavaScript + HTML, 271 250 232 bytes

Apparantly you can use Dates as pseudo-random numbers. I stole this from Shaggy's answer.

(Only uses about 4 of your quota)

q=[]
g=f=>fetch('//api.stackexchange.com/questions/unanswered?site=codegolf&page='+f).then(r=>r.json().then(j=>(q=[...q,...j.items])^j.has_more?g(f+1):document.write(`<pre>${(q=q[new Date%q.length]).title}
${q.tags}
`+q.link)))
g(1)

It makes an array q, then calls g(1), which fetches the first page of results and adds it to q. Then, if the request says it has_more, then it calls g(f+1), which fetches the next page, until it reaches the end and writes out to the HTML document (Which will automatically unescape the response)

If we don't care about all of the unanswered questions, just the most recent 30 (Only uses 1 of your quota):

JavaScript + HTML, 213 196 179 bytes

fetch`//api.stackexchange.com/questions/unanswered?site=codegolf`.then(r=>r.json().then(j=>document.write(`<pre>${(j=j.items[new Date%j.items.length]).title}
${j.tags}
`+j.link)))

Artyer

Posted 2017-05-11T21:19:21.280

Reputation: 1 697

Sorry, @Artyer, I was so focused on working on my own answer, I never spotted that you'd beaten me to the punch by a few minutes. I'm happy to delete my answer, if you feel it's to similar to yours. – Shaggy – 2017-05-12T09:17:02.773

@Shaggy It's alright. I also wrote the second answer at the same time as you wrote your answer, so it's a happy coincidence that they ended up similar. – Artyer – 2017-05-12T09:18:53.207

You could save a few byes by hardcoding in the number of pages that need to be fetched. Instead of j.has_more?g(f+1), try ++f<5?g(f) – Shaggy – 2017-05-12T10:38:15.893

You could also replace q=q.concat(j.items) with q=[...q,...j.items]. It looks like Tags: is optional, so you can drop that too. And no need to join q.tags, it will be coerced into a string when being concatenated to a string. Finally, using a template literal for the final should save you a few bytes, too. – Shaggy – 2017-05-12T10:45:57.907

@Shaggy Unfortunately, I've met my quota. It resets in 425 seconds though. – Artyer – 2017-05-12T10:53:56.830

After further consideration, I've decided to delete my answer. Your paging solution is now almost identical to the one I was working before I decided to ditch the paging in order to save multiple requests to the API. – Shaggy – 2017-05-12T14:58:19.350

TIP: To avoid being booted from the API when testing, grab a sample set of data and use it as I did in the second Snippet here – Shaggy – 2017-05-12T15:04:38.873

Your code also returns answered questions: https://codegolf.stackexchange.com/questions/143220/simple-complexity was returned and that question has two answers.

– Michthan – 2017-09-20T06:36:17.020

6

Python + requests + json + random + html, 249 239 bytes

import requests as r,json,random as R,html
j=R.choice(json.loads(r.get('http://api.stackexchange.com/questions/no-answers?site=codegolf').text)['items'])
print('\n'.join([html.unescape(j['title']),'Tags: '+', '.join(j['tags']),j['link']]))

Turned out longer than I'd like.

-10 bytes thanks to @totallyhuman by using R.choice rather than R.shuffle and taking the first element.

HyperNeutrino

Posted 2017-05-11T21:19:21.280

Reputation: 26 575

Can you save a few bytes by using random.shuffle? – totallyhuman – 2017-05-12T01:00:30.873

...Wait, or even better, random.choice()? – totallyhuman – 2017-05-12T01:25:26.017

1@totallyhuman Changing the inpurt name happens to actually make no difference in bytecount :P But thanks for .choice()! – HyperNeutrino – 2017-05-12T01:33:37.883

You don't need the json library, use r.get(url).json() instead – ovs – 2017-05-12T05:40:32.170

This doesn't account for has_more. It only randomly chooses from the first 30. – Artyer – 2017-05-12T08:40:45.093

0

Bash 255 232 bytes

a="api.stackexchange.com/questions/";b="?site=codegolf";c=$(w3m $a"unanswered"$b"&filter=total"|tr -cd 0-9);w3m $a"no-answers"$b"&pagesize=1&page="$((RANDOM%c))|jq -r ".items[0]|.title,(.tags|join(\", \")),.link"|recode html..utf-8

Looks like a wrong results returns for totals for no-answers/unanswered. General idea - get total, than get random page with one item.

Bash 174 153 bytes

w3m api.stackexchange.com/questions/no-answers?site=codegolf|jq -r ".items[$RANDOM%(.items|length)]|.title,(.tags|join(\", \")),.link"|recode html..utf-8

It select one random question from last 30, not from all questions. Works from command line. Required curl w3m, jq and recode.

result:

Tips for golfing in Charcoal
code-golf, tips
https://codegolf.stackexchange.com/questions/117269/tips-for-golfing-in-charcoal

user1516873

Posted 2017-05-11T21:19:21.280

Reputation: 101

I'm pretty sure you need to choose from all of them. But welcome to PPCG anyway! – NoOneIsHere – 2017-05-12T17:09:35.223