Mortarboard Challenge

7

2

Challenge

Given a user's ID, determine how many times they have hit the repcap.

Specs

On a given day, let's a user has hit the repcap if they had reputation that wasn't gained due to the repcap. Essentially, on any given day, if the user's net reputation change as calculated without any cap was different from their actual observed reputation change, then they hit the repcap.

Input/Output

Input will be a single integer, the user's ID.
Output will be a single integer, indicating the number of days for which they had reputation that was "lost".
I/O can be in any reasonable format.

Test Cases

Feel free to add your own ID and stats here. The brackets indicate which user it is, but that isn't part of the output. Don't include it.

input -> output (username)
42649 -> 0 (HyperNeutrino)
41723 -> 7 (Fatalize)
46271 -> 0 (Riker) (This user has obtained 200 rep twice, but never over)

HyperNeutrino

Posted 2017-05-01T14:14:37.570

Reputation: 26 575

2For the record, your criterion is different from that of the mortarboard badge. For that you just need 200 rep, even if you haven't got the rep cap at that point (the rules are a bit more complicated because not all rep changes count towards the badge). – Martin Ender – 2017-05-01T14:30:02.067

@MartinEnder Yes. I decided to simplify it so people didn't have to count badge progress. Essentially, it counts if and only if the user didn't gain rep they otherwise would have. – HyperNeutrino – 2017-05-01T14:31:56.193

1This question is of interest to me because I happened to hit the rep cap a couple of times last month and I've already hit it again today. +1 – Neil – 2017-05-01T16:01:46.373

1Very related :) – Stewie Griffin – 2017-05-01T16:56:16.740

@StewieGriffin I was inspired to write this challenge because of your challenge, in fact. :) :P – HyperNeutrino – 2017-05-01T20:04:48.297

Answers

1

JS ES6, 360 bytes

f=(i,p=1,d=[])=>fetch(`https://api.stackexchange.com/2.2/users/${i}/reputation?site=codegolf&pagesize=100&page=${p}`).then(x=>x.json()).then(j=>(q=d.concat(j.items),j.has_more?f(i,p+1,q):(r=[],q.map(s=>(r[d=new Date(s.on_date*1000),i=d.getDate()+d.getMonth()*32+d.getYear()*365]?r[i]+=s.reputation_change:r[i]=s.reputation_change)),r.filter(x=>x>200).length)))

Call it like f(user id). Returns a promise that resolves with the number of days that rep was lost.

Ungolfed:

f=(i,p=1,d=[])=>fetch(`https://api.stackexchange.com/2.2/users/${i}/reputation?site=codegolf&pagesize=100&page=${p}&key=kAc8QIHB*IqJDUFcjEF1KA((`).then(x=>x.json()).then(j=>{
    return (q=d.concat(j.items),
    j.has_more?
        f(i,p+1,q)

        :(r=[],
            q.map(s=>(r[d=new Date(s.on_date*1000),
                i=d.getDate()+d.getMonth()*32+d.getYear()*365]?
                    r[i]+=s.reputation_change

                    :r[i]=s.reputation_change)),
            r.filter(x=>x>200).length
        )
    )
});

programmer5000

Posted 2017-05-01T14:14:37.570

Reputation: 7 828