5 kyu

Simple Fun #43: Ada Number

84 of 164myjinxin2015

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] string line

A non-empty string.

  • [output] a boolean value

true if line is a valid integer representation, false otherwise.

Puzzles

Stats:

CreatedJan 25, 2017
PublishedJan 25, 2017
Warriors Trained489
Total Skips63
Total Code Submissions1415
Total Times Completed164
JavaScript Completions84
C# Completions40
Ruby Completions34
Python Completions23
Total Stars13
% of votes with a positive feedback rating89% of 57
Total "Very Satisfied" Votes46
Total "Somewhat Satisfied" Votes9
Total "Not Satisfied" Votes2
Total Rank Assessments6
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • hobovsky Avatar
  • mauro-1 Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
Ad