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 |
<lang rexx>/*REXX program reads a file and prints the longest [widest] record(s)/line(s). */ |
||
!.= |
!.= /*initialize the stemmed array to nul. */ |
||
fileID='LONGEST1.TXT' |
fileID= 'LONGEST1.TXT' /*the name of the file used for input. */ |
||
⚫ | |||
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).*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
do j=m for m /*handle the case of no input. */ |
|||
do while min(lines(fileID),1); _=linein(fileID); w=length(_) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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= when using the default input:}} |
|||
⚫ | |||
<pre> |
|||
⚫ | |||
⚫ | |||
say center(' list end ',79,'═') |
|||
⚫ | |||
⚫ | |||
'''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 |
<lang rexx>/*REXX program reads a file and prints the longest [widest] record(s)/line(s). */ |
||
!.= |
!.= /*initialize the stemmed array to nul. */ |
||
fileID='LONGEST2.TXT' |
fileID= 'LONGEST2.TXT' /*the name of the file used for input. */ |
||
signal on |
signal on notReady /*when E-O-F is reached, jump/branch. */ |
||
m=0 /*maximum width |
m=0 /*the maximum width (so far). */ |
||
do forever; |
do forever; _=linein(fileID); w=length(_) /*read a line from the input file. */ |
||
say 'input =' _ /*display |
say 'input =' _ /*display line's content to terminal. */ |
||
!.w=!.w || ' |
!.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. */ |
|||
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= 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 *************************************************************** |