---
jupyter:
jupytext:
- formats: ipynb,md,py:percent
+ formats: ipynb,md
text_representation:
extension: .md
format_name: markdown
, ie_limit: int = 3
, ii_limit: int = 2
, ee_limit: int = 2) -> (RiddleClue, RiddleClue):
- r = random.random()
- if r <= 0.7:
+ clue_type = random.choices(['include_exclude', 'include_include', 'exclude_exclude'],
+ weights=[7, 2, 1],
+ k=1)[0]
+ if clue_type == 'include_exclude':
return include_exclude_clue(letter, limit=ie_limit)
- elif r <= 0.9:
+ elif clue_type =='include_include':
return include_include_clue(letter, limit=ii_limit)
else:
return exclude_exclude_clue(letter, limit=ee_limit)
```
```python
-def random_riddle(word: str, limit: int = 3) -> Riddle:
- return {i+1 : random_clue(l, ie_limit=limit)
+def random_riddle( word: str
+ , ie_limit: int = 3
+ , ii_limit: int = 2
+ , ee_limit: int = 2
+ ) -> Riddle:
+ return {i+1 :
+ random_clue(l,
+ ie_limit=ie_limit, ii_limit=ii_limit, ee_limit=ee_limit)
for i, l in enumerate(word)}
```
```python
-sample_riddle = random_riddle('sonnet')
+sample_riddle = random_riddle('teacup')
sample_riddle
```
-```python
-
-```
-
-```python
-sample_riddle = random_riddle('sonnet', limit=4)
-sample_riddle
-```
-
-```python
-sample_riddle
-```
-
-```python
-collapse_riddle_clues(sample_riddle)
-```
-
```python
solve_riddle(collapse_riddle_clues(sample_riddle))
```
return riddle
```
+```python
+import time
+import csv
+reports = []
+for _ in range(1000):
+ w1, c1 = time.perf_counter(), time.process_time()
+ r = valid_random_riddle(random.choice(dictionary))
+ w2, c2 = time.perf_counter(), time.process_time()
+ linecount = len(r)
+ reports.append({'wall_time': w2 - w1,
+ 'cpu_time': c2 - c1,
+ 'riddle_lines': linecount})
+ w_times.append(w2 - w1)
+ c_times.append(c2 - c1)
+
+with open('metrics_original.csv', 'w', newline='') as csvfile:
+ fieldnames = list(reports[0].keys())
+ writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
+
+ writer.writeheader()
+ for r in reports:
+ writer.writerow(r)
+```
+
```python
def write_include_exclude_line(clue_a: RiddleClue, clue_b: RiddleClue) -> str:
line = f"is in {clue_a.word} but not in {clue_b.word}"
```python
def write_include_include_line(clue_a: RiddleClue, clue_b: RiddleClue) -> str:
- line = f"is in {clue_a.word} and also in {clue_b.word}"
+ if random.randrange(2) == 0:
+ line = f"is in {clue_a.word} and also in {clue_b.word}"
+ else:
+ line = f"is in both {clue_a.word} and {clue_b.word}"
return line
```