22 lines
527 B
Mojo
22 lines
527 B
Mojo
# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
|
|
|
|
# How many positions of T hold the base B.
|
|
def count_base(b: String, t: String) -> Int:
|
|
# Set up
|
|
var n: Int
|
|
var total: Int
|
|
n = t.count_codepoints()
|
|
total = 0
|
|
# Visit each position
|
|
for i in range(n):
|
|
# Test this position
|
|
if String(t[codepoint=i]) == b:
|
|
# Update the running total
|
|
total = total + 1
|
|
# Report
|
|
return total
|
|
|
|
|
|
def main():
|
|
print(count_base("A", "GATTACA"))
|