Anonymous user
Longest string challenge: Difference between revisions
→read file until not ready: re-worked REXX program to NOT use a variable to hold the length of a record or the maximum record, elided the use of an IF statement..
(Delete dead link to non-rosetta URI and referencing sentence.) |
(→read file until not ready: re-worked REXX program to NOT use a variable to hold the length of a record or the maximum record, elided the use of an IF statement..) |
||
Line 1,775:
In the REXX language, ''everything'' is a string (characters).
===read file until not ready===
This REXX version adheres to spirit (and letter) of all the restrictions for this task:
No comparators are used (such as '''if''' or '''when'''), ▼
::* no comparators are used, including those within:
<br>no output is produced when the file is empty (or contains all null strings),▼
▲
<br>no arrays or lists are used, and ▼
::::* '''when''' (statements)
<br>no additions or subtractions are used.▼
::::* '''until''' (clauses) and
<lang rexx>/*REXX program reads a file and displays the longest [widest] record(s) [line(s)].*/▼
::* no variables are used to hold the length of (any) record.
signal on notReady /*when E-O-F is reached, jump/branch. */
iFID= 'LONGEST.TXT' /*the default file identifier for input*/
parse arg fid . /*obtain optional argument from the CL.*/
do r=1; _=linein(iFID); w=length(_) /*read a line from the input file. */▼
do n=m for 1; end /*for smaller records. */▼
!=
do forever; _=linein(iFID);
▲ end /*r*/
do #=length(!' ') to length(?) for 1; $=; end /*found widest rec.*/
!=left(., max( length(!), length(?) )
/* [↓] comes here when file gets E─O─F*/
▲notReady:
say substr($, 2) /*display (all) the longest records. */
exit /*stick a fork in it, we're all done. */
end /*j*/</lang>
{{out|input|text=file '''LONGEST.TXT''':}}
<pre>
|