Files
alexm e092cb029c
Build, test, deploy / site (push) Failing after 15m13s
Initial commit
2026-11-12 22:24:02 -05:00

27 lines
519 B
Plaintext

// CALL: COUNT_BASE('A', "GATTACA")
// EXPECT: COUNT_BASE returned 3
// How many positions of T hold the base B.
FUNCTION COUNT_BASE(B : CHAR, T : STRING) RETURNS INTEGER
// Set up
DECLARE N : INTEGER
DECLARE Total : INTEGER
N <- LENGTH(T)
Total <- 0
// Visit each position
FOR I <- 0 TO N
// Test this position
IF T[I] == B THEN
// Update the running total
Total <- Total + 1
ENDIF
NEXT I
// Report
RETURN Total
ENDFUNCTION