Count occurrences of a substring: Difference between revisions

→‎{{header|RPL}}: simple, idiomatic version
(→‎{{header|RPL}}: simple, idiomatic version)
Line 3,299:
=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
DUP2DUP SIZE 1 -sstr substr tsubsize
SIZE SWAP SIZE 0
'''IF''' DUP21 *str LASTSIZE subsize AND+ '''THENFOR''' j
SWAP - 1str +j 0DUP subsize + R→CSUB
'''WHILEIF''' DUP RE 0substr >== '''REPEATTHEN'''
s OVER RE DUP t SIZE1 + 1 - SUB
'''IF''' t ==j '''THEN'''subsize t SIZE -1 R→C -+ '''ELSE''j' (1,0) - '''END'''STO
'''END'''
IM'''NEXT'''
≫ ≫ '<span style="color:blue">CNTSUB</span>' STO
'''ELSE''' DROP2 -1 '''END'''
 
≫ ≫ ''''CNTSUB'''' STO
"the three truths" <span style="color:blue">CNTSUB</span>
"ababababab" <span style="color:blue">CNTSUB</span>
{{out}}
<pre>
2: 3
1: 2
</pre>
 
=={{header|Ruby}}==
1,151

edits