Skip to content

Instantly share code, notes, and snippets.

@dennisquintel
Created December 23, 2013 15:03
Show Gist options
  • Save dennisquintel/8098551 to your computer and use it in GitHub Desktop.
Save dennisquintel/8098551 to your computer and use it in GitHub Desktop.
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