10
\$\begingroup\$

Challenge

Given a SE user's ID, output the sum of their reputation from across all of the Stack Exchange networks​ the user has signed up to.

Rules

If a user has 101 or less reputation on a site, count it as zero in the sum.

You should not count Area 51 rep or hidden communities!!

URL shorteners are disallowed.

Examples

Subject to change

User 3244989 (Beta Decay)

14141

User 918086 (Dennis)

204892

User 11683 (Jon Skeet)

1029180

Winning

The shortest code in bytes wins.

\$\endgroup\$

5 Answers 5

3
\$\begingroup\$

Python 2 (with Requests), 149 Bytes

from requests import*
lambda i,r="reputation":sum(u[r]for u in get("http://api.stackexchange.com/users/"+i+"/associated").json()["items"]if u[r]>101)

I requested the API, converted the API to JSON, then summed the reputation via a generator expression. The generator does remove accounts with less than 101 reputation.

Credit for improving the code: Jonathan Allan.

\$\endgroup\$
0
1
\$\begingroup\$

curl, grep and awk, 106 bytes

curl http://api.stackexchange.com/users/$1/associated|grep -o n\"[^,]*|awk -F: '$2>101{s+=$2}END{print s}'

It's dirty but seems to work well. I don't use awk often so I wouldn't be surprised if there was a way to golf the grep away with it.

\$\endgroup\$
1
\$\begingroup\$

R with httr, 146 Bytes

library(httr)
a=sapply(content(GET(paste0("http://api.stackexchange.com/users/",readline(),"/associated")))$items,'[[','reputation')
sum(a[a>101])
\$\endgroup\$
0
0
\$\begingroup\$

Ruby 2.4, 136 + 20 = 156 bytes

Requires the -rjson -rnet/http -n flags. Input is from STDIN (no trailing newline). Ruby 2.4 is needed for sum.

p JSON.parse(Net::HTTP.get URI"http://api.stackexchange.com/users/#$_/associated")["items"].map{|i|i["reputation"]}.select{|i|i>101}.sum
\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES6), 148 143 142 141 bytes

u=>fetch(`//api.stackexchange.com/users/${u}/associated`).then(j=>j.json(s=0)).then(i=>(i.items.map(r=>s+=(r=r.reputation)>101&&r),alert(s)))

Try it

f=

u=>fetch(`//api.stackexchange.com/users/${u}/associated`).then(j=>j.json(s=0)).then(i=>(i.items.map(r=>s+=(r=r.reputation)>101&&r),alert(s)))

i.addEventListener("submit",e=>{e.preventDefault();(v=+i.firstChild.value)&&f(v)})
<form id=i><input type=number><button>Calc.</button></form>

\$\endgroup\$
7
  • \$\begingroup\$ Does this ignore Area 51? \$\endgroup\$
    – Beta Decay
    Apr 22, 2017 at 19:06
  • \$\begingroup\$ @BetaDecay, I think so. I'm editing a caveat into my answer now to explain. \$\endgroup\$
    – Shaggy
    Apr 22, 2017 at 19:14
  • \$\begingroup\$ Oh right, I didn't think it'd be so simple to filter out \$\endgroup\$
    – Beta Decay
    Apr 22, 2017 at 19:23
  • \$\begingroup\$ @BetaDecay, is that confirmation that that endpoint doesn't include A51 sites? \$\endgroup\$
    – Shaggy
    Apr 22, 2017 at 19:28
  • \$\begingroup\$ What do you mean by endpoint? :/ \$\endgroup\$
    – Beta Decay
    Apr 22, 2017 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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