-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiglatin.py
40 lines (28 loc) · 897 Bytes
/
piglatin.py
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
40
import numpy as np
def ScorePigLatin(beforeword, afterword):
if(afterword[-2:] != "ay"):
return False
transposed = beforeword[1:] + beforeword[0]
if(transposed != afterword[:-2]):
return False
return True
def ConvertWord(word):
x = 0
while(True):
x = x + 1
ss = np.random.permutation(list(word))
qq = ""
for i in ss:
qq = qq + i
qq = qq + "ay"
if(ScorePigLatin(word, qq)):
#print(qq + " discovered in " + str(x) + " iterations.")
return qq
def ConvertSentence(sentence):
if(sentence == ""):
return "Error: empty input sentence."
RetSentence = ""
for word in str.split(sentence):
RetSentence = RetSentence + ConvertWord(word) + " "
return RetSentence[0:-1]
print(ConvertSentence("the quick brown"))