This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# An anagram is a word formed by rearranging the letters of another, like "topside" and | |
# "deposit". In some cases, there might be as many (or more) anagrams than there are | |
# characters, like "post", "spot", "stop" and "tops". | |
# | |
# Write a program to find all of the anagrams in a dictionary in which there are at | |
# least 4 letters in the word and at least as many anagrams as there are letters. | |
# | |
# The dictionary will be a file on disk with one line per word. Your operating system | |
# likely already has such a file in /usr/dict/words or /usr/share/dict/words. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a deep copy of an object. - Based on https://github.com/documentcloud/underscore/pull/595 | |
deepClone = (obj) -> | |
if !_.isObject obj or _.isFunction obj then return obj | |
if _.isDate obj then return new Date do obj.getTime | |
if _.isRegExp obj then return new RegExp obj.source, obj.toString().replace(/.*\//, "") | |
isArr = _.isArray obj or _.isArguments obj | |
func = (memo, value, key) -> | |
if isArr then memo.push deepClone value |