Longest string challenge: Difference between revisions

Content deleted Content added
Added Julia language
m →‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output.
Line 1,737: Line 1,737:


=={{header|REXX}}==
=={{header|REXX}}==
In the REXX language, ''everything'' is a string (characters).
In the REXX language,   ''everything''   is a string (characters).
<br>A stemmed array (y.1 y.2 y.3 ∙∙∙) is nothing more than three disjointed REXX variables.
<br>A stemmed array (y.1 y.2 y.3 ∙∙∙) is nothing more than three disjointed REXX variables.
===read file until E-O-F===
===read file until E-O-F===
<lang rexx>/*REXX pgm reads a file & prints the longest [widest] record(s)/line(s).*/
<lang rexx>/*REXX program reads a file and prints the longest [widest] record(s)/line(s). */
!.='' /*initialize stemmed array to nul*/
!.= /*initialize the stemmed array to nul. */
fileID='LONGEST1.TXT' /*point to the input file. */
fileID= 'LONGEST1.TXT' /*the name of the file used for input. */
m=0 /*the maximum width (so far). */
m=0
do while min( lines(fileID), 1) /*form to bypass using conditional test*/
_=linein(fileID); w=length(_) /*obtain a line; obtain the width(len).*/
say 'input =' _ /*display the line to the terminal. */
!.w=!.w || '0a'x || _ /*build a stemmed array element. */
m=max(m, w) /*determine the maximum width so far. */
end /*while*/


do j=m for m /*handle the case of no input. */
do while min(lines(fileID),1); _=linein(fileID); w=length(_)
say center(' longest record(s): ', 79, '═')
say 'input =' _ /*display the input to terminal. */
say substr(!.m, 2)
!.w=!.w || '0a'x || _ /*build a stemmed array element. */
m=max(m,w) /*find the maximum width so far. */
say center(' list end ' , 79, '═')
exit /*stick a fork in it, we're all done. */
end /*while min(lines(... */
end /*j*/</lang>

{{out|output|text=&nbsp; when using the default input:}}
do j=m for m /*handle the case of no input. */
<pre>
say center(' longest record(s): ',79,'═')
say substr(!.m,2)
say center(' list end ',79,'═')
exit /*stick a fork in it, we're done.*/
end /*j*/</lang>
'''output'''
<pre style="overflow:scroll">
input = a
input = a
input = bb
input = bb
Line 1,774: Line 1,774:


===read file until not ready===
===read file until not ready===
<lang rexx>/*REXX pgm reads a file & prints the longest [widest] record(s)/line(s).*/
<lang rexx>/*REXX program reads a file and prints the longest [widest] record(s)/line(s). */
!.='' /*initialize stemmed array to nul*/
!.= /*initialize the stemmed array to nul. */
fileID='LONGEST2.TXT' /*point to the input file. */
fileID= 'LONGEST2.TXT' /*the name of the file used for input. */
signal on notready /*when E-O-F is reached, jump. */
signal on notReady /*when E-O-F is reached, jump/branch. */
m=0 /*maximum width line so far. */
m=0 /*the maximum width (so far). */


do forever; _=linein(fileID); w=length(_) /*read a line. */
do forever; _=linein(fileID); w=length(_) /*read a line from the input file. */
say 'input =' _ /*display the input to terminal. */
say 'input =' _ /*display line's content to terminal. */
!.w=!.w || '0a'x || _ /*build a stemmed array element. */
!.w=!.w || 'a'x || _ /*build a stemmed array element. */
m=max(m,w) /*find the maximum width so far. */
m=max(m, w) /*find the maximum width so far. */
end /*forever*/
end /*forever*/


notready: do j=m for m /*handle the case of no input. */
notReady: do j=m for m /*handle the case of no input. */
say center(' longest record(s): ',79,'═')
say center(' longest record(s): ', 79, '═')
say substr(!.m,2)
say substr(!.m, 2)
say center(' list end ',79,'═')
say center(' list end ' , 79, '═')
exit /*stick a fork in it, we're done.*/
exit /*stick a fork in it, we're all done. */
end /*j*/</lang>
end /*j*/</lang>
{{out|output|text=&nbsp; when using the default input:}}
'''output'''
<pre>
<pre style="height:30ex;overflow:scroll">
input = -3
input = -3
input = -two
input = -two
Line 1,818: Line 1,818:
══════════════════════════════════ list end ═══════════════════════════════════
══════════════════════════════════ list end ═══════════════════════════════════
</pre>
</pre>

===Dual code (works on TSO and PC)===
===Dual code (works on TSO and PC)===
<lang rexx>/* REXX ***************************************************************
<lang rexx>/* REXX ***************************************************************