[personal profile] aranthe posting in [community profile] intro_to_cs

I'll be posting the remaining solutions over the next few days, as soon as I have time to finish reviewing them.

PS3: Problem 1 » Solutions

# Problem 1: countSubstringMatch, countSubstringMatchRecursive
def countSubStringMatch( target, key ):
    count = 0
    while target.find( key ) > -1:
        count += 1
        target = target[target.find( key ) + len( key ):]
    return count

def countSubStringMatchRecursive( target, key ):
    if target.find( key ) < 0:
        return 0
    else:
        return 1 + countSubStringMatchRecursive( target[(target.find( key ) + len(key)):], key )

Profile

Introduction to Computer Science

July 2010

S M T W T F S
    123
45678910
11121314151617
18192021222324
2526272829 3031

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 8th, 2025 09:59 am
Powered by Dreamwidth Studios