Skip to content

Instantly share code, notes, and snippets.

@adusak
Created June 2, 2015 17:57
Show Gist options
  • Select an option

  • Save adusak/544a323a6a7cde19bff9 to your computer and use it in GitHub Desktop.

Select an option

Save adusak/544a323a6a7cde19bff9 to your computer and use it in GitHub Desktop.
Checks wheather numbers are random
def analyze():
files = []
for i in range(1, 8):
file = open("random/random" + str(i) + ".txt")
read_file = file.read()
files.append(read_file)
for i in range(len(files)):
read_file = files[i]
if read_file != files[0]:
print("\n")
print("File:", str(i + 1))
for j in range(1, 7):
count = read_file.count(str(j))
print(str(j) + ":", count, (" " if count > 1000 else " ") + "sequence:",
sequence_length(str(j), read_file))
# Check a number of sequences of the same character and the length of sequence
def sequence_length(a, _str):
_input = _str.replace(" ", "")
result = {}
i = 0
while i < len(_input):
char = _input[i]
index = 0
count = 0
while char == a or char == " ":
if char != " ":
count += 1
index += 1
if i + index < len(_input):
char = _input[i + index]
else:
break
if count > 1:
if count not in result.keys():
result[count] = 0
result[count] += 1
i += 1
return result
analyze()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment