Created
November 3, 2010 20:38
-
-
Save ehrenmurdick/661675 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
require 'active_support' | |
require 'enumerator' | |
require 'abbrev' | |
Letters = [[], []] + ('a'..'z').enum_for(:each_slice, 3).to_a | |
class Array | |
def sequence(i = 0, *a) | |
return [a] if i == size | |
self[i].map {|x| | |
sequence(i+1, *(a + [x])) | |
}.inject([]) {|m, x| m + x} | |
end | |
def codes | |
sequence.map {|c| c.join} | |
end | |
end | |
S = ["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"].map{|x| x.downcase} | |
A = S.abbrev | |
def n *numbers | |
codes = numbers.map {|c| Letters[c] }.codes | |
codes.find_all do |code| | |
A[code] | |
end.map {|x| A[x] } | |
end | |
v = ARGV.map{|x| x.to_i} | |
p n(*v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment