Jump to content

Talk:Align columns: Difference between revisions

→‎J solution: solution contains no column count
(→‎J solution: Current solution requires specifying the correct column count.)
(→‎J solution: solution contains no column count)
Line 1:
== J solution ==
 
I haven't read the J solution in depth yet, but it appears more complex than may be necessary. For example, with <ttcode>'LEFT CENTER RIGHT'=:i.3</ttcode> we can solve the task thus:
 
_2 {:\ ": <;._2@:,~&>/'$';LF;text [ 9!:17 CENTER #,~ 2CENTER [ 9!:7 ' '$~11
Given a text file of many lines, where fields within a line
are delineated by a single 'dollar' character, write a program
Line 11:
justified, right justified, or center justified within its column.
Replacing <ttcode>CENTER</ttcode> with <ttcode>LEFT</ttcode> or <ttcode>RIGHT</ttcode> to taste.
 
Now, of course, the justification selected applies to every word. If we want to be able to treat each word (or column) independently, there are other methods. Even for this more general specification, I'm still not convinced that the large explicit verb is required, but I'll have to review it in detail to confirm.
Line 24:
 
: The new solution has the column count hardcoded into it. I suspect that the task is intended to work such that the tally of columns is derived from the text, not provided by the user as part of the input. --[[User:TBH|TBH]] 22:34, 2 December 2008 (UTC)
 
:: Where is the column count hardcoded? AFAIK, the number of columns wholly determined by the (maximum) number of <code>$</code>s in a line. To be more explicit, the numeric constants are, from left to right:
::{| class="wikitable" style="text-align: top,left; font-size: 85%; width: auto; table-layout: fixed;"
|-
| Constant
| Description
|-
| <code>'''_2''' {:\ ":</code>
| Non-overlapping (<code>'''-'''</code>) pairs (<code>'''2'''</code>) of rows of the formatted data.
|-
| <code><;.'''_2'''...</code>
| Split the input, treating the last (<code>'''2'''</code>) item as the fret, and exclude (<code>'''-'''</code>) the frets.
|-
| <code>'''9'''!:'''17'''</code>
| Foreign family controlling parameters (<code>'''9'''</code>), specifically controlling alignment (<code>'''17'''</code>).
|-
| <code>... ,~ '''CENTER''' ...</code>
| Parameter specifying centered alignment. (A prior version had <code>'''CENTER''' #~'''2'''</code>, which is the same, but one word longer)
|-
| <code>'''9'''!:'''7'''</code>
| Foreign family controlling parameters (<code>'''9'''</code>), specifically controlling linedrawing characters (<code>'''7'''</code>).
|-
| <code>' '$~'''11'''</code>
| Parameter specifying linedrawing characters (all <code>'''11'''</code> linedrawing characters will be <code>' '</code>).
|}
::--[[User:DanBron|DanBron]] 23:32, 2 December 2008 (UTC)
 
== Output Question ==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.