25
2
Background
A bijective base b numeration, where b is a positive integer, is a bijective positional notation that makes use of b symbols with associated values of 1 to b.
Unlike its non-bijective counterpart, no symbol has a value of 0. This way, each non-negative integer n has a unique representation in bijective base b.
Popular bijective numerations include unary, bijective base 2 (used in bzip2's run-length encoding) and bijective base 26 (used to number columns in spreadsheets).
Definition
In this challenge, we define the set M of symbols as
123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<=>
and a function i from M to the natural number such that i('1') = 1, …, i('>') = 64.
Given a base b between 1 and 64 (both inclusive), we define that each non-negative integer n corresponds to the string ak…a0, consisting of symbols of M, such that n = bki(ak)+…+b0i(a0).
This correspondence is well-defined and bijective. Since an empty sum is defined as 0, the integer 0 can be encoded as an empty string.
Task
Accept three strings as input:
An input base b between 1 and 64, encoded as a bijective base 64 string.
A non-negative integer n, encoded as a bijective base b string.
An output base B between 1 and 64, encoded as a bijective base 64 string.
Given these three inputs, encode n as a bijective base B string.
Test cases
All test cases specify the input in the order b, n, B.
Input: "4" "" "8"
Output: ""
Input: "A" "16" "2"
Output: "1112"
Input: "2" "122" "A"
Output: "A"
Input: "3" "31" "1"
Output: "1111111111"
Input: ">" "Fe" "a"
Output: "RS"
Rules
You may read the three strings in any convenient order, as such, an array of strings, a string representation thereof, concatenated or separated by single-character delimiters of your choice.
If you choose to print the output to STDOUT, you may only print the symbols and (optionally) a trailing newline.
Base conversion built-ins of all kinds are allowed.
Standard code-golf rules apply.
Oh, you can actually use the regular base conversion operator for the first base conversion? Now I feel silly for using all the code I have in my solution. :) I didn't realize that it would work with values that are outside the range of the base. Well, in hindsight, there's no good reason why it shouldn't. – Reto Koradi – 2015-08-03T15:34:08.877
@RetoKoradi yes, you can do that; one day it will be documented :) – aditsu quit because SE is EVIL – 2015-08-03T15:40:07.400
Do you mind if I change my solution to use the base conversion? I normally try to avoid taking ideas from other solutions. But it really bugs me to let mine stand with such a sub-optimal approach. It's highly likely that your solution will still be shorter. – Reto Koradi – 2015-08-03T22:11:08.083
@RetoKoradi no problem, go ahead – aditsu quit because SE is EVIL – 2015-08-04T01:57:45.540