6 kyu

Simple Fun #355: Possible Base

60 of 70myjinxin2015

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:

613 * 913 = 4213

Because:

613 == 610

913 == 910

4213 == 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 ^_^

Fundamentals

Stats:

CreatedSep 26, 2017
PublishedSep 26, 2017
Warriors Trained162
Total Skips2
Total Code Submissions383
Total Times Completed70
JavaScript Completions60
Python Completions15
Total Stars2
% of votes with a positive feedback rating95% of 32
Total "Very Satisfied" Votes29
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • JohanWiltink Avatar
  • saudiGuy Avatar
Ad