aboutsummaryrefslogtreecommitdiffstats
path: root/csci1913/Python
diff options
context:
space:
mode:
authorRossTheRoss <msattr@gmail.com>2019-10-19 23:12:35 -0500
committerRossTheRoss <msattr@gmail.com>2019-10-19 23:12:35 -0500
commita9e3232189d026f55a1e60cc3570fc7399cff9c9 (patch)
treeec31ba4c5f2305f69e433cbe943e1eae5e21ec60 /csci1913/Python
parentFeature-complete but not perfect (diff)
downloadhomework-a9e3232189d026f55a1e60cc3570fc7399cff9c9.tar
homework-a9e3232189d026f55a1e60cc3570fc7399cff9c9.tar.gz
homework-a9e3232189d026f55a1e60cc3570fc7399cff9c9.tar.bz2
homework-a9e3232189d026f55a1e60cc3570fc7399cff9c9.tar.lz
homework-a9e3232189d026f55a1e60cc3570fc7399cff9c9.tar.xz
homework-a9e3232189d026f55a1e60cc3570fc7399cff9c9.tar.zst
homework-a9e3232189d026f55a1e60cc3570fc7399cff9c9.zip
Almost done
Diffstat (limited to 'csci1913/Python')
-rw-r--r--csci1913/Python/project1_strap012.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/csci1913/Python/project1_strap012.py b/csci1913/Python/project1_strap012.py
index e0c73bb..8355400 100644
--- a/csci1913/Python/project1_strap012.py
+++ b/csci1913/Python/project1_strap012.py
@@ -50,12 +50,17 @@ class Grammar:
def select(self, left):
rules=self.dictionary[left]
- total=len(rules)
- index=self.r.choose(total)
- chosen=rules[0] #Debug Kludge
+ total=0
+ chosenOne=0
+ for m in range (0, len(rules)):
+ total+=rules[m].count
+ index = self.r.choose(total)
+ chosen=rules[0]
while index > 0:
- chosen=rules[index]
- index-=rules[index].count
+ index-=rules[chosenOne].count
+ chosenOne+=1
+ else:
+ chosen=rules[chosenOne]
for n in range (0, len(rules)):
if rules[n] is not chosen:
rules[n].count+=1
@@ -88,4 +93,4 @@ G.rule('Story', ('Phrase', 'and', 'Story')) # 10
G.rule('Story', ('Phrase', 'but', 'Story')) # 11
G.rule('Start', ('Story', '.')) # 12
for n in range (0,5):
- print(G.generate()) \ No newline at end of file
+ print(G.generate())