Simple Fun #43: Ada Number
Description:
Task
Consider two following representations of a non-negative integer:
A simple decimal integer, constructed of a non-empty sequence of digits from 0 to 9;
An integer with at least one digit in a base from 2 to 16 (inclusive), enclosed between # characters, and preceded by the base, which can only be a number between 2 and 16 in the first representation. For digits from 10 to 15 characters a, b, ..., f and A, B, ..., F are used.
Additionally, both representations may contain underscore (_) characters; they are used only as separators for improving legibility of numbers and can be ignored while processing a number.
Your task is to determine whether the given string is a valid integer representation.
Note: this is how integer numbers are represented in the programming language Ada.
Example
For line = "123_456_789"
, the output should be true;
For line = "16#123abc#"
, the output should be true
;
For line = "10#123abc#"
, the output should be false
;
For line = "10#10#123ABC#"
, the output should be false
;
For line = "10#0#"
, the output should be true
;
For line = "10##"
, the output should be false
.
Input/Output
[input]
stringline
A non-empty string.
[output]
a boolean value
true
if line is a valid integer representation, false
otherwise.
Similar Kata:
Stats:
Created | Jan 25, 2017 |
Published | Jan 25, 2017 |
Warriors Trained | 489 |
Total Skips | 63 |
Total Code Submissions | 1415 |
Total Times Completed | 164 |
JavaScript Completions | 84 |
C# Completions | 40 |
Ruby Completions | 34 |
Python Completions | 23 |
Total Stars | 13 |
% of votes with a positive feedback rating | 89% of 57 |
Total "Very Satisfied" Votes | 46 |
Total "Somewhat Satisfied" Votes | 9 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 6 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |