Last active
August 29, 2015 14:07
-
-
Save danielbonnell/1fd110325d994744d2b4 to your computer and use it in GitHub Desktop.
Hexadecimal Converter Challenge
This file contains 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
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