20
1
Challenge
Given a binary number as input through any means, "simplify" the number using a full program or a function.
Input
[binary]
binary
is a number in binary that is over 0.
Output
Take the input, convert it to base 10 without using a builtin, then if that number contains only 1s and 0s, convert it into a base 10 number as if it were another binary number. Repeat the process until the number cannot be read in binary and output that number.
Other information
If the input is 1, simply output
1
. Your program should not go on infinitely simplifying 1.This is code golf, so shortest answer in bytes by Tuesday (November 17th) wins.
If anything is confusing, leave a comment specifying what I need to clear up and I will edit it accordingly.
Builtins for base conversion are not allowed.
Examples
Input | Output
1 | 1
1010 | 2
1011 | 3
1100100 | 4
1100101 | 5
1111110011 | 3
4Could use a couple test cases. – isaacg – 2015-11-11T02:10:30.450
Is the input an ASCII string, or actually 1's and 0's? – Tom Carpenter – 2015-11-11T02:15:55.583
@TomCarpenter 1s and 0s. – The_Basset_Hound – 2015-11-11T02:20:57.203
@isaacg Added ways to get 1-5 as output. – The_Basset_Hound – 2015-11-11T02:21:39.803
Are functions which convert a string to a given base allowed? – isaacg – 2015-11-11T02:40:06.600
Are implicit base conversions allowed? e.g.
sprintf("%d",n);
in c effectively converts n to a base 10 string – Digital Trauma – 2015-11-11T02:48:11.667@isaacg No, unless you are simply turning the string into integers. – The_Basset_Hound – 2015-11-11T02:52:31.140
@DigitalTrauma If it is a builtin that performs base conversion, no. – The_Basset_Hound – 2015-11-11T02:54:48.587
@The_Basset_Hound To clarify Digital Trauma's question, is turning a number into its standard string representation, in base 10, allowed? I wouldn't consider it a base conversion, more of a typecast. – isaacg – 2015-11-11T02:58:19.360
@isaacg That's fair. – The_Basset_Hound – 2015-11-11T03:00:48.613