Skip to content

Instantly share code, notes, and snippets.

@surrealdetective
Created June 14, 2013 03:47
Show Gist options
  • Save surrealdetective/5779333 to your computer and use it in GitHub Desktop.
Save surrealdetective/5779333 to your computer and use it in GitHub Desktop.
decode the tree felled
code = "fx1=ZY&iX3=ZW&hm5=ZU&dg7=ZS&ei9=ZQ&ge11=ZO&tr13=ZM&hh15=ZK&uX17=ZI&si19=ZG&tX21=ZE&Xn23=ZC&hp25=ZA&pX27=YY&dl29=YW&wo31=YU&XX33=YS&XX35=YQ&re37=YO&et39=YM&ia41=YK&wn43=YI&uo45=YG&dX47=YE&so49=YC&ec51=YA&do53=XY&sX55=XW&xr57=XU&so59=XS&aX61=XQ&ph63=XO&ni65=XM&nX67=XK&Xa69=XI&yX71=XG&aX73=XE&ei75=XC&ie0=ZZ&Xa2=ZX&Xy4=ZV&aX6=ZT&Xn8=ZR&in10=ZP&hp12=ZN&Xa14=ZL&os16=ZJ&rx18=ZH&Xs20=ZF&od22=ZD&ce24=ZB&os26=YZ&Xd28=YX&ou30=YV&nw32=YT&ai34=YR&te36=YP&er38=YN&XX40=YL&XX42=YJ&ow44=YH&ld46=YF&Xp48=YD&ph50=YB&nX52=XZ&Xt54=XX&is56=XV&Xu58=XT&hh60=XR&rt62=XP&eg64=XN&ie66=XL&gd68=XJ&mh70=XH&Xi72=XF&xf74=XD"
chars = ('A'..'ZZ').to_a.reverse
#tactic:
#isolate the key-value pair, which is
#ultimately, you combine hashes using the = Hash [key1, value1, key2, value2, key3, value3]
def code_to_hash (code)
code_split_again = []
code_hash = 0
code_split = code.split('&')
code_split.each do |splitter|
code_split_again << splitter.split('=')
code_hash = Hash[*code_split_again.flatten]
end
code_hash
end
code_hash = code_to_hash(code)
#puts code_to_hash(code)
#["ZZ", "ZY", "ZX", "ZW", "ZV",
def hashvalue_to_position(code_hash, chars)
code_hash.each do |key, value|
if chars.include?(value)
code_hash[key] = chars.index(value)
end
end
code_hash
end
code_hash = hashvalue_to_position(code_hash, chars)
def sort_hash (code_hash)
code_hash.sort_by{ |key, value| value}
end
code_hash = sort_hash(code_hash)
def sorted_array_to_key_array(code_hash)
code_hash = code_hash.flatten
sorted_array = []
code_hash.each_with_index do |key_or_value, index|
if index.even?
sorted_array << key_or_value[0,2]
end
end
sorted_array
end
code_hash = sorted_array_to_key_array(code_hash)
puts code_hash.inspect
def position_grabber(code_hash, position)
string = ""
code_hash.each do |two_chars|
desired_snippet = two_chars[position]
string.concat(desired_snippet)
end
string.gsub('X', ' ')
end
even_string = position_grabber(code_hash, 0)
odd_string = position_grabber(code_hash, 1)
puts even_string
puts odd_string.reverse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment