Skip to content

Commit c6cf21e

Browse files
committed
BruteForce.py finally approved
1 parent d431689 commit c6cf21e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
def brute_force(text, pattern):
2+
l1 = len(text)
3+
l2 = len(pattern)
4+
5+
i=0
6+
j=0
7+
8+
flag = False
9+
while i < l1:
10+
j = 0
11+
count = 0
12+
while j < l2:
13+
if i+j < l1 and text[i+j] == pattern[j]:
14+
count += 1
15+
j +=1
16+
if count == l2:
17+
print("\nPattern occurs at index ", i)
18+
flag = True
19+
i += 1
20+
if not flag:
21+
print('\nPattern is not at all present in the array')
22+
23+
24+
#Output of string matching with Brute force
25+
brute_force('acbcabccababcaacbcac','acbcac')

0 commit comments

Comments
 (0)