Jewels and stones: Difference between revisions

add ABC
(add SETL)
(add ABC)
 
(4 intermediate revisions by 4 users not shown)
Line 388:
Result: 0
</pre>
=={{header|ABC}}==
<syntaxhighlight lang="abc">HOW TO RETURN stones count.in jewels:
PUT 0 IN count
FOR stone IN stones:
IF stone in jewels: PUT count+1 IN count
RETURN count
 
WRITE "aAAbbbb" count.in "aA"/
WRITE "ZZ" count.in "z"/</syntaxhighlight>
{{out}}
<pre>3
0</pre>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">with Ada.Text_IO;
Line 1,610 ⟶ 1,623:
<pre>Jewels.count("aAAbbbb", "aA") = 3
Jewels.count("ZZ", "z") = 0</pre>
 
=={{header|K}}==
<syntaxhighlight lang="k">jewels: +/~^?
 
jewels["aA";"aAAbbbb"]</syntaxhighlight>
{{out}}
<pre>3</pre>
 
=={{header|Kotlin}}==
<syntaxhighlight lang="scalakotlin">// Version 1.2.40
 
fun countJewels(s: String, j: String) = s.count { it in j }
Line 1,620 ⟶ 1,640:
println(countJewels("ZZ", "z"))
}</syntaxhighlight>
{{out}}
 
{{output}}
<pre>
3
Line 2,276 ⟶ 2,295:
0
</pre>
 
=={{header|Refal}}==
<syntaxhighlight lang="refal">$ENTRY Go {
= <Prout <Jewels ('aAAbbb') ('aA')>>
<Prout <Jewels ('ZZ') ('z')>>;
};
 
Jewels {
() (e.Jewels)
= 0;
(s.Stone e.Stones) (e.Jewels), e.Jewels: e.X s.Stone e.Y
= <+ 1 <Jewels (e.Stones) (e.Jewels)>>;
(s.Stone e.Stones) (e.Jewels)
= <Jewels (e.Stones) (e.Jewels)>;
};</syntaxhighlight>
{{out}}
<pre>3
0</pre>
 
=={{header|REXX}}==
Line 2,282 ⟶ 2,319:
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
Line 2,568 ⟶ 2,607:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">var countJewels = Fn.new { |s, j| s.count { |c| j.contains(c) } }
 
System.print(countJewels.call("aAAbbbb", "aA"))
2,114

edits