Arbitrary Base88

Problem #96

Tags: computing

Who solved this?

Previous:Negative Bases Next:Kaprekar's Constant


As we observed during the Arbitrary Bases Problem, any number could be represented in base B as long as there are at least B symbols available to use as digits. So far, we have expressed numbers up to base 36 by using the following symbol set:

0123456789abcdefghijklmnopqrstuvwxyz

But we could add even more symbols to achieve even higher bases. Base64 is commonly used in computing, and adds the uppercase letters with two other characters to acheive 64 total symbols.

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

Base64 also rearranges the order of the symbols, placing the numeric digits near the end of the sequence. Indeed, the order of the symbols in the set are also somewhat arbitrary.

Let's push this even further and make our own "Base88", by utilizing the following 88 symbols:

0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-!#$%&()*,./:;?@[]^{}~+<=>

However, let's really put our signature on this set by first randomizing the order of the symbols. So we'll end up with something like this, for example:

iQ*40XarG&p;yK)25C~,ED3J}Ube^l]1zhj.wnHVMd[WFY:L9>c$v?!At+#{g%TPx6qSmk7fR(IOo=B@/uNZ8-s<

Problem Statement

Input Data
First line will be a string of 88 characters, corresponding to the symbol set to be used for this problem.
Second line line will be Q, the quantity of testcases.
Q lines will then follow, each in the format V B1 B2 where V is a value expressed in base B1 using the listed symbol set, which you will be expected to convert into base B2.
Note that B1 and B2 will always be expressed in decimal notation, using the given symbol set.

Answer
Should consist of Q space-separated values, corresponding to each value V converted into base B2 using the listed symbol set.
Please do not use prefixes such as 0b or 0x for this problem.

Example

input data:
iQ*40XarG&p;yK)25C~,ED3J}Ube^l]1zhj.wnHVMd[WFY:L9>c$v?!At+#{g%TPx6qSmk7fR(IOo=B@/uNZ8-s<
6
Qi 2 5
QQiQ 2 10
Qiii 10 88
Q*40XarG&i 10 88
o.O 77 55
>o=o< 88 87

answer:
* Q4 ;z E$!Fc *V9& vC0>C
You need to login to get test data and submit solution.