This question is inspired by the fact that I love seeing questions with equal vote and answer counts...

So here's a simple challenge for y'all:

Challenge:

Given a codegolf.stackexchange question id, output the ratio between the question's votes and number of answers (e.g. votes/answers).

Specifics:

• You may access the internet, but you may only access stackexchange.com and its various sub-domains. You may not use URL shorteners.

• You may take input and give output in any standard format.

• You must output the ratio as a decimal number in base 10, with at least 4 {accurate} digits after the decimal (zeros may be truncated).

• If the question is unanswered, your program may produce undefined behavior.

• You should use the score of the question as the vote-count, see here.

This is , least bytes in each language wins for that language, least bytes overall wins overall.

Here is a sample program in Python 3 + requests:

import requests
import json

id = input("id> ")
url = "https://api.stackexchange.com/2.2/questions/" + id + "?site=codegolf"
content = requests.get(url).text


• Does the ratio need at least 4 decimal digits after the decinal point even if they are zero? E.g. 41/4= 10.25 or 10.2500 – pizzapants184 Sep 18 '17 at 15:19
• @pizzapants184 10.25 is fine – Socratic Phoenix Sep 18 '17 at 15:21
• What if the challenge is not answered? Then the ratio would be infinite? – Mr. Xcoder Sep 18 '17 at 15:37
• Do you mean score or total votes on the question? – AdmBorkBork Sep 18 '17 at 15:37
• @Mr.Xcoder in that case, undefined behavior is okay – Socratic Phoenix Sep 18 '17 at 15:37

# JavaScript (ES6), 103 102 bytes

Needs to be run from the root level of api.stackexchange.com. Returns a Promise object containing the result.

n=>fetch(questions/${n}?site=codegolf).then(r=>r.json()).then(({items:[j]})=>j.score/j.answer_count)  If requiring that it be run from a specific path is allowed then that becomes 92 90 bytes. n=>fetch(n+?site=codegolf).then(r=>r.json()).then(({items:[j]})=>j.score/j.answer_count)  ## Try it Full URL added to enable it to work here. f= n=>fetch(//api.stackexchange.com/questions/${n}?site=codegolf).then(r=>r.json()).then(({items:[j]})=>j.score/j.answer_count)
onchange=_=>f(+i.value).then(t=>o.innerText=t)
<input id=i type=number><pre id=o>

• Replace i=>(j=i.items) with ({items:[j]})=>j to save a byte. – kamoroso94 Sep 18 '17 at 20:14
• Nice trick, thanks, @kamoroso94. I'll have to remember that one. – Shaggy Sep 18 '17 at 22:25

# Stratos, 40 bytes

-4 bytes thanks to Shaggy

f"¹⁵s/%²"r"⁷s"@0
⁰s"score"/


Try it!

Stratos specialises in questions.

Explanation:

The code decompresses to the following:

f"api.stackexchange.com/questions/%?site=codegolf"r"items"@0
⁰s"score"/


Starting from the first line, Stratos evaluates the dyads from right to left.

f"api.stackexchange.com/questions/%?site=codegolf"r"items"@0 means "evaluate the dyad @ with the left-hand argument f"api.stackexchange.com/questions/%?site=codegolf"r"items" and the right-hand argument 0. @ gets the nth element of a JSON array.

To evaluate f"api.stackexchange.com/questions/%?site=codegolf"r"items", we will next evaluate the dyad r with the left-hand argument f"api.stackexchange.com/questions/%?site=codegolf" and the right-hand argument "items". r gets the JSON array with the specified name.

Next, we will need to evaluate f"api.stackexchange.com/questions/%?site=codegolf". First, % is replaced with the input. f means "get the contents of this URL".

Now, we can move on to the second line. The newline means "add what we evaluated to the implicit argument list"

Next, we evaluate s (get string in JSON object with a certain name) with { and "answer_count". { takes an element from the implicit argument stack, returns it, and adds it back to the stack.

Then, we add the output of that to the implicit argument stack.

To evaluate ⁰s"score"/, we are applying the dyad / (divide) to ⁰s"score" and an element from the implicit argument stack.

To evaluate ⁰s"score" we are getting the string "score" from the JSON object from the 0th element in the implict argument stack.

Now, the output of / is printed and the program terminates.

• Save 4 bytes by ditching the API version (2.2/). – Shaggy Sep 18 '17 at 17:14
• @Shaggy Didn't realise the API version wasn't required, thanks. Not crossing out 44 :P – Okx Sep 18 '17 at 17:18

function(n,x=jsonlite::fromJSON(sprintf('http://api.stackexchange.com/questions/%s?site=codegolf',n))$i)x$s/x$a  R-fiddle link jsonlite is a nice JSON <-> R conversion library which works quite well. I wasn't about to golf a JSON parser for R... • You can save a byte by using the http protocol. Also, I'm guessing 142729 shouldn't be hardcoded in there? – Shaggy Sep 18 '17 at 15:50 • @Shaggy good call, thank you. I copied and pasted too fast. – Giuseppe Sep 18 '17 at 15:53 # T-SQL, 64 54 bytes It is rare that SQL can beat (most) other languages! Instead of the API URL I went directly to the Stack Exchange Data Explorer: SELECT 1.0*Score/AnswerCount FROM Posts WHERE Id=##i##  The ##i## isn't standard SQL, that's Stack Exchange's format to prompt for input. Note that the data explorer source is only updated nightly, so values aren't current. Will throw a divide by zero error on questions with no answers. Edit: Saved 10 bytes by multiplying by 1.0 instead of an explicit CONVERT to FLOAT. • can beat others, but not all :) – Okx Sep 18 '17 at 19:58 • Oh maaan, I had another solution but I was in school so I never ended up posting it... Is my answer too similar to yours? Should I delete mine? – totallyhuman Sep 18 '17 at 20:05 • @icrieverytim Ha, yep looks like pretty much the same query, although I just edited mine to save 10 more bytes. – BradC Sep 18 '17 at 20:11 • @BradC I edited my answer into a Mathematica answer lol. – totallyhuman Sep 18 '17 at 20:50 # PowerShell, 130 bytes ($a=(ConvertFrom-Json(iwr("http://api.stackexchange.com/questions/"+$args+"?site=codegolf")).content).items).score/$a.answer_count


Performs an Invoke-WebRequest against the URL, gets the .content thereof, does a ConvertFrom-Json of that content, and gets the .items of that JSON object. Stores that into $a and pulls out the .score as the numerator. The denominator is the .answer_count. That value is left on the pipeline and output is implicit. If the question is unanswered, this should toss a "Divide by zero" error. # Japt, 83 82 bytes Wanted to give this a try to see how it would work out, seeing as Japt can't natively accomplish it. Essentially all this is doing is evaling a compressed version of my JS solution. As Japt is JS then we can require that this be run from the root level of api.stackexchange.com and also return a Promise object containing the result. Oxfet®("quÀËs/{U}?ÐÒ=¬¸golf").È(r=>r.js()).È(i=>(j=i.ems).sÖ/j.s³r_Öt)  • View it • Try it - the extra bytes in this version are accounted for by the inclusion of //api.stackexchange.com/ in the URL and of console.log so you can actually see it working • o0 Why have you made the code a link? It even messes with the userscript's byte count display lol. i.imgur.com/SO2zgAy.png – totallyhuman Sep 18 '17 at 20:54 # Mathematica, 124 bytes N@("score"/.(u="items"/.Import["http://api.stackexchange.com/questions/"<>#<>"?site=codegolf","JSON"]))/("answer_count"/.u)&  Mathematica has a data type called Rule and it confuses the heck out of me. :P # Python 3 + requests, 149 bytes -1 byte thanks to Mr. Xcoder. from requests import* u=get('http://api.stackexchange.com/questions/%s?site=codegolf'%input()).json()['items'] print(u['score']/u['answer_count'])  • The link is to Python 2. Btw, it throws an error both in Python 2 and Python 3 (on TIO). – user72349 Sep 18 '17 at 15:38 • No internet access on TIO whoops. I just used TIO for the answer formatting lol. – totallyhuman Sep 18 '17 at 15:42 • I think that (for now) http suffices. – Mr. Xcoder Sep 18 '17 at 15:49 • 125 bytes – LyricLy Sep 19 '17 at 9:27 # PHP, 167 bytes <?$f=json_decode(gzdecode(file_get_contents('https://api.stackexchange.com/2.2/questions/'.$argv.'?site=codegolf')))->items;echo$f->score/\$f->answer_count;


Turbo-fast crack at this. Save as a file and execute in the terminal like so:

php -f file.php 143083
`

Might be a way to reduce this.