Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
"returns an array of all
(n k)
-pairs (as two-element int arrays) where the value of "n
-choose-k
" equals the input, sorted by ascendingk
"You're just sorting wrong.
intro + formula chapter just implement that and pass this kata :) It's not a closed formula, if that is what you are looking for. DP will do the trick.
I could not find it. Which section is that in?
https://en.m.wikipedia.org/wiki/Singmaster%27s_conjecture, linked from the Triangle page, doesn't give a general solution.
The general solution is explained on the wiki page of Pascal's triangle.
bad testcases: 6 appears three times - Expected: [[6, 1], [4, 2], [6, 5]], instead got: [[4, 2], [6, 1], [6, 5]]
many other numbers appear four times - Expected: [[10, 1], [5, 2], [5, 3], [10, 9]], instead got: [[5, 2], [5, 3], [10, 1], [10, 9]]
I similarly was annoyed that we had to round the distance. I ran into a weird problem using int() vs round().
from math import sqrt
r2 = 5
rA = int( sqrt(r2)*10000 )/10000 # 2.236
rB = round( r2**0.5, 4 ) # 2.236
This happened ONLY when r-squared equalled 5.
This comment is hidden because it contains spoiler information about the solution
Even although the first sentence calls for an accurate solution, many current solutions, including the one with most "best practices" upvotes (4), will fail the following test case, which I think should be added to rule out the not-quite-right solutions:
I am not aware of a general solution, and if one were known, I suspect Singmaster's conjecture would rather be known as Someone's theorem.
Anyway since
n-choose-k >= n
for all0<k<n
, you only need to sample finitely many canidate solutions for any given finitea
, so a provably correct overall solution must exist. (I am not sure how to prevent that kind of brute force, but for largea
it will probably time out already.)One should be able to pass all tests with this approach, i.e. find
(n,k)
candidate pairs and check whethern-choose-k == a
, if the candidate pairs are picked more reasonably.I haven't yet given up on this kata, but I would like to know:
Is there an actual, general solution for this problem, or should I cobble together something from OEIS series, rules about primes and powers of them, and educated guesses that are not provably correct?
Well, the random test does not check your solution against mine, it only did a rather rudimentary plausibility check. I expanded it to do more plausibility checks. :-)
Oops...Fixed. (I had just copied the a section of the full test cases there. Seems I cannot run the example tests only from the author interface.) Sorry for the inconvenience.
Thanks for the hint ;-)
Example test is using
it
when it should be usingdescribe
, which makes them not working:To see the tests, I submitted with
return []
.All the random tests passed. Is that supposed to happen?
Loading more items...