Skip to content

Commit 287636d

Browse files
committed
renamed markov_words to gibberish
1 parent c98e3fe commit 287636d

File tree

9 files changed

+29
-28
lines changed

9 files changed

+29
-28
lines changed

anagram/discussion.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ True
129129

130130
## Selecting words to compare
131131

132-
My first implementation of this program was quite naive and yet worked fine for find all other single words that were anagrams. Everything came crashing down when I attempted to find combinations. I suddenly realized the number of 2-word combinations I needed to check (that 55 *billion* I mentioned before). As it happened, I then rewatched "The Imitation Game" about Alan Turing and the creation of his machine ("Christopher") to crack the Enigma code which has a possible 150 million million possible states. He was unable to build a machine that could churn through that many possibilities in the 18 hours or so per day they had to find the right combination, so they had to find a way to cut down the number of combinations they attempted. Similarly, I realized I only needed to look at combinations of words whose lengths sum to the length of the given word; hency my decision to store `words` using the word length as the key and then as a `set` of words that length.
132+
My first implementation of this program was quite naive and yet worked fine for find all other single words that were anagrams. Everything came crashing down when I attempted to find combinations. I suddenly realized the number of 2-word combinations I needed to check (that 55 *billion* I mentioned before). As it happened, I then rewatched "The Imitation Game" about Alan Turing and the creation of his machine ("Christopher") to crack the Enigma code which has a possible 150 million million possible states. He was unable to build a machine that could churn through that many possibilities in the 18 hours or so per day they had to find the right combination, so they had to find a way to cut down the number of combinations they attempted. Similarly, I realized I only needed to look at combinations of words whose lengths sum to the length of the given word; hence my decision to store `words` using the word length as the key and then as a `set` of words that length.
133133

134134
Next I needed to find all combinations of numbers that add up to that number. Let's consider we are using "listen" as the `text`:
135135

@@ -216,7 +216,7 @@ Let's take the first combo:
216216
````
217217
>>> keys = key_combos[0]
218218
>>> keys
219-
(1, 3)
219+
(3, 3)
220220
````
221221

222222
And pretend we have a very small `words` list:
@@ -270,4 +270,4 @@ tin les
270270

271271
Some are repeated which is why I chose to create my `anagrams` holder as a `set` to make them unique.
272272

273-
In the end, I look to see how many `anagrams` I found using `len(anagrams)`. If there are some, I report how many and what they are in `sorted` order; otherwise I let the user know that none were found.
273+
In the end, I look to see how many `anagrams` I found using `len(anagrams)`. If there are some, I report how many and what they are in `sorted` order; otherwise I let the user know that none were found.

bin/chapters.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mommys_little_helper
2323
kentucky_friar
2424
mad_libs
2525
license_plates
26-
markov_words
26+
gibberish
2727
piggie
2828
soundex_rhymer
2929
substring

book.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4277,9 +4277,9 @@ In creating all the possible plates from your regular expression, you are making
42774277

42784278
\newpage
42794279

4280-
# Chapter 26: Markov Chains for Words
4280+
# Chapter 26: Gibberish Generator
42814281

4282-
Write a Python program called `markov.py` that uses the Markov chain algorithm to generate new words from a set of training files. The program should take one or more positional arguments which are files that you read, word-by-word, and note the options of letters after a given `-k|--kmer_size` (default `2`) grouping of letters. E.g., in the word "alabama" with `k=1`, the frequency table will look like:
4282+
Write a Python program called `gibberish.py` that uses the Markov chain algorithm to generate new words from a set of training files. The program should take one or more positional arguments which are files that you read, word-by-word, and note the options of letters after a given `-k|--kmer_size` (default `2`) grouping of letters. E.g., in the word "alabama" with `k=1`, the frequency table will look like:
42834283

42844284
````
42854285
a = l, b, m
@@ -4300,11 +4300,11 @@ Chose the best words and create definitions for them:
43004300
* urchenev: fungal growth found under cobblestones
43014301

43024302
````
4303-
$ ./markov.py
4304-
usage: markov.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
4305-
markov.py: error: the following arguments are required: FILE
4306-
$ ./markov.py -h
4307-
usage: markov.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
4303+
$ ./gibberish.py
4304+
usage: gibberish.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
4305+
gibberish.py: error: the following arguments are required: FILE
4306+
$ ./gibberish.py -h
4307+
usage: gibberish.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
43084308

43094309
Markov chain for characters/words
43104310

@@ -4321,7 +4321,7 @@ optional arguments:
43214321
Max word length (default: 12)
43224322
-s int, --seed int Random seed (default: None)
43234323
-d, --debug Debug to ".log" (default: False)
4324-
$ ./markov.py /usr/share/dict/words -s 1
4324+
$ ./gibberish.py /usr/share/dict/words -s 1
43254325
1: oveli
43264326
2: uming
43274327
3: uylatiteda
@@ -4332,7 +4332,7 @@ $ ./markov.py /usr/share/dict/words -s 1
43324332
8: eyhopy
43334333
9: auretrab
43344334
10: ozogralach
4335-
$ ./markov.py ../inputs/const.txt -s 2 -k 3
4335+
$ ./gibberish.py ../inputs/const.txt -s 2 -k 3
43364336
1: romot
43374337
2: leasonsusp
43384338
3: gdoned
@@ -4343,7 +4343,7 @@ $ ./markov.py ../inputs/const.txt -s 2 -k 3
43434343
8: nmentyone
43444344
9: effereof
43454345
10: eipts
4346-
$ ./markov.py -k 2 ../inputs/1945-boys.txt
4346+
$ ./gibberish.py -k 2 ../inputs/1945-boys.txt
43474347
1: baronaler
43484348
2: lip
43494349
3: oselli
@@ -5886,7 +5886,7 @@ True
58865886

58875887
## Selecting words to compare
58885888

5889-
My first implementation of this program was quite naive and yet worked fine for find all other single words that were anagrams. Everything came crashing down when I attempted to find combinations. I suddenly realized the number of 2-word combinations I needed to check (that 55 *billion* I mentioned before). As it happened, I then rewatched "The Imitation Game" about Alan Turing and the creation of his machine ("Christopher") to crack the Enigma code which has a possible 150 million million possible states. He was unable to build a machine that could churn through that many possibilities in the 18 hours or so per day they had to find the right combination, so they had to find a way to cut down the number of combinations they attempted. Similarly, I realized I only needed to look at combinations of words whose lengths sum to the length of the given word; hency my decision to store `words` using the word length as the key and then as a `set` of words that length.
5889+
My first implementation of this program was quite naive and yet worked fine for find all other single words that were anagrams. Everything came crashing down when I attempted to find combinations. I suddenly realized the number of 2-word combinations I needed to check (that 55 *billion* I mentioned before). As it happened, I then rewatched "The Imitation Game" about Alan Turing and the creation of his machine ("Christopher") to crack the Enigma code which has a possible 150 million million possible states. He was unable to build a machine that could churn through that many possibilities in the 18 hours or so per day they had to find the right combination, so they had to find a way to cut down the number of combinations they attempted. Similarly, I realized I only needed to look at combinations of words whose lengths sum to the length of the given word; hence my decision to store `words` using the word length as the key and then as a `set` of words that length.
58905890

58915891
Next I needed to find all combinations of numbers that add up to that number. Let's consider we are using "listen" as the `text`:
58925892

@@ -5973,7 +5973,7 @@ Let's take the first combo:
59735973
````
59745974
>>> keys = key_combos[0]
59755975
>>> keys
5976-
(1, 3)
5976+
(3, 3)
59775977
````
59785978

59795979
And pretend we have a very small `words` list:
@@ -6028,6 +6028,7 @@ tin les
60286028
Some are repeated which is why I chose to create my `anagrams` holder as a `set` to make them unique.
60296029

60306030
In the end, I look to see how many `anagrams` I found using `len(anagrams)`. If there are some, I report how many and what they are in `sorted` order; otherwise I let the user know that none were found.
6031+
60316032
\newpage
60326033

60336034
# Chapter 34: Hangman

gibberish/.log

Whitespace-only changes.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Markov Chains for Words
1+
# Gibberish Generator
22

3-
Write a Python program called `markov.py` that uses the Markov chain algorithm to generate new words from a set of training files. The program should take one or more positional arguments which are files that you read, word-by-word, and note the options of letters after a given `-k|--kmer_size` (default `2`) grouping of letters. E.g., in the word "alabama" with `k=1`, the frequency table will look like:
3+
Write a Python program called `gibberish.py` that uses the Markov chain algorithm to generate new words from a set of training files. The program should take one or more positional arguments which are files that you read, word-by-word, and note the options of letters after a given `-k|--kmer_size` (default `2`) grouping of letters. E.g., in the word "alabama" with `k=1`, the frequency table will look like:
44

55
````
66
a = l, b, m
@@ -21,11 +21,11 @@ Chose the best words and create definitions for them:
2121
* urchenev: fungal growth found under cobblestones
2222

2323
````
24-
$ ./markov.py
25-
usage: markov.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
26-
markov.py: error: the following arguments are required: FILE
27-
$ ./markov.py -h
28-
usage: markov.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
24+
$ ./gibberish.py
25+
usage: gibberish.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
26+
gibberish.py: error: the following arguments are required: FILE
27+
$ ./gibberish.py -h
28+
usage: gibberish.py [-h] [-n int] [-k int] [-m int] [-s int] [-d] FILE [FILE ...]
2929
3030
Markov chain for characters/words
3131
@@ -42,7 +42,7 @@ optional arguments:
4242
Max word length (default: 12)
4343
-s int, --seed int Random seed (default: None)
4444
-d, --debug Debug to ".log" (default: False)
45-
$ ./markov.py /usr/share/dict/words -s 1
45+
$ ./gibberish.py /usr/share/dict/words -s 1
4646
1: oveli
4747
2: uming
4848
3: uylatiteda
@@ -53,7 +53,7 @@ $ ./markov.py /usr/share/dict/words -s 1
5353
8: eyhopy
5454
9: auretrab
5555
10: ozogralach
56-
$ ./markov.py ../inputs/const.txt -s 2 -k 3
56+
$ ./gibberish.py ../inputs/const.txt -s 2 -k 3
5757
1: romot
5858
2: leasonsusp
5959
3: gdoned
@@ -64,7 +64,7 @@ $ ./markov.py ../inputs/const.txt -s 2 -k 3
6464
8: nmentyone
6565
9: effereof
6666
10: eipts
67-
$ ./markov.py -k 2 ../inputs/1945-boys.txt
67+
$ ./gibberish.py -k 2 ../inputs/1945-boys.txt
6868
1: baronaler
6969
2: lip
7070
3: oselli
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env python3
2-
"""tests for markov.py"""
2+
"""tests for gibberish.py"""
33

44
import os
55
import re
66
import random
77
import string
88
from subprocess import getstatusoutput, getoutput
99

10-
prg = './markov.py'
10+
prg = './gibberish.py'
1111
const = '../inputs/const.txt'
1212
dickinson = '../inputs/dickinson.txt'
1313

playful_python.pdf

26 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)