Skip to content

Instantly share code, notes, and snippets.

@danielbonnell
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbonnell/1fd110325d994744d2b4 to your computer and use it in GitHub Desktop.
Save danielbonnell/1fd110325d994744d2b4 to your computer and use it in GitHub Desktop.
Hexadecimal Converter Challenge
def hex_to_decimal(input)
input = input.split('')
array = []
input.each do |x|
x == "A" ? x.replace("10").to_i : x
x == "B" ? x.replace("11").to_i : x
x == "C" ? x.replace("12").to_i : x
x == "D" ? x.replace("13").to_i : x
x == "E" ? x.replace("14").to_i : x
x == "F" ? x.replace("15").to_i : x
x = x.to_i
end
array = input.map {|x| x = x.to_i }
output = []
array.each do |x|
input.each do |y|
if input[y].is_a?(Integer) && input[y.next].is_a?(String)
output << array[x] * array[x.next]
elsif input[y].is_a?(String) && output[-1].is_a?(Integer)
true
elsif input[y].is_a?(Integer) && input[y.next] != String
output << array[x]
end
end
end
puts output
end
hex_to_decimal('5A5A5A')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment