A multi-word anagram solver in Clojure, based on the article "Anagrams and Pangrams" from The Armchair Universe, by A.K. Dewdney.
You will need Leiningen 2.8.1 or above installed.
To build and start the service locally, run:
$ cd ars-magna
$ lein deps
$ lein test
$ lein ring server-headless
To build and run a standalone jar:
$ lein ring uberjar
$ java -jar target/ars-magna-0.2.1-standalone.jar
In both instances, the webapp starts on http://localhost:3000. See the curl examples below for usage.
A docker image is available as richardhull/ars-magna, and can be downloaded and started with:
$ docker pull ghcr.io/rm-hull/ars-magna:main
$ docker run --name ars-magna -d -p 3000:3000 ghcr.io/rm-hull/ars-magna:main
Using all the letters to find multi-word anagrams, from a Clojure REPL:
(use 'ars-magna.dict)
(use 'ars-magna.solver)
(let [dict (load-word-list :en-GB)
index (partition-by-word-length dict)]
(sort
(multi-word index "compute" 3)))
; ("come put" "compute" "cote ump" "cut mope" "cut poem"
; "cute mop" "met coup" "mote cup" "mute cop" "tome cup")
or querying the web service for the word 'compute':
$ curl -s http://localhost:3000/multi-word/compute | jq .
returns the same anagrams:
[
"come put",
"compute",
"cote ump",
"cut mope",
"cut poem",
"cute mop",
"met coup",
"mote cup",
"mute cop",
"tome cup"
]
Find the longest single words from the given word, without necessarily using all the letters - at the REPL:
(use 'ars-magna.dict)
(use 'ars-magna.solver)
(let [dict (load-word-list :en-GB)
index (partition-by-letters dict)]
(sort-by
(juxt (comp - count) identity)
(longest index "compute" 4)))
; ("compute" "comet" "coupe" "tempo" "come"
; "cope" "cote" "coup" "cute" "mope" "mote"
; "mute" "poem" "poet" "pout" "temp" "tome")
(the (sort-by (juxt (comp - count) identity) ...)
returns the words
sorted by longest first, then alphabetically)
or querying the web service for the word 'compute':
$ curl -s http://localhost:3000/longest/compute | jq .
returns the same anagrams:
[
"compute",
"comet",
"coupe",
"tempo",
"come",
"cope",
"cote",
"coup",
"cute",
"mope",
"mote",
"mute",
"poem",
"poet",
"pout",
"temp",
"tome"
]
Find the single words from the given wildcard (use ?
or .
for a single
character or *
for a sequence) - at the REPL:
(use 'ars-magna.dict)
(use 'ars-magna.solver)
(->
(load-word-list :en-GB)
(wildcard "c..p..e")
sort)
; ("compare" "compete" "compile"
; "compose" "compote" "compute"
; "coppice" "cowpoke" "cripple"
or querying the web service for the word 'compute':
$ curl -s http://localhost:3000/wildcard/c..p..e | jq .
returns the same words:
[
"compare",
"compete",
"compile",
"compose",
"compote",
"compute",
"coppice",
"cowpoke",
"cripple"
]
The MIT License (MIT)
Copyright (c) 2016 Richard Hull
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.