Tuesday, February 2, 2021

Factorials and unscrambling words with bash on Linux

In this post, we examine a bash script that takes a string of letters, rearranges them in every possible way and checks each permutation to identify those that are English words. In the process, we'll take a close look at the script and calculate how hard it might have to work.

Note that, in the algorithm used, each letter arrangement must use all of the letters in the string provided. Words formed by substrings are not considered.

First, the script expects the scrambled string to be provided as an argument and prompts for it if none is provided. It then checks out each arrangement of letters to find those that exist in the system's words file – in this case, that's /usr/share/dict/words. Here are the first lines in the script:

To read this article in full, please click here

Thanks to Sandra Henry-Stocker (see source)

No comments:

Post a Comment