Created
December 23, 2013 15:03
-
-
Save dennisquintel/8098551 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class WordMachine | |
def initialize(string) | |
@letters = string.split('') | |
end | |
def words | |
@letters.permutation.to_a.map(&:join).uniq.sort | |
end | |
def find(string) | |
words.find_index(string) + 1 | |
end | |
end | |
position = WordMachine.new('snowman').find('snowman') | |
puts sum_of_digits = position.to_s.split('').map(&:to_i).reduce(&:+) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment