Anagram

Anagram

Medium

Instructions

An anagram is a rearrangement of letters to form a new word: for example "owns" is an anagram of "snow". A word is not its own anagram: for example, "stop" is not an anagram of "stop".

Given a target word and a set of candidate words, this exercise requests the anagram set: the subset of the candidates that are anagrams of the target.

The target and candidates are words of one or more ASCII alphabetic characters (A-Z and a-z). Lowercase and uppercase characters are equivalent: for example, "PoTS" is an anagram of "sTOp", but StoP is not an anagram of sTOp. The anagram set is the subset of the candidate set that are anagrams of the target (in any order). Words in the anagram set should have the same letter case as in the candidate set.

Given the target "stone" and candidates "stone", "tones", "banana", "tons", "notes", "Seton", the anagram set is "tones", "notes", "Seton".

Track Specific Notes

For purposes of this exercise, a word is not considered to be an anagram of itself.

Running and testing your solutions

From the command line

Simply type make chez if you're using ChezScheme or make guile if you're using GNU Guile. Sometimes the name for the scheme binary on your system will differ from the defaults. When this is the case, you'll need to tell make by running make chez chez=your-chez-binary or make guile guile=your-guile-binary.

From a REPL

  • Enter (load "test.scm") at the repl prompt.
  • Develop your solution in anagram.scm reloading as you go.
  • Run (test) to check your solution.

Failed Test Cases

If some of the test cases fail, you should see the failing input and the expected output. The failing input is presented as a list because the tests call your solution by (apply anagram input-list). To learn more about apply see The Scheme Programming Language -- Chapter 5

Edit via GitHub The link opens in a new window or tab
Scheme Exercism

Ready to start Anagram?

Sign up to Exercism to learn and master Scheme with 39 exercises, and real human mentoring, all for free.