Range extraction: Difference between revisions

Content added Content deleted
(added RPL)
Line 5,171: Line 5,171:
<pre>
<pre>
[0-2, 4, 6-8, 11, 12, 14-25, 27-33, 35-39]
[0-2, 4, 6-8, 11, 12, 14-25, 27-33, 35-39]
</pre>


« 1 SF "" <span style="color:grey">@ initialize output string</span>
'''WHILE''' OVER SIZE '''REPEAT''' <span style="color:grey">@ while input list is not empty</span>
'''IF''' 1 FC?C '''THEN''' "," + '''END''' <span style="color:grey">@ do not append comma at first iteration</span>
'''IFERR''' OVER ΔLIST '''THEN END''' <span style="color:grey">@ if at least 2 items in input list</span>
'''IF''' DUP 1 2 SUB { 1 1 } == '''THEN''' <span style="color:grey">@ if 3 consecutive items </span>
ROT ROT OVER HEAD + "-" + <span style="color:grey">@ append range start to result string</span>
ROT 1 « 1 ≠ » DOLIST 1 POS <span style="color:grey">@ get rank of last consecutive number</span>
'''IF''' DUP NOT '''THEN''' DROP OVER SIZE '''END'''
ROT DUP2 SWAP 1 + OVER SIZE SUB <span style="color:grey">@ remove processed items from input list</span>
4 ROLLD SWAP GET + <span style="color:grey">@ append range end to result </span>
'''ELSE''' <span style="color:grey">@ else</span>
DROP OVER HEAD + SWAP TAIL SWAP <span style="color:grey">@ append first item and remove it from input </span>
'''END'''
'''END'''
SWAP DROP
» '<span style="color:blue">→RNG</span>' STO

{ -6, -3, -2, -1, 0, 1, 3, 4, 5, 7, 8, 9, 10, 11, 14, 15, 17, 18, 19, 20 } <span style="color:blue">→RNG</span>
{{out}}
<pre>
1: "-6,-3-1,3-5,7-11,14,15,17-20"
</pre>
</pre>