Jewels and stones: Difference between revisions

m
m (→‎{{header|Wren}}: Changed to Wren S/H)
Line 2,282:
say count('aAAbbbb', "aA")
say count('ZZ' , "z" )
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
count: procedure
count: procedure; parse arg stones,jewels /*obtain the two strings specified. */
#= 0 /*initialize the variable # to zero.*/
number= 0 do j=1 for length(stones) /*scaninitialize STONESnumber for matchingto JEWELS charszero.*/
do j=1 for length(stones) /*scan STONES for matching JEWELS chars*/
x= substr(stones, j, 1) /*obtain a character of the STONES var.*/
if datatype(x, 'M') then if pos(x, jewels)\==0 then #number= #number + 1
end /*j*/ /* [↑] if a letter and a match, bump #*/
end /*j*/ return # /* [↑] if a letter and a match, /*return thebump number of common letters. */</syntaxhighlight>
return number /*return the number of common letters. */
</syntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>3
41

edits