SHOW:
|
|
- or go back to the newest paste.
1 | # the sounds in the language | |
2 | vowels = ["a", "e", "i", "o", "u"] | |
3 | consonants = ["m", "p", "f","t","s","k"] | |
4 | #vowels = ["u"] | |
5 | #consonants = ["k"] | |
6 | wordlength = 5 | |
7 | ||
8 | #imports | |
9 | from numpy import * | |
10 | ||
11 | #initial settings | |
12 | - | from array import * |
12 | + | |
13 | - | from numpy import * |
13 | + | |
14 | numberofvowels = len(vowels) | |
15 | numberofconsonants = len(consonants) | |
16 | - | a = zeros([pow(numberofsounds,wordlength),wordlength]) |
16 | + | numberofpossiblewords = pow(numberofsounds,wordlength) |
17 | ||
18 | #initial array settings | |
19 | a = zeros([numberofpossiblewords,wordlength]) | |
20 | - | while line < pow(numberofsounds,wordlength): |
20 | + | |
21 | #entire addition loop | |
22 | end = 0 | |
23 | line=1 | |
24 | while line < numberofpossiblewords: | |
25 | ||
26 | #var used for loop | |
27 | n = 0 | |
28 | #print "n="+str(n) | |
29 | while n <= wordlength-1: | |
30 | a[line,n] = a[line-1,n] | |
31 | n = n+1 | |
32 | #print "n="+str(n) | |
33 | #print a | |
34 | ||
35 | #add 1 to the last | |
36 | a[line,wordlength-1] = a[line,wordlength-1]+1 | |
37 | ||
38 | #loop that detect if a the number is too large | |
39 | m = wordlength-1 | |
40 | while m >= 0: | |
41 | - | m=m-1 |
41 | + | |
42 | a[line,m] = 0 | |
43 | a[line,m-1] = a[line,m-1]+1 | |
44 | ||
45 | m -= 1 | |
46 | ||
47 | line=line+1 | |
48 | #print "line="+str(line) | |
49 | ||
50 | #displaying the representation | |
51 | - | #code goes here |
51 | + | |
52 | print a | |
53 | ||
54 | #generating the words from the representation | |
55 | #converter | |
56 | def convert(input): | |
57 | return sounds[input] | |
58 | ||
59 | #fetcher | |
60 | def fetch(input1,input2): | |
61 | return a[input1,input2] | |
62 | ||
63 | #remove non-possible words | |
64 | line = 0 | |
65 | n = 0 | |
66 | - | while line < pow(numberofsounds,wordlength): |
66 | + | #loop thru all the lines |
67 | while line < numberofpossiblewords: | |
68 | #loop thru the colums | |
69 | while n < wordlength: | |
70 | #is it a consonant? | |
71 | if convert(int(a[line,n])) in consonants: | |
72 | #to avoid errors due to missing fields, i use three if-sentences | |
73 | ||
74 | #if the field is outermost to the left, hence only check the right side | |
75 | if n == 0 and wordlength > 1: | |
76 | #print "n=0" | |
77 | if convert(int(a[line,n+1])) in consonants: | |
78 | #if the field is in the middle | |
79 | - | print "number of different words is "+(str(pow(numberofsounds,wordlength))) |
79 | + | print "consonant in [%d,%d] has consonant on its right side and nothing on the other side" % (line,n) |
80 | if n != 0 and n != wordlength-1: | |
81 | #print "n>0 and <wordlength-1" | |
82 | if convert(int(a[line,n+1])) in consonants and convert(int(a[line,n-1])) in consonants: | |
83 | print "consonant in [%d,%d] has consonant on both its sides" % (line,n) | |
84 | ||
85 | #if the field is outermost to the right, hence only check the left side | |
86 | if n == wordlength-1 and wordlength>1: | |
87 | #print "n=wordlength-1" | |
88 | if convert(int(a[line,n-1])) in consonants: | |
89 | print "consonant in [%d,%d] has consonant on its left side and nothing on the other side" % (line,n) | |
90 | n += 1 | |
91 | #print "n got +1 and is now %d" % n | |
92 | line=line+1 | |
93 | n=0 | |
94 | #print "line got +1 and is now %d" % line | |
95 | ||
96 | #print words | |
97 | line = 0 | |
98 | ||
99 | print "The possible words are:" | |
100 | while line < numberofpossiblewords: | |
101 | word = "" | |
102 | n = 0 | |
103 | while n < wordlength: | |
104 | word = word + convert(int(fetch(line,n))) | |
105 | n=n+1 | |
106 | #print str(n) | |
107 | ||
108 | #print "line="+str(line) | |
109 | print word | |
110 | ||
111 | line=line+1 | |
112 | ||
113 | print "number of different words is "+(str(numberofpossiblewords)) |