# The problem

Given a binary number from 0 to 111111 convert it to trinary. (Base 3). Then print the result.

## Rules

No using a list of conversions.

Don't cheat

You must use a string as the number

No compressing the input string As I will be testing the code with several different numbers I can't use compressed strings

## Notes

By trinary I mean counting in base 3. So 0,1,2,10,11,12,20... ect

Leading zeros will be present 001101

Most important number is on the left.

## Example

String input = "110111"
String a = code(input);
print(a);


# To win

This is code golf!

Do it correctly and in the smallest size.

• You must use a string as the number I'd recommend allowing other formats such as integer etc. Dec 18, 2016 at 19:39
• Base 3 is more commonly referred to as ternary. Dec 18, 2016 at 19:47
• I'm not sure what No using a list of conversions. means. Are you disallowing base conversion built-ins? Dec 18, 2016 at 19:48
• It's even less clear what "no compression" is supposed to refer to. Dec 18, 2016 at 19:49
• We have a sandbox where you can have feedback and help from the community before posting a challenge. Please use it.
Dec 18, 2016 at 20:06

# Bash 25 bytes

Golfed

bc<<<"ibase=2;obase=3;$1"  ## JavaScript (ES6), 26 bytes s=>(+0b${s}).toString(3)


# Ruby, 97 87 bytes

f=->a{x=0
a.chars.map{|i|x+=x+i.ord%2}
o=x>0?"":?0
(o=(48+x%3).chr+o
x/=3)while x>0
o}


Old version:

def f a
x=0
a.chars.map{|i|x=x+x+i.ord%2}
o=x>0?"":"0"
while x>0
o=(48+x%3).chr+o
x/=3
end
o
end

• Unless you were purposefully avoiding builtins, I think you're overthinking this. 21 bytes: ->s{s.to_i(2).to_s 3}. Also you might find this useful: codegolf.stackexchange.com/q/363/11261 Dec 18, 2016 at 20:11
• @Jordan Indeed I was avoiding built-in base conversion functions. Dec 18, 2016 at 21:08
• @Jordan Thanks for the tip list I have applied some of them and trimmed off 10 bytes. Dec 19, 2016 at 7:00