Wham! Bam! Anagrams!

Along came the rap fairy

With a Unix dictionary .

Seekers solve his riddles nary.

"If you surpass my mental trap, I will grant you power to rap. Words are the weapon that I wield, how many anagrams does one sword yield?

As for the length of your sword, do not use 6 letters or more.

There's one more part, and just one more: What's ten times this number, then its floor?"

Details and assumptions:

  • An anagram is the result of rearranging the letters of a word to produce a new word.
  • Do not count words with apostrophes ( ' ).
  • Make sure to make the words lowercase.
  • A word cannot be an anagram of itself; i.e. - "god" is an anagram of "dog", but "dog" is not an anagram of "dog".
  • Only count words with 5 letters or less.
  • Take the mean, not the mode.
  • Use the Unix dictionary . (Brilliant hosted)


The answer is 6.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Brock Brown
May 25, 2015

Python 2.7:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from itertools import permutations
import random
from time import time
from math import floor
words = set()
for word in open("words",'r').read().split("\n"):
    if "'" in word or word == '' or len(word) > 5:
        continue
    words.add(word.lower())
def anagrams(word):
    found = set()
    for combo in permutations(word, len(word)):
        if ''.join(combo) in words:
            found.add(''.join(combo))
    return found
total = 0.0
trials = 0
end = time() + 60
while time() < end:
    random_word = random.sample(words, 1)[0]
    total += len(anagrams(random_word)) - 1
    trials += 1
print "Answer:", floor(10*(total/trials))

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...