1
1
"""
2
- Context:
3
- Given:
4
- method isSubstring
5
- checks if one word is a substring of another
6
-
7
- Definitions:
8
- rotation = letters moved n places left/right
9
- split string into two parts
10
- x,y
11
- rotated string = yx
12
- original string = xy
13
- --------------------------------------
14
- s1 = abcd
15
- s2 = cdab
16
-
17
- s1
18
- x = ab
19
- y = cd
20
- yx = cdab = s2
21
-
22
- is not:
23
- shuffling letters into arbitary positions
24
-
25
- Objective:
26
- Given two strings
27
- s1 and s2
28
-
29
- Write Algorithm to check
30
- if s2 is a
31
- rotation
32
- of s1
33
-
34
- Assumptions:
35
- s1 and s2 are same length
36
- Constraints:
37
- Only 1 call to isSubstring
38
-
39
- Algorithm flow:
40
- Using definition of rotation
41
- yxyx contains xy
42
- cdabcd contains abcd
43
-
44
- Flow:
45
- s2contact = concat s2 and s2
46
- check if s1 isSubstring of s2contact
47
- Possible Solutions
48
-
49
- Example(s):
2
+ Context:
3
+ Given:
4
+ method isSubstring
5
+ checks if one word is a substring of another
6
+
7
+ Definitions:
8
+ rotation = letters moved n places left/right
9
+ split string into two parts
10
+ x,y
11
+ rotated string = yx
12
+ original string = xy
13
+ --------------------------------------
14
+ s1 = abcd
15
+ s2 = cdab
16
+
17
+ s1
18
+ x = ab
19
+ y = cd
20
+ yx = cdab = s2
21
+
22
+ is not:
23
+ shuffling letters into arbitary positions
24
+
25
+ Objective:
26
+ Given two strings
27
+ s1 and s2
28
+
29
+ Write Algorithm to check
30
+ if s2 is a
31
+ rotation
32
+ of s1
33
+
34
+ Assumptions:
35
+ s1 and s2 are same length
36
+ Constraints:
37
+ Only 1 call to isSubstring
38
+
39
+ Algorithm flow:
40
+ Using definition of rotation
41
+ yxyx contains xy
42
+ cdabcd contains abcd
43
+
44
+ Flow:
45
+ s2contact = concat s2 and s2
46
+ check if s1 isSubstring of s2contact
47
+ Possible Solutions
48
+
49
+ Example(s):
50
50
51
51
52
52
"""
@@ -59,10 +59,10 @@ def is_substring(search_string, source_string):
59
59
return is_substring (s1 , s2 + s2 )
60
60
61
61
62
- assert ( string_rotation ("waterbottle" , "erbottlewat" ) ) # True
63
- assert ( string_rotation ("abcd" , "cdab" ) ) # True
64
- assert ( not string_rotation ("abcd" , "cdaob" ) ) # False
65
- assert ( not string_rotation ("abcd" , "" ) ) # False
62
+ assert string_rotation ("waterbottle" , "erbottlewat" ) # True
63
+ assert string_rotation ("abcd" , "cdab" ) # True
64
+ assert not string_rotation ("abcd" , "cdaob" ) # False
65
+ assert not string_rotation ("abcd" , "" ) # False
66
66
print ("completed successfully" )
67
67
68
68
"""
0 commit comments