Share your repls and programming experiences

← Back to all posts
11
Pattern Finder

https://repl.it/@johnj/pattern-finder. Put in a sequence of characters, and it will try to find a pattern! (it can only do simple ones like 121212, where it is obvious, not 121314, where it is one, followed by an increasing number.) only sort of ai, but close enough!

Note: it will only find repeating patterns.

Commentshotnewtop
1

This is what it would look like if you said this is the pattern:

sequence = input('put your sequence here: ')
sequence.split()

a = 2
pattern_types = []
patterns_found = 0
while True:
find = []
find2 = []
find3 = []
b = 0
c = 0
d = len(sequence) // a
for i in range(d):
find.append(sequence[b])
b += 1
for i in range(d):
find2.append(sequence[b])
b += 1
if len(sequence) - (d 2) != 0:
for i in range(len(sequence) - (d
2)):
find3.append(sequence[b])
b += 1
if find == find2:
if len(find3) <= len(find):
for i in range(len(find3)):
if find[c] == find3[c]:
c += 1
else:
print('We did not find a pattern.')
break
if c == len(find3):
patterns_found += 1
pattern_types.append('repeating pattern')
print('We found a pattern!')
print("The pattern was: " , sequence)
break
else:
a += 1
b = 0
d = len(sequence) // a
if d == -1:
print('we did not find a pattern.')
break

def find_pattern():
global find
simple = []
simple1 = []
a1 = 0
a2 = -1
while True:
if len(find) % 2 == 0:
times = len(find) / 2
for i in range(times):
simple.append(find[a1])
simple1.append(find[a2])
a1 += 1
a2 -= 2
if simple == simple1:
find = simple
find_pattern()
else:
print(simple)

1

@SebastianCooke yeah... that would be because I had to stop in the middle of a line... I'll change that.

1

Hi there,

Your program tells us if it found a pattern or not -- but it should also tell us the pattern!

Maka

2

@themaka HEY! Good Idea! I'll work on that.