Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # the sounds in the language
- vowels = ["a", "e", "i", "o", "u"]
- consonants = ["m", "p", "f","t","s","k"]
- #vowels = ["u"]
- #consonants = ["k"]
- wordlength = 5
- #imports
- from numpy import *
- #initial settings
- sounds = vowels+consonants
- numberofsounds = len(sounds)
- numberofvowels = len(vowels)
- numberofconsonants = len(consonants)
- numberofpossiblewords = pow(numberofsounds,wordlength)
- #initial array settings
- a = zeros([numberofpossiblewords,wordlength])
- #entire addition loop
- end = 0
- line=1
- while line < numberofpossiblewords:
- #var used for loop
- n = 0
- #print "n="+str(n)
- while n <= wordlength-1:
- a[line,n] = a[line-1,n]
- n = n+1
- #print "n="+str(n)
- #print a
- #add 1 to the last
- a[line,wordlength-1] = a[line,wordlength-1]+1
- #loop that detect if a the number is too large
- m = wordlength-1
- while m >= 0:
- if a[line, m] > numberofsounds-1 and m != 0:
- a[line,m] = 0
- a[line,m-1] = a[line,m-1]+1
- m -= 1
- line=line+1
- #print "line="+str(line)
- #displaying the representation
- print "numerical representation is"
- print a
- #generating the words from the representation
- #converter
- def convert(input):
- return sounds[input]
- #fetcher
- def fetch(input1,input2):
- return a[input1,input2]
- #remove non-possible words
- line = 0
- n = 0
- #loop thru all the lines
- while line < numberofpossiblewords:
- #loop thru the colums
- while n < wordlength:
- #is it a consonant?
- if convert(int(a[line,n])) in consonants:
- #to avoid errors due to missing fields, i use three if-sentences
- #if the field is outermost to the left, hence only check the right side
- if n == 0 and wordlength > 1:
- #print "n=0"
- if convert(int(a[line,n+1])) in consonants:
- #if the field is in the middle
- print "consonant in [%d,%d] has consonant on its right side and nothing on the other side" % (line,n)
- if n != 0 and n != wordlength-1:
- #print "n>0 and <wordlength-1"
- if convert(int(a[line,n+1])) in consonants and convert(int(a[line,n-1])) in consonants:
- print "consonant in [%d,%d] has consonant on both its sides" % (line,n)
- #if the field is outermost to the right, hence only check the left side
- if n == wordlength-1 and wordlength>1:
- #print "n=wordlength-1"
- if convert(int(a[line,n-1])) in consonants:
- print "consonant in [%d,%d] has consonant on its left side and nothing on the other side" % (line,n)
- n += 1
- #print "n got +1 and is now %d" % n
- line=line+1
- n=0
- #print "line got +1 and is now %d" % line
- #print words
- line = 0
- print "The possible words are:"
- while line < numberofpossiblewords:
- word = ""
- n = 0
- while n < wordlength:
- word = word + convert(int(fetch(line,n)))
- n=n+1
- #print str(n)
- #print "line="+str(line)
- print word
- line=line+1
- print "number of different words is "+(str(numberofpossiblewords))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement