generated from mwc/lab_pipes
59 lines
3.4 KiB
Markdown
59 lines
3.4 KiB
Markdown
# Exercises
|
|
|
|
Answer the following questions (or at least as many as you can figure out) in this document.
|
|
For all the questions, use the 100k words. Give your answer for each exercise, and
|
|
show the command you used to get it. Each question can be answered using a single Terminal
|
|
command, though you might need to use a number of pipes.
|
|
|
|
If you want to be really stylish, put your code inside of backticks like this:
|
|
|
|
`cat words_100k.txt | length | put 10 | equal | count`
|
|
|
|
## 1. What is the longest word?
|
|
The longest word is "antidisestablishmentarianism."
|
|
I use the following command: `cat words_100k.txt | length | order -r | head -n 1 | pluck 1`
|
|
|
|
## 2. How many words have two u's in a row?
|
|
There are 16 words that have two u's in a row.
|
|
I used the following command: `cat words_100k.txt | match "uu" | count`
|
|
|
|
## 3. How many words have the word "cat" in them?
|
|
There are 893 words with the word "cat" in them.
|
|
I used the following command: `cat words_100k.txt | match "cat" | count`
|
|
|
|
## 4. How many words have all five vowels (aeiou)?
|
|
There are 812 words that have all five vowels.
|
|
I used the following command: `cat words_100k.txt | match "a" | match "e" | match "i" | match "o" | match "u" | count`
|
|
|
|
## 5. Which words have two l's in a row, two m's in a row, and two t's in a row? (they don't have to be in that order)
|
|
There are no words that have two l's in a row, two m's in a row, and two t's in a row.
|
|
I used the following command: `cat words_100k.txt | match "ll" | match "mm" | match "tt" | count`
|
|
|
|
## 6. How many words have sixteen or more letters?
|
|
There are 696 words that have sixteen or more letters.
|
|
I used the following command: `cat words_100k.txt | length | order -r | put 16 | lessthan 0 1 -e | count`
|
|
|
|
## 7. What's the most frequent 10-letter word?
|
|
The most frequent 10-letter word is "government."
|
|
I used the following command: `cat words_100k.txt | frequency | length 1 | put 10 | equal 0 1 | order 2 -r | head -n 1 | pluck 3`
|
|
|
|
## 8. What's the longest word which doesn't have any repeated letters?
|
|
The longest word that doesn't have any repeated letters is "salpingectomy," which has 13 letters.
|
|
I used the following command: `cat words_100k.txt | length | unique 1 | length | equal 0 2 | order -r | head -n 1 | pluck 3`
|
|
|
|
Edit: I found that there are four words with the same number of letters as "salpingectomy:"
|
|
"troublemaking"
|
|
"unproblematic"
|
|
"copyrightable"
|
|
"unpredictable"
|
|
I found these by manually counting the number of letters in salpingectomy and then using the following command: `cat words_100k.txt | length | unique 1 | length | equal 0 2 | order -r | head -n 10 | put 13 | equal | pluck 4`
|
|
I'm not sure if I hadn't thought to check how I would've known there were ties using the commands I had available to me.
|
|
|
|
## 9. What's the longest word which only uses four different letters?
|
|
The longest word that uses only four different letters is "senselessness."
|
|
I used the following command: `cat words_100k.txt | unique | length | put 4 | equal | length 3 | order -r | head -n 1 | pluck 4`
|
|
|
|
## 10. If you rearrange the letters in "sidebar," what other words can you create?
|
|
The other words that I can create by rearranging the letters in "sidebar" are: "braised" and "seabird."
|
|
I used the following command: `cat words_100k.txt | length | unique 1 | length | equal 0 2 | put 7 | equal | pluck 4 | match "s" | match "i" | match "d" | match "e" | match "b" | match "a" | match "r"`
|