-
Notifications
You must be signed in to change notification settings - Fork 177
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
More precise algorithm definition #11
Comments
This is definitively a good idea! Do you have any recommendation on how we can define it? |
This is how i understood it: The remaining numbers would then be 1,3,7,7,34 or if you don't want the same numbers 1,3,7,34. |
I believe that no extra information should be lost apart from what the algorithm instructs, so the double 7 seems like something that should remain. One other thing is that there should be some well-tested inputs and outputs for comparison. |
There should be more precise definition of "eliminated". For instance, in javascript, stalin-sort/javascript/stalin-sort.js Line 5 in 174338d
filtering elements by the functional way can be called "elimination", I think. in php, Line 22 in 174338d
the recursive way also may well be called "elimination". in haxe, stalin-sort/haxe/stalin_sort.hx Line 8 in 2972fd3
procedurally adding admitted elements to a new array is not appropriate, imo. Thoughts? |
I don't think that something so expecific needs to be a concern, for instance filtering in JS returns a new Array, so it's just like adding something to the a new Array, the way that some codes are doing. |
I divided my comment so we can discuss each proposal separately. One important thing that I thought that needs to be pattern is the way that the function and the codes are written. For example, the Java and the C code have a main function that uses the funcion, this is one think that I see as bad. Look how many lines were used for this purpose: Lines 16 to 35 in 174338d
I suggest that all codes needs to be a single function that is exported from the file at its end, just like the JS code. Of course that some languages don't have this feature of exporting a single function, so for this purposes, like Java stalin-sort/javascript/stalin-sort.js Lines 1 to 15 in 174338d
|
I divided my comment so we can discuss each proposal separately. Other point that I think that needs to be pattern is the number of the parameters and the return of the function. All functions must have one param, returns one value and the received argument mustn't be modified, it makes the code easier to understand in any given language. Good example:stalin-sort/python/stalin_sort.py Lines 1 to 9 in 174338d
Bad example:stalin-sort/C++/stalin_sort.cpp Lines 4 to 15 in 174338d
|
I divided my comment so we can discuss each proposal separately. Other important thing is the validation and error throwing that needs to be done. Some codes simply don't check if the argument is really an array or a pointer, in some cases. I think that all codes needs to check this, just like here: stalin-sort/javascript/stalin-sort.js Line 2 in 174338d
Other good checking is check if the array is empty, it's a good improvement for all codes, just like here; stalin-sort/ruby/stalin_sort.rb Line 2 in 174338d
|
Hey mates, could you take a look at PR #68? |
We talk about arrays a lot, but a good(?!) property of Stalin Sort is that it can be done in-place on a linked list, still in O(n) time. In-place sort using an array is also possible, but more complex as you'd need to keep track of the position offset from elimination. |
As this project gets larger and larger, lol, we may need a less vague algorithm definition than a tweet so that it is easier to know if a PR is wrong.
The text was updated successfully, but these errors were encountered: