Jewels and stones: Difference between revisions

m
Grouping BASIC dialects
(→‎Joy: add)
m (Grouping BASIC dialects)
Line 457:
 
=={{header|BASIC}}==
 
<syntaxhighlight lang="basic">10 READ N%
20 FOR A%=1 TO N%
Line 480 ⟶ 479:
 
{{out}}
 
<pre>aAAbbbb in aA: 3
ZZZZ in z: 0</pre>
 
==={{header|BASIC256}}===
<syntaxhighlight lang="basic256vb">
function contar_joyas(piedras, joyas)
cont = 0
Line 504 ⟶ 502:
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="vb">
function contar_joyas(piedras as string, joyas as string) as integer
dim as integer bc, cont = 0
for i as integer = 1 to len(piedras)
bc = instr(1, joyas, mid(piedras, i, 1))
if bc <> 0 then cont += 1
next i
contar_joyas = cont
end function
 
print contar_joyas("aAAbbbb", "aA")
print contar_joyas("ZZ", "z")
print contar_joyas("ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz", _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz")
print contar_joyas("AB", "")
</syntaxhighlight>
{{out}}
<pre>3
0
53
0</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">window 1, @"Jewels and Stones"
 
local fn JewelsAndStones( jewels as CFStringRef, stones as CFStringRef ) as long
long index, count = 0
for index = 0 to len(stones) - 1
if ( fn StringContainsString( jewels, mid(stones,index,1) ) ) then count++
next
end fn = count
 
print fn JewelsAndStones( @"aA", @"aAAbbbb" )
print fn JewelsAndStones( @"z", @"ZZ" )
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>3
0</pre>
 
==={{header|VBA}}===
{{trans|Phix}}<syntaxhighlight lang="vb">Function count_jewels(stones As String, jewels As String) As Integer
Dim res As Integer: res = 0
For i = 1 To Len(stones)
res = res - (InStr(1, jewels, Mid(stones, i, 1), vbBinaryCompare) <> 0)
Next i
count_jewels = res
End Function
Public Sub main()
Debug.Print count_jewels("aAAbbbb", "aA")
Debug.Print count_jewels("ZZ", "z")
End Sub</syntaxhighlight>{{out}}
<pre> 3
0 </pre>
 
==={{header|Visual Basic .NET}}===
{{trans|C#}}
<syntaxhighlight lang="vbnet">Module Module1
 
Function Count(stones As String, jewels As String) As Integer
Dim bag = jewels.ToHashSet
Return stones.Count(AddressOf bag.Contains)
End Function
 
Sub Main()
Console.WriteLine(Count("aAAbbbb", "Aa"))
Console.WriteLine(Count("ZZ", "z"))
End Sub
 
End Module</syntaxhighlight>
{{out}}
<pre>3
0</pre>
 
 
=={{header|BCPL}}==
Line 821 ⟶ 896:
0
4 -- 1 is found once, "Boo" is found once, and 3 is found twice = 4 things in the search list were found in the target list
</pre>
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
function contar_joyas(piedras as string, joyas as string) as integer
dim as integer bc, cont: cont = 0
for i as integer = 1 to len(piedras)
bc = instr(1, joyas, mid(piedras, i, 1))
if bc <> 0 then cont += 1
next i
contar_joyas = cont
end function
 
print contar_joyas("aAAbbbb", "aA")
print contar_joyas("ZZ", "z")
print contar_joyas("ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz", _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz")
print contar_joyas("AB", "")
</syntaxhighlight>
{{out}}
<pre>
3
0
53
0
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">window 1, @"Jewels and Stones"
 
local fn JewelsAndStones( jewels as CFStringRef, stones as CFStringRef ) as long
long index, count = 0
for index = 0 to len(stones) - 1
if ( fn StringContainsString( jewels, mid(stones,index,1) ) ) then count++
next
end fn = count
 
print fn JewelsAndStones( @"aA", @"aAAbbbb" )
print fn JewelsAndStones( @"z", @"ZZ" )
 
HandleEvents</syntaxhighlight>
{{out}}
<pre>
3
0
</pre>
 
Line 1,931 ⟶ 1,960:
0
</pre>
 
=={{header|VBA}}==
{{trans|Phix}}<syntaxhighlight lang="vb">Function count_jewels(stones As String, jewels As String) As Integer
Dim res As Integer: res = 0
For i = 1 To Len(stones)
res = res - (InStr(1, jewels, Mid(stones, i, 1), vbBinaryCompare) <> 0)
Next i
count_jewels = res
End Function
Public Sub main()
Debug.Print count_jewels("aAAbbbb", "aA")
Debug.Print count_jewels("ZZ", "z")
End Sub</syntaxhighlight>{{out}}
<pre> 3
0 </pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<syntaxhighlight lang="vbnet">Module Module1
 
Function Count(stones As String, jewels As String) As Integer
Dim bag = jewels.ToHashSet
Return stones.Count(AddressOf bag.Contains)
End Function
 
Sub Main()
Console.WriteLine(Count("aAAbbbb", "Aa"))
Console.WriteLine(Count("ZZ", "z"))
End Sub
 
End Module</syntaxhighlight>
{{out}}
<pre>3
0</pre>
 
=={{header|V (Vlang)}}==
2,130

edits