7
\$\begingroup\$

Challenge

Given a the ID for a PPCG user who has existed for at least a month, output the average amount of reputation they gain per month. You can do this by dividing their reputation by the time since their account was created (which you can find on the profile). This should be returned floored; that is, truncate all of the decimals. (We don't care about the small stuff).

Input

A single integer, which is the user's ID

Output

A single integer, representing the floored rep change per month.

Test Cases

input -> output
42649 -> 127 (me)
12012 -> 3475 (Dennis)
8478  -> 3015 (Martin Ender)
\$\endgroup\$
6
  • 4
    \$\begingroup\$ Can you define what a month is considered to be - a calendar month, a lunar month or 30 days? Or is it at our discretion? \$\endgroup\$
    – Shaggy
    May 5, 2017 at 7:27
  • \$\begingroup\$ @Shaggy When you go to a user profile, under the profile tab, it says "User for <x time>". Go by that. \$\endgroup\$
    – hyper-neutrino
    May 10, 2017 at 17:46
  • \$\begingroup\$ @HyperNeutrino so the formula is (rep/daysSinceAccountCreate)*30? You need to give us a constant for what a month is. \$\endgroup\$
    – Allison
    May 11, 2017 at 17:39
  • \$\begingroup\$ @Sirens Go here and Ctrl-F for 1 year, 9 months. That's what I mean. \$\endgroup\$
    – hyper-neutrino
    May 11, 2017 at 18:10
  • \$\begingroup\$ Should a check that the user has existed for at least a month be included? \$\endgroup\$
    – DimP
    May 18, 2017 at 13:02

2 Answers 2

2
\$\begingroup\$

JS, ES6 243 235 168 166 165 164 bytes

i=>fetch(`//api.stackexchange.com/users/${i}?site=codegolf`).then(x=>x.json()).then(x=>alert(~~((y=x.items[0]).reputation/((new Date/1e3-y.creation_date)/2592e3))))

Based on the Python answer.

Run this in the console:

(i=>fetch(`//api.stackexchange.com/users/${i}?site=codegolf`).then(x=>x.json()).then(x=>alert(~~((y=x.items[0]).reputation/((new Date/1e3-y.creation_date)/2592e3)))))(+prompt("Enter a userId"))

-4 thanks to @insert_name_here

Old answer:

z=>fetch("//codegolf.stackexchange.com/u/"+z).then(x=>x.text()).then(x=>alert((/([\d,]+) <span class="label-uppercase">repu/.exec(x)[1].replace(/,/g,"")/(((y=/Member for <.+>((\d+) years?, )?(\d+) month/.exec(x))[2]||0)*12+ +y[3]||0))))

Improvements welcome! Just fetches the profile page and parses it with regular expressions!

Won't work as a stack snippet, but you can paste this in your console:

(z=>fetch("//codegolf.stackexchange.com/u/"+z).then(x=>x.text()).then(x=>alert(Math.floor(/([\d,]+) <span class="label-uppercase">repu/.exec(x)[1].replace(/,/g,"")/(((y=/Member for <.+>((\d+) years?, )?(\d+) month/.exec(x))[2]||0)*12+ +y[3]||0)))))(+prompt("Enter a userId"))
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Okay :) You have a much higher rep change than me D: I think about double \$\endgroup\$
    – hyper-neutrino
    May 18, 2017 at 13:25
  • \$\begingroup\$ You could save two bytes by using new Date instead of Date.now(). You could also save one more by using 1e3 instead of 1000 and another by using 2592e3 instead of 2592000. \$\endgroup\$ May 18, 2017 at 14:22
1
\$\begingroup\$

Python 3 2, 206 219 201 193 bytes

import requests,time
a=requests.get('http://api.stackexchange.com/users/'+str(input())+'?site=codegolf').json()['items'][0]
print a['reputation']/((int(time.time())-a['creation_date'])/2592000)

I am estimating the months as the OP suggested, but actually print(int(b/((d-c)/2592000))) is a more accurate solution than print(int(b/int((d-c)/2592000))) and also saves a few bytes.

\$\endgroup\$
2
  • \$\begingroup\$ get is not defined \$\endgroup\$
    – hyper-neutrino
    May 18, 2017 at 13:17
  • \$\begingroup\$ @HyperNeutrino try it again now, should work (Python 2). Obviously needs requests. \$\endgroup\$
    – DimP
    May 18, 2017 at 13:41

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.