-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob72.py
More file actions
40 lines (33 loc) · 1.18 KB
/
Copy pathprob72.py
File metadata and controls
40 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
Funny Words Generator
Generate randome words where letters at odd positions are consonants and
letters at even positions are vowels. Exclude 'q' and 'y'
"""
__author__ = 'Vince'
import prob25
def funny_word_generator(random_nums):
"""
Converts a list of random numbers into a 'funny word'
:param random_nums:
:return funny_word:
"""
vowels = 'aeiou'
consonants = 'bcdfghjklmnprstvwxz'
funny_word = ''
for idx, number in enumerate(random_nums):
if idx % 2 != 0:
funny_word += vowels[number % 5]
else:
funny_word += consonants[number % 19]
return funny_word
with open('test.txt') as data_file:
N, x0 = map(int, data_file.readline().strip().split())
word_length_list = map(int, data_file.readline().split())
# From problem statement: for LCG A = 445, C = 700001, M = 2097152
random_params = [445, 700001, 2097152, x0, sum(word_length_list)]
random_gen = prob25.lcg_random(random_params)
for word_length in word_length_list:
random_numbers = []
for num in range(word_length):
random_numbers.append(next(random_gen))
print funny_word_generator(random_numbers),