Task
Write a program/function that, given three integers n,a,b prints a regular expression which matches all of the base-n integers from a to b (and no integers outside of that range).
Your algorithm should, in theory, work for arbitrarily large integers. In practice, you may assume that the input can be stored in your data type. (don't abuse native data type, that's a standard loophole)
Input
Three integers, n, a, b where n is in the range 1-32. a and b may be taken as base-n string/character list/digit list.
Output
A single string, represent the regex.
Rules
- Base-n integers use the first
ndigits of0123456789ABCDEFGHIJKLMNOPQRSTUV, you can choose to use upper-case or lower-case. aandbmay be negative, denoted by a-in front of the integer- You may assume
a ≤ b. - Any regex flavor is allowed.
- The behavior of the regex on strings not a base-n integer is undefined.
Winning criteria
Answers will be scored by the length of the code in bytes. (so code-golf rules apply)
3 Answers 3
Jelly, 24 bytes
ƓØBḣḊ;0
rμṠṾṖ$€ż8Aṃ¢¤j"|
Take 2 input from command line argument as decimal number, and base from stdin.
-
\$\begingroup\$ Looks like this doesn't work for negative numbers. \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2017年12月18日 19:19:14 +00:00Commented Dec 18, 2017 at 19:19
-
\$\begingroup\$ @EriktheOutgolfer Fixed. \$\endgroup\$user202729– user2027292017年12月19日 01:21:50 +00:00Commented Dec 19, 2017 at 1:21
-in the front or something else? \$\endgroup\$