Longest string challenge: Difference between revisions

Content deleted Content added
Aerobar (talk | contribs)
added RPL
Aerobar (talk | contribs)
→‎{{header|RPL}}: improved code
Line 2,388: Line 2,388:
=={{header|RPL}}==
=={{header|RPL}}==
This program complies with the list of restrictions:
This program complies with the list of restrictions:
The main hack is based on the fact that the <code>SUB</code> function, which extracts one or more characters from a string, returns the null character if its arguments exceed the size of the string. A minor hack is to use <code>INCR</code> and <code>DECR</code> commands, instead of forbidden arithmetic operations.
The main hack is based on the fact that the <code>SUB</code> function, which extracts one or more characters from a string, returns the null character if its arguments exceed the size of the string.
A second hack is to use a string to count the number of compliant strings already in the stack: the <code>+</code> and <code>STO+</code> commands present in the code are not arithmetic operations, but string operations aiming at appending characters.
The user stack is both the standard input and output.
The user stack is both the standard input and output.
{{works with|HP|49}}
{{works with|HP|49}}
1 → count
"X" → count
≪ 1 CF <span style="color:grey">@ flag 1 set means there are at least 2 strings in the stack</span>
≪ 1 CF <span style="color:grey">@ flag 1 set means there are at least 2 strings in the stack</span>
'''WHILE''' "String?" "" INPUT DUP SIZE '''REPEAT'''
'''WHILE''' "String?" "" INPUT DUP SIZE '''REPEAT'''
'''IF''' 1 FS? '''THEN'''
'''IF''' 1 FS? '''THEN'''
'''CASE'''
'''CASE'''
DUP2 SWAP SIZE DUP SUB NUM NOT '''THEN''' DROP '''END'''
DUP2 SWAP SIZE DUP SUB NUM NOT '''THEN'''
DUP2 SIZE DUP SUB NUM NOT '''THEN''' 'count' INCR ROLLD 'count' DECR DROPN 1 'count' STO '''END'''
DROP '''END'''
'count' INCR DROP
DUP2 SIZE DUP SUB NUM NOT '''THEN'''
count "X" + SIZE ROLLD count SIZE DROPN "X" 'count' STO '''END'''
"X" 'count' STO+
'''END'''
'''END'''
'''ELSE''' 1 SF '''END'''
'''ELSE''' 1 SF '''END'''