Baseline: tree as shared
This commit is contained in:
1679 files changed
+1024562
No files matched your search
@@ -0,0 +1,26 @@
|
||||
// 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
|
||||
Reference in new issue
Block a user