Files
pplus-library/mojo/local/gc-fraction.mojo
T
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

17 lines
507 B
Mojo

# origin: Programming+ exercise gc-fraction
# status: unverified; `corpus.py verify` checks it on the pinned compiler
# probe: the fraction of t that is G or C, as a Float64
# expect-stdout: 0.2857142857142857
def gc_fraction(t: String) -> Float64:
# requires: |t| > 0
var gc = 0
for cp in t.codepoint_slices():
var b = String(cp)
if b == "G" or b == "C":
gc += 1
return Float64(gc) / Float64(t.count_codepoints())
def main():
print(gc_fraction("GATTACA"))