22
0
Given 3 integers, determine the lowest possible base for the first two integers to multiply into the third. If you think of the Answer to the Ultimate Question of Life, The Universe, and Everything, 6 * 9 == 42, is true in Base 13.
The inputs can include any numbers whose digits use the characters 0-9, a-z, and A-Z, where a
equals 10 in Base 10, and Z
is 61 in Base 10.
The inputs should be inputted in any way you like (except for hard-coding), and you can write either an individual function or an entire program.
The maximum base that must be considered is Base 62, and the minimum base is Base 2.
You can assume that the first two values are smaller than the third. You can also conclude that the minimum base is one greater than the highest digit/character from the inputs (for example, if the inputs are 3 1a 55
, the minimum base would be Base 11, because a
is the highest digit).
If there is no such base, return a junk value of your choice.
This is code golf, so the shortest code wins.
Test Cases
6 9 42 --> 13
a a 64 --> 16
aA bB 36jk --> 41
2 3 20 --> <junk value>
10 10 100 --> 2
Going up to base 62 AND requiring error cases really puts a wrench in the system. – Beefster – 2019-03-08T23:59:58.630
I think STDIN would probably be better, and either would be fine. – erdekhayser – 2014-10-27T12:17:01.720
@MartinBüttner So should I just allow input in either form? – erdekhayser – 2014-10-27T12:25:03.580
@MartinBüttner - Let the OP add examples. – Optimizer – 2014-10-27T17:26:38.013
1As a point of clarification what should be done if multiple bases are valid such as your last example (which has now been removed - it was 10*10=100) where it is also valid in base 10 and indeed any other base you care to mention... – Chris – 2014-10-27T17:28:59.633
There is no such thing as base 1. – kay - SE is evil – 2014-10-27T17:38:10.303
1@Kay If I define the positional system in base
b
in a general way likea_0 b^0 + a_1 b^1 + a_2 b^2 + ...
(wherea_0
is the least significant digit) than base 1 definitely makes sense. Furthermore, the OP's conclusion would also include base 1 in the search if the largest present digit is 0. – Martin Ender – 2014-10-27T17:44:50.3772
About base 1, unary is a number system. http://en.m.wikipedia.org/wiki/Unary_numeral_system
– erdekhayser – 2014-10-27T18:20:10.397I made an edit so that you should return the lowest possible base. – erdekhayser – 2014-10-27T18:21:15.847
Changed the rules to stay at base 2. – erdekhayser – 2014-10-27T18:25:09.610
@MartinBüttner Correct. Junk value should be a number that is not in the range of 2-62 inclusive. – erdekhayser – 2014-10-27T20:01:03.537