This is the first task to be solved with the help of regexps.
Your submission (in the Code field below) should consist of one or more lines, each consisting of two parts separated with space:
There should be no other code in any language, except these pairs of patterns!
These regular expressions and substitutions are applied to each line of the input in order. If the given regexp will found the matching framgent inside the line, it will be substituted with the given pattern.
For example an input like this:
aaaaa bbbb aaabb
Could be processed with the following solution:
a+ X
b+ Y
and the following result would be produced:
X Y XY
If input consists of several lines, they will be processed independently (though results are glued together into a single line with spaces).
Regexp format used here is one of PHP Regexps - it is very close to Perl-style regexps, I hope.
You are given a set of integers in decimal
, octal
, hex
and binary
format as they are used in several
programming languages (derivatives from C
and Assemblies
):
0-7
and starting with 0
is octal;0-9ABCDEF
and starting with 0x
is hexadecimal;h
but then it should not start with letter;0b1000101
or 1000101b
(though the single letter b
is not a number);0-9
are considered decimals (but not ones starting with zero -
they should be regarded as octals and coul only contain digits 0-7
).And your goal is to recognize these formats. Note that all letters (in hexadecimal values and in prefixes / suffixes) should be treated case-insensitively!
Input data will contain several "integers", each on separate line.
Answer should contain replacements for them - dec
for decimals, oct
for octals, bin
for binaries
and hex
for hexadecimals. Strings which could not be recognized should be left unchanged.
Solution - i.e. your regexp - is also checked for this task.
Example:
input data:
1347
0x80
013
101b
answer:
dec hex oct bin
Solution may start like:
^0\d+ oct
\d+ dec
...
Use the button "RegExp" below to try your solution against sample input.