Alvaro-Germans

Introduction

I'm not very good at anagrams, so I've decided to write my own anagram solver. Now, as long as I have access to my laptop, I'll be able to impress my friends.

Milestones

  • Solve one-word anagrams
  • Solve multi-word anagrams
  • Build a web front end so I can do it sneaky-like on my phone

Intuition

Any two anagrams can be compared (slowly) in two sorting operations,

acb -> abc
cba -> abc
=> acb is an anagram of cba

Abstracting away briefly, suppose we take map letter as a prime,

primify:
    a = 2
    b = 3
    c = 5
    ...
    z = 101

And define a function

numberfy(word):
	out = 1
	for letter in word:
		out *= primify(letter)

Then it's trivial to show,

numberfy('acb') = 30
numberfy('cba') = 30
OK

This is much quicker, and serves as a core primitive in the solver. Then, each dictionary word can be expressed by the following map,

F: numberfy -> word
F(2286526) = apple
F(44376) = banana

It's possible that some words in the dictionary are already anagrams of each other, in which case we can map numberfy to a list of words.

Step one is building the map.