Last active
August 29, 2015 14:19
-
-
Save netsprout/54686d5e76f1e1d6aa5c to your computer and use it in GitHub Desktop.
Phone Dial Combinations
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
keypad = { | |
'2': ['A','B','C'], | |
'3': ['D', 'E', 'F'], | |
'4': ['G','H','I'], | |
'5': ['J','K','L'], | |
'6': ['M','N','O'], | |
'7': ['P','Q','R','S'], | |
'8': ['T','U','V'], | |
'9': ['W','X','Y','Z'] | |
} | |
words = [] | |
numbers = [2,3,8] | |
# 2 => ['A','B','C'] | |
# 3 => ['D','E','F'], | |
# 8 => ['T','U','V'], | |
# Take first number 2 | |
# Get letters | |
# get first letter 'A' | |
# build all combinations with that by looping through each array of other 2 numbers | |
# A + DEF + TUV | |
# ADT | |
# AET | |
# BDT | |
# CDT | |
# AET | |
# AFT | |
# B | |
# for i in 0..numbers.length do | |
# times = i + 1 | |
numbers.each_with_index do |number,index| | |
letters = keypad[number.to_sym] | |
letters.each do |letter| | |
puts "NUMBER: #{number}, LETTER: #{letter}, INDEX. #{index}" | |
end | |
words[index] = '' | |
end | |
# end | |
# words = [] | |
# traverse(words, numbers) | |
# def traverse(number, numbers) | |
# numbers.each_with_index do |number, index| | |
# if index + 1 == numbers.length | |
# @words << word | |
# else | |
# traverse(word, numbers) | |
# end | |
# end | |
# word | |
# end | |
# def build_word(letter) | |
# end | |
# def construct(expanded=false) | |
# strategy.each do |f| | |
# node = Node.new(f, formatter) | |
# if expanded == true | |
# @facets << node.traverse_all | |
# else | |
# @facets << node.traverse | |
# end | |
# end | |
# @facets | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment