-
Notifications
You must be signed in to change notification settings - Fork 63
nthperm(): Replace one %= by a -= remainder * divisor computed earlier
#55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## master #55 +/- ##
=======================================
Coverage 96.96% 96.96%
=======================================
Files 6 6
Lines 594 594
=======================================
Hits 576 576
Misses 18 18
Continue to review full report at Codecov.
|
Just found out there is such a function, |
| k = k % f | ||
| f = div(f, n-i) | ||
| j = k ÷ f | ||
| k -= j * f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, by k - div(k, f) * f == k % f
mschauer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not passing tests after resolving conflict
|
The issue is: |
This is a tiny rewrite that makes
nthperm!()a little faster, by about 15% or so. The speed results from replacing an effectivek = k ÷ fbyk = k - j * f, wherejhas been computed in an earlier%.(Incidentally, this kind of code could benefit from a generic function
divisor, remainder = integer_divide(num, denom))Further some small cosmetic changes, and an unnecessary
+1-1removal forj.