DEV Community


Discussion on: I just solved this coding challenge, but I don't understand why my solution works 🤔

gnsp profile image
Ganesh Prasad • Edited

Actually, your formula is correct. Let's derive it mathematically.

The number of articles you want to publish is A, and the impact you want is I. It's given that impact(I) = total_citations(C) / total_articles(A). It's also given that rounding is done only upwards. For example if your impact value is 23.0000001, then it will be rounded up as 24. (That's same as saying rounding is done using math.ceil).

We want to find the minimum number of citations C_min so that our rounded value of impact equals to I. We know that I = math.ceil( C / A ), therefore, the value of (C / A) must be something between I-1 and I. That is, I-1 < (C/A) <= I. From this, we can write, (I-1)*A < C <= I*A.
Now we know that value of C should be strictly higher than (I-1)*A and it should be less than or equal to I*A. C is an integer, therefore the minimum value of C that satisfies the above condition must be (I-1)*A + 1.

Hence it's proved that, C_min = (I-1)*A + 1.

wangonya profile image
Kinyanjui Wangonya Author • Edited

Wow, it all makes sense now. Thanks a lot @gnsp