lab_pipes/exercises.md

1.9 KiB

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?

antidisestablishmentarianism cat words_100k.txt | length | order -r | head -n 1 | pluck 1

2. How many words have two u's in a row?

16 cat words_100k.txt | match "uu" | count

3. How many words have the word "cat" in them?

893 cat words_100k.txt | match "cat" | count

4. How many words have all five vowels (aeiou)?

812 cat words_100k.txt | unique | pluck 0 | match "a.*e.*i.*o.*u.*" | count

5. Which words have two e's in a row, two o's in a row, and two k's in a row? (they don't have to be in that order)

3 cat words_100k.txt | match "ee" | match "kk" | match "oo" | count

6. How many words have sixteen or more letters?

696 cat words_100k.txt | length | put 16 | lessthan -e | count

7. What's the most frequent 10-letter word?

9869 cat words_100k.txt | length | put 10 | equal | count

8. What's the longest word which doesn't have any repeated letters?

antidisestablishmentarianism cat words_100k.txt | length | order -r | head -n 1 | pluck 1

9. What's the longest word which only uses four different letters?

senselessness cat words_100k.txt | unique | length | put 4 | equal | pluck 3 | length | order -r | head -n 1 | pluck 1

10. If you rearrange the letters in "sidebar," what other words can you create?

braised and seabird cat words_100k.txt | length | put 7 | equal | pluck 2 | unique | match "a.*b.*d.*e.*i.*r.*s.*" | pluck 1