FunctionRacerProblemsRace

Base K to Decimal

BeginnerMathPython, JavaScript, TypeScript, Java, C++

The string digits holds a number written in base k (2 to 10), with each character a digit from "0" to "9" smaller than k. Return its value as an ordinary integer.

Example 1

digits "1011"
k 2
returns 11

8 + 0 + 2 + 1 = 11.

Example 2

digits "202"
k 7
returns 100

2*49 + 2 = 100.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Math problems