Skip to content

Instantly share code, notes, and snippets.

@holdenhinkle
Last active March 12, 2016 21:01
Show Gist options
  • Save holdenhinkle/1e53514fb0f8e6de8e5f to your computer and use it in GitHub Desktop.
Save holdenhinkle/1e53514fb0f8e6de8e5f to your computer and use it in GitHub Desktop.
Trinary
class Trinary
attr_reader :number
def initialize(value)
@number = value
end
def to_decimal
return 0 if number.match(/[^0-2]/)
converted_num = 0
number.split('').reverse.each_with_index do |num, index|
converted_num += num.to_i * 3 ** index
end
converted_num
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment