7 kyu
Sorting in R: Rank
189 of 263saudiGuy
Loading description...
Lists
Puzzles
Sorting
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Haskell translation
.
Integers and half-integers are represented exactly, so there is no need for approximate comparisons. If solver manages to lose precision, that's on solver.
This may be a problem with other langauges as well, but I haven't looked at those.
It doesn't really hurt to use approximate equality (unless it significantly impacts test performance), but you're absolutely right.
A perfect example how ranking of katas is highly misleading; maybe a 7 kyu in Python, but no way this would be ranked 7 kyu if it was implemented in C first.
In Rust I get the following error while attemping to pass the Kata:
I return
Vec<f32>
as requested. Fixed tests run fine.Is this going to be fixed anytime soon?
the type was changed from f32 to f64 (see thread below), and you got caught in-between (starting with f32 initial code but submitted after the change)
It would be good to add what a rank is, because not everybody has experience in R.
Rank of a vector element is its location relative to the other elements in an ordered vector.
I would even mark this as an issue; asking for rank without explaining what is asked.
Rust translation (I suggest to wait for the approval of the kata, since there may be suggestions of improvements).
It seems like the testing sequence should prioritize testing with small random arrays first, giving users a better opportunity for debugging.
Test Results:
tests::big_random_arrays
tests::fixed_tests
tests::huge_random_arrays
tests::medium_random_arrays
tests::small_random_arrays
Unlike Python and other interpreted languages, tests are executed in parallel in Rust (and several other languages). I have no possibility to change this and force a particular order of execution (well, strictly technically speaking I believe it is somehow feasible but it's advanced stuff I currently don't dominate, and AFAIK it is not done in any kata).
Also, the way tests are designed doesn't make it hard to focus on small inputs for debugging, it's ok to fold / unfold any part one is interested in. For example (unfolding only fixed tests and small arrays, with a function just returning an empty vector
vec![]
):approved.
AFAIK, rust tests are executed in parallel but are reported in alphabetic order, so it should simply be a matter of just naming them in alphabetic order. I know this from reading discussions on the discord server, not from experience, so it might not be fully accurate.
Hmmm, seems right. I didn't know that.
saudyGuy: do you want me to change the tests so they appear in order of difficulty? I don't think it's actually useful for the reasons I have explained, but it doesn't bother me either to change the design of the tests if you prefer.
If it can be easily implemented, please go ahead.
Done.
Initial solution: trait bounds
Clone + Hash + Ord
should be added toT
.The return type must be
f64
.f32
is not precise enough for big tests (it is possible to get different results if the sum is computed withf32
directly). More precisely,f32
is enough for this problem but the reference solution does not compute average ranks accurately (all ranks are either integers or integers + 0.5 but the reference solution may return13583.501
or20734.002
for tests withT = char
).I did the change. I was not sure about the output type. However, I don't understand how reference solution can return inaccurate results with chars especially (I think the result doesn't depend on the type of the input).
The following expression was the source of imprecision:
sum::<usize>() as f32
. This sum may become larger than the largest safe integer forf32
(2**24
) if a value is repeated sufficiently many times in the original array. It is very likely to get this situation in big tests with chars because only 26 chars are used.Indeed.. Damn floats! Thanks for the explanation!
Random tests should also generate strings of more than one character, since some fixed tests also do (or harmonize both the other way). I am writing a Rust translation so I'd like it to be aligned with the original language and the description (Rust is strictly typed so I need to explicitly set the possibility to have either integers, chars or strings).
Since this is a 7kyu kata, let's keep things simple. Random inputs will generate single characters only.
I am not sure it will be approved as 7kyu. The problem is actually that the description says
Expect numbers and lower-case alphabetic characters only.
while some fixed tests provide an array of strings. This should be aligned, and there is no reason random tests don't provide all the types one can find in fixed tests. In this case, you may also choose to remove/change the tests including strings with multiple characters.Also, I don't think it adds difficulty to the task using chars or strings, a single comparison works (at least in Python and Rust, and many languages; I saw rowcased only uses unsigned ints in his translation, which may be a reasonable choice since handling multiple types is not easy in C).
I have removed strings from both the fixed and full test suites. I believe that generating strings will reduce the likelihood of duplicate values, which is the primary purpose of this kata.
Ok, Thanks, I will allign Rust on this. It is possible to generate dupe strings if needed, but it doesn't bring a great thing to the task.
You're always welcome to edit the Python version as well. I would be happy to learn from you guys.
Well, I am sure I don't need to teach you how to insert dupe strings randomly in an array ;)
For me the kata is ok, I don't see currently how to improve it really.
C Translation
Approved by author
O(n²) solutions should not pass.
done.
7kyu kata should not have performance requirements. The kata should be reranked ( ask a mod ) or the performance requirement should be removed.
Note that I haven't even solved the kata; I am just going off the description, the tags ( which don't include
performance
?!? ), and this comment.