Simple Fun #355: Possible Base
Description:
When we see an arithmetic expression:
6 * 9 = 42
We usually think of it as a wrong expression. This is because we usually use the decimal system(Base10).
In fact, this expression is correct in Base13:
6
13 *
9
13 = 42
13
Because:
6
13 == 6
10
9
13 == 910
42
13 == 5410
Task
You are given a string exp
that represents a arithmetic expression, such as a + b = c
, a - b = c
or a * b = c
. Your task is to determine the possible base of it. the range of base is 2-32
. If more than one base are valid, return the smallest base. If no valid base found, return -1
.
Example
For exp = "1 + 1 = 2"
, The output should be 3
.
For exp = "1 + fe = ff"
, The output should be 16
.
For exp = "1 + a = b"
, The output should be 12
.
For exp = "1 * a = a"
, The output should be 11
.
For exp = "1 + 1 = 10"
, The output should be 2
.
For exp = "a + b = c"
, The output should be -1
.
Note
string
exp
contains only digits and lowercase letters.Happy Coding
^_^
Similar Kata:
Stats:
Created | Sep 26, 2017 |
Published | Sep 26, 2017 |
Warriors Trained | 162 |
Total Skips | 2 |
Total Code Submissions | 383 |
Total Times Completed | 70 |
JavaScript Completions | 60 |
Python Completions | 15 |
Total Stars | 2 |
% of votes with a positive feedback rating | 95% of 32 |
Total "Very Satisfied" Votes | 29 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |