Jump to content

Longest string challenge: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output.
(Added Julia language)
m (→‎{{header|REXX}}: added/changed comments and whitespace, used a template for the output.)
Line 1,737:
 
=={{header|REXX}}==
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.
===read file until E-O-F===
<lang rexx>/*REXX pgmprogram reads a file &and prints the longest [widest] record(s)/line(s). */
!.='' /*initialize the stemmed array to nul. */
fileID= 'LONGEST1.TXT' /*point to the input file. /*the name of the file used for input. */
m=0 exit /*stickthe amaximum forkwidth in it,(so we're donefar). */
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 inputline to the terminal. */
!.w=!.w || '0a'x || _ /*build a stemmed array element. */
do jm=max(m, w) for m /*handledetermine the casemaximum ofwidth noso inputfar. */
end /*jwhile*/</lang>
 
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) say center(' list end ' , 79, /*find the maximum width so far. */'═')
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 = bb
Line 1,774:
 
===read file until not ready===
<lang rexx>/*REXX pgmprogram reads a file &and prints the longest [widest] record(s)/line(s). */
!.='' /*initialize the stemmed array to nul. */
fileID= 'LONGEST2.TXT' /*point to the input file. /*the name of the file used for input. */
signal on notreadynotReady /*when E-O-F is reached, jump/branch. */
m=0 /*the maximum width line (so far). */
 
do forever; _=linein(fileID); w=length(_) /*read a line from the input file. /*read a line. */
say 'input =' _ /*display theline's inputcontent to terminal. */
!.w=!.w || '0aa'x || _ /*build a stemmed array element. */
m=max(m, w) /*find the maximum width so far. */
end /*forever*/
 
notreadynotReady: do j=m for m /*handle the case of no input. */
say center(' longest record(s): ', 79, '═')
say substr(!.m, 2)
say center(' list end ' , 79, '═')
exit /*stick a fork in it, we're all done. */
end /*j*/</lang>
{{out|output|text=&nbsp; when using the default input:}}
'''output'''
<pre>
<pre style="height:30ex;overflow:scroll">
input = -3
input = -two
Line 1,818:
══════════════════════════════════ list end ═══════════════════════════════════
</pre>
 
===Dual code (works on TSO and PC)===
<lang rexx>/* REXX ***************************************************************
Cookies help us deliver our services. By using our services, you agree to our use of cookies.