Talk:Sort the letters of string in alphabetical order: Difference between revisions

 
(11 intermediate revisions by 4 users not shown)
Line 52:
:::::::::: Well, we can argue till the cows come home about what words mean or allow us to do and, if someone set their mind to it, they could probably drive a coach and horses through many of the task descriptions on RC. However, there is such a thing as the ''spirit'' of a task and, for a non-pedant such as me, that at least is clear and is not to use built-in sort functionality at all for this particular task. Simply hiding it behind the facade of your own function would go against that spirit. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 08:50, 27 July 2021 (UTC)
 
::::::::::: A non-pedant?! /me: hisses. makes a little crucifix with thishis fingers. Of course you are quite right about the ''spirit'' --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]])
 
:::: The task title and description are currently at odds with each other. The former says sort in alphabetical order and the latter in lexicographical order. Given that we have example strings containing both upper and lower case letters and non-letters, lexicographical order seems the most appropriate to me and I therefore agree with Paddy3118's suggested title change above. --[[User:PureFox|PureFox]] ([[User talk:PureFox|talk]]) 15:48, 26 July 2021 (UTC)
Line 71:
: I might suggest your Slacksort is a variant of [[Sorting_algorithms/Selection_sort]] except that one inefficiency of the latter is it can make multiple passes down the rest of the array in order to obtain the same minimum value, whereas one inefficiency of the former is it <del>can</del> will make multiple passes down the entire array that achieve nothing.
: Plus as written it does not appear it can actually be used as a sort method, as in s := Slacksort(s), and is integer/char-only. --[[User:Petelomax|Pete Lomax]] ([[User talk:Petelomax|talk]]) 20:15, 25 July 2021 (UTC)
 
== Request collation and sample input/output ==
The task appears to require a collation sequence, but doesn't clearly specify. Further, title says "''letters'' in ''alphabetical'' order", while task says "''characters'' in ''lexicographical'' order". (I would presume task description as more-authoritative than title) It also isn't clear how to sort upper/lower of same letter - does sort("CcBbAa") → "aAbBcC" or → "AaBbCc"? (dictionaries and phone books often disagree on that point) Numeric characters will have a "natural for your language" order, but what about punctuation characters, et al? Which comes first: comma or period? And do those come before zero? And so on for every other ''character'' to be considered. Author seems to assume this "natural" order is self-evident; I think it's not. ASCII or EBCDIC or UTF or similar are certainly '''NOT''' "natural" to any language (that I'm aware of!) so let's rule those out. I'd propose presenting an input string of all characters to be considered, as well as an output string showing the desired sequencing (i.e. the ''answer'' for given input). Further, it would be helpful to specify what to do with any characters encountered that ''aren't'' in the input string - discard? keep-in-place where encountered? append-at-end unsorted in order of encounter? (several other possibilities here) Additionally, if the collation sequence is indeed the focus of this task, then perhaps the (seemingly odd) final line of the task description (Write the function even if your language has a built-in function for it.) perhaps becomes unneccessary - because then the task would really be about writing the ''comparator'' rather than the ''sorter'', so why not allow a built-in sort if available? --[[User:Davbol|Davbol]] ([[User talk:Davbol|talk]]) 19:11, 12 August 2022 (UTC)
 
:# As written, the task allows ASCII/UTF or EBCDIC ordering (or, hypothetically, some other ordering).
:# Also, here, [[wp:Bucket_sort|sorting]] does not require a comparator.
:# But... when you say <i>it would be helpful to specify what to do with any characters encountered that ''aren't'' in the input string</i> -- what do you mean? If the characters are not in the input string, how would they be encountered??
:--[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 19:32, 12 August 2022 (UTC)
 
::Maybe I'm just reading too strictly, but the wording of the task encourages my confusion..
::# As I read it, it asks for characters "natural to the language". ASCII is certainly not "natural", EBCDIC perhaps even less-so. Both are machine constructs, not language constructs, so it seemed to me like the task-writer might have had something else in mind.
::# If this is just another pointless variation of "rewrite a sort algorithm" then still same request: please clarify/formalize the specification, provide an example, etc. There are hints that the task-writer might have been attempting to convey the use of a natural-language-specific collated sort.
::# It's a question of domain, and how to handle values outside the domain. Let's assume the task-author agrees to provide sample input/output strings in order to demonstrate the intended collation sequence, but still allows implementations to choose their OWN input strings, natural to their language (as is currently the case). If, hypothetically, the task-author failed to include/demonstrate the sorting of punctuation, then how should an implementation handle punctuation characters if encountered? Either that, or require the use of the example input, and accept only the example output. (eliminating free choice input entirely, so that the domain of characters is predetermined)
::If the task-writer merely wants characters of a string sorted by whatever machine-collation (whether ASCII, EBCDIC or other) happens to be in effect, then I'd recommend the task be written in simpler terms, so as not to suggest that something more might have been intended. --[[User:Davbol|Davbol]] ([[User talk:Davbol|talk]]) 05:38, 13 August 2022 (UTC)
 
::: Indeed "natural to the language" and the most typical meaning for "natural" represent very different concepts (and rely on different "natural language" definitions of the adjective).
::: But perhaps you could suggest a better phrasing which you think would serve here? --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 07:53, 13 August 2022 (UTC)
 
:::: The task says "A character for this purpose should be whatever is natural for your language" - surely, this means the programming language, not the programmer's natural language. The collating sequence is thus defined by the character set being used - ASCII, Unicode, EBCDIC or whatever. Most languages have a character/byte/rune/whatever type and so the task author is saying use whatever's best for the language.
:::: Perhaps the wording could be changed to "A character for this purpose should be whatever is natural for your programming language".
:::: Mandating the collating sequence would disadvantage languages where the specified sequence wasn't the one "natural" to the programming language and surely over-complicate the code. The task is a simple sorting application, requiring demonstration of how to get at the individual characters of a string.--[[User:Tigerofdarkness|Tigerofdarkness]] ([[User talk:Tigerofdarkness|talk]]) 08:59, 13 August 2022 (UTC)
 
:::::So it'd be ok if "N" comes before "a"? In ASCII it does, alphabetically it does not. Even case-insensitive, it still isn't specified which of e.g. "nN" or "Nn" would be correct. If the tasks indeed just wants a simple ASCII sort then it should just come out and say so - all of the extraneous language in the task description does NOT clarify that. If the task is merely to demonstrate individual character retrieval, then there are simpler ways to demonstrate (e.g, just count the chars, or reverse the string, etc) without opening up the can-of-worms of lexicographical order. If the task has something ''else'' in mind, then it fails to convey it adequately. --[[User:Davbol|Davbol]] ([[User talk:Davbol|talk]]) 18:10, 15 August 2022 (UTC)
:::::: My reading of the task is that ASCII order is *acceptable* but not *required*. --[[User:Rdm|Rdm]] ([[User talk:Rdm|talk]]) 19:44, 15 August 2022 (UTC)
 
:::::: I agree - looking at the existing samples, it would seem that almost all of them have N before a, a small number have a before A, so the "acceptable but not required" interpretion seems good to me. I see your Lua sample is one of the exceptions, which is fine. I don't think making 99% of the others invalid is worth it. --[[User:Tigerofdarkness|Tigerofdarkness]] ([[User talk:Tigerofdarkness|talk]]) 20:22, 15 August 2022 (UTC)
 
:::::: Incidently, the task was written by Calmosoft, the author of the Ring sample, which appears to specifically use ASCII and removes spaces. It has only lowercase and spaces in the sample string. --[[User:Tigerofdarkness|Tigerofdarkness]] ([[User talk:Tigerofdarkness|talk]]) 20:37, 15 August 2022 (UTC)
3,022

edits