Anagram Finder

An anagram of a word or phrase is the result of rearranging its letters to form another meaningful word or phrase. For example, an anagram of “anagram finder” is “garden in a farm” (work it out!).

This page describes, in Unix manual page style, a C++ program available for downloading from this site which finds English language anagrams for a phrase. The program is available as source code compatible with any current C++ compiler or as a ready-to-run 32-bit Windows executable.

Anagrams are generated based on the official dictionary (second edition) of that crossword game whose name you cannot mention without having lawyers burst out of your screen brandishing menacing documents, courtesy of Grady Ward's Moby Words compilation. We search the dictionary in decreasing order of word length, as longer words tend to produce more interesting anagrams. Only alphabetic characters are considered in anagrams, and accented characters are “flattened” by removing the accents.

Users may create their own dictionaries from word lists; this permits supporting other languages and vocabularies, for example, using only words which appeared in the works of Shakespeare. If you create interesting dictionaries and wish to share them, please get in touch—we'll be glad to host them on this site.


NAME

anagram – find anagrams for phrase

SYNOPSIS

anagram [ options ] [ 'target phrase' [ seed… ] ]

DESCRIPTION

anagram finds anagrams or permutations of words in the target phrase. If one or more seed words is given, only anagrams containing all of those words will be shown. The target and seed may be specified by options or CGI program environment variables as well as on the command line.

OPTIONS

Options are specified on the command line prior to the input and output file names (if any). Options may appear in any order. Long options beginning with “--” may be abbreviated to any unambiguous prefix; single-letter options introduced by a single “-” may be aggregated.

--all
Generate all anagrams in --cgi --step 2.
--bail
Bail out after the first anagram found containing a word. In many cases this drastically reduces the time required to run the program. You can review the list of words appearing in anagrams and then request a complete list of anagrams containing “interesting” ones.
--bindict, -b file
Load binary dictionary from file. The default binary dictionary is wordlist.bin.
--cgi
When executed as a CGI program on a Web server, set options from form fields. These settings may be overridden by command line options which follow --cgi.
--copyright
Print copying information.
--dictionary, -d file
Load word list from file. This is (only) used with the --export option to compile a word list into a binary dictionary. The default word list is crossword.txt.
--export file
Create a binary dictionary file from the word list specified by the --dictionary option or the default crossword.txt.
--help, -u
Print how-to-call information including a list of options.
--html, -h
Generate HTML output when run as a CGI program on a Web server. The HTML is based on the template file specified by the --template option, which defaults to a file named template.html in the current directory.
--permute, -p 'phrase'
Print all permutations of words in the given phrase. The phrase must be quoted so that blanks separating words are considered part of the single phrase argument.
--seed, -s word
Find only anagrams which contain the specified word. You may specify as many seed words as you wish (each with a separate --seed option) to restrict the anagrams to those containing all of the seed words. To obtain a list of words which appear in anagrams of a phrase, specify the --bail option. You can also specify seed words on the command line after the options and target phrase, if any.
--step number
Perform step number when operating as a CGI program on a Web server. Step 0, the default, selects non-CGI operation; the program acts as a command line utility. In step 1, a list of words appearing in anagrams is generated. Step 2 generates anagrams in which a selected word appears (or, all anagrams if the HTML template permits this option). Step 3 generates all permutations of words in a selected anagram.
--target, -t 'phrase'
Generate anagrams or permutations for the specified phrase, which must be quoted if it contains more than a single word. If no --target is specified, the program uses the first command line argument as the target.
--verbose, -v
Print diagnostic information as the program performs various operations.
--version
Print program version information.

FILES

Output is written to standard output and may be redirected or piped to another program in the usual manner. When generating HTML as a CGI program, it is the responsibility of the shell script which invokes anagram to emit the Content-type: text/html and blank line which precedes the HTML. This permits changing the type to text/plain for debugging.

BUGS

The standard dictionary includes many extremely obscure words, including all the curious short words permitted in That Crossword Game. Consequently, anagrams of phrases with many high-frequency letters will often include these words. Sorting through them all can be tedious and (see below) time consuming. Somebody ought to edit the dictionary and create an “interesting word” list which excludes the esoterica.

Long phrases containing many high-frequency letters may have tens or hundreds of millions of anagrams, not counting permutations. If you launch such a search, be aware of the potential consequences. If you're setting up the program on a server, you may want to limit the resources it can consume.

If you find errors in this program or document, please report them to Bravo Uniform Golf Sierra @ Foxtrot Oscar Uniform Romeo Mike India Lima Alpha Bravo Decimal Charlie Hotel. If you don't have any idea what I just said, please consult this document.

Download

*   anagram C++ source code: anagram-1.5.tar.gz
*   Ready-to-run 32-bit Windows executable (Zipped archive): anagram.zip
*   Read anagram user documentation and source code [PDF]
*   anagram source code repository at GitHub

Prior releases remain available.

AUTHOR

John Walker
http://www.fourmilab.ch/

This software is in the public domain. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, without any conditions or restrictions. This software is provided “as is” without express or implied warranty.

Last update: August 8th, 2019

Fourmilab Home Page