From a9e3232189d026f55a1e60cc3570fc7399cff9c9 Mon Sep 17 00:00:00 2001 From: RossTheRoss Date: Sat, 19 Oct 2019 23:12:35 -0500 Subject: Almost done --- csci1913/Python/project1_strap012.py | 17 +++++++++++------ 1 file 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()) -- cgit v1.2.3