-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
Add next_k_array!
and k_array_rank
.
#199
Add next_k_array!
and k_array_rank
.
#199
Conversation
Thanks @shizejin
One possibility is: function k_array_rank(T::Type{<:Integer}, a::Vector{<:Integer})
k = length(a)
idx = one(T)
for i = 1:k
idx += binomial(T(a[i])-one(T), T(i))
end
return idx
end
k_array_rank(a::Vector{<:Integer}) = k_array_rank(Int, a) n, k = 100, 50
a = collect((n-k+1):n)
k_array_rank(BigInt, a) 100891344545564193334812497256 k_array_rank(a) InexactError() I don't know if this is "Julian": @sglyon ? |
That proposal is quite Julian. It would be great if there was a way to make it "just work" without throwing an error, but unfortunately I don't think there is. As long as you don't expect the |
@sglyon Thanks. @shizejin We may add a note about the possibility of an error as well as a sufficient condition for it not to occur, as in the Python version. |
@oyamad Sure, I will modify this. In this case, in the tournament game, should we set a threshold of the pair of n and k to determine whether use |
@oyamad It seems that the if binomial(BigInt(n), BigInt(k)) > typemax(typeof(n))
error("Overflow! Maximum allowed size of $(typeof(n)) exceeded")
end What do you think? |
Are we talking about this PR, or the tournament game? About the latter let's discuss at |
Codecov Report
@@ Coverage Diff @@
## master #199 +/- ##
==========================================
+ Coverage 91.02% 91.12% +0.09%
==========================================
Files 24 24
Lines 1693 1712 +19
==========================================
+ Hits 1541 1560 +19
Misses 152 152
Continue to review full report at Codecov.
|
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.
Looks good to me.
179c923
to
a645c2d
Compare
Add
next_k_array!
andk_array_rank
utilities, mimicking the counterpart Python version implemented by @oyamad. It is mainly copying and pasting, and modifying a little part (let index start from 1 rather than 0).