Talk:Longest string challenge: Difference between revisions

Line 94:
:::::: Re Pt2. Stepping back this seems to be focusing on avoiding direct comparison of length as in the pedestrian solution. Most of the posted solutions are looking at some secondary way of detecting end of string.
:::::: Does any of that help? As a start? --[[User:Dgamey|Dgamey]] 21:45, 14 August 2011 (UTC)
::::::: Ok, yes, J has data types inside of its arrays, they are mostly invisible, but they can be grouped into: numeric, literal (which means that it's an array of characters), and boxed (which means that it's an array of references to arrays). So, hypothetically speaking, we could claim that "no list" really means, in the context of J, no boxed arrays" -- this means we can have arrays of characters with multiple dimensions even though in another language a person might think of this as "lists of strings". That might leave use with a solution like <code>(];._2 ([ #~ -:"1) [:|."1|.;._2)@(1!:1) but would this be legal? It's using the -: verb, which tests for an exact [http://jsoftware.com/help/dictionary/d122.htm match]. But is that a comparison operator? If the point is to not be testing on length, then this might or might not be legal, depending on what that concept really means.
::::::: But, ok, you probably do not know enough J to read that sentence, so here's a description: Using the end of line marker, form the characters into a two dimensional array (padding short lines with spaces). This is the left argument to the inner expression. The right argument is formed using the same technique, except that we reverse each line in the process of forming them into an array and then reverse each row again after it has been padded. The inner set of parenthesis contains an expression which will keep the rows which are identical in both copies.
::::::: That said, it's probably also worth noting that most J programming involves "thinking outside the box" if "the box" means "traditional approaches used in traditional languages".
::::::: Also, for reference, here is a "use length directly" approach: <code>(#~ (=>./)@:(#@>))@(<;._2)@(1!:1)</code> -- note that it does not use any "comparison operators" except = and that it's not doing any "arithmetic". It is, however, finding the maximum length and using that to select the relevant rows.
::::::: --[[User:Rdm|Rdm]] 01:08, 15 August 2011 (UTC)
 
== Not pointless ==
6,962

edits