[Challenge] All your bijective base are belong to us 08-31-2015, 01:36 PM
#1
This challenge was loosely inspired by another user on the forum, Dijkstra.
Just to give you all a run down.. 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 run-length encoding) and bijective base 26 (used to number columns in spreadsheets).
The Challenge
In this challenge, we define the set M of symbols as
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.
The 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 Case
All test cases specify the input in the order b, n, B.
The Rules
No special tricks in here really, except for the [2::5] slicing to get the charset at a lower byte count. Here's my solution written in Python 2 (167 bytes):
Tests:
Just to give you all a run down.. 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 run-length encoding) and bijective base 26 (used to number columns in spreadsheets).
The Challenge
In this challenge, we define the set M of symbols as
Code:
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.
The 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 Case
All test cases specify the input in the order b, n, B.
Code:
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"The Rules
- You can 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.
No special tricks in here really, except for the [2::5] slicing to get the charset at a lower byte count. Here's my solution written in Python 2 (167 bytes):
Code:
x=range;A=`map(chr,x(49,58)+x(65,91)+x(97,123))`[2::5]+'<=>'
r=A.find
b,n,B=input()
B=r(B)+1
d=0;s=''
for c in n:d=d*-~r(b)+r(c)+1
while d:d-=1;s=A[d%B]+s;d/=B
print sTests:
Code:
"4","","8" Â Â >>> (empty string)
">","Fe","a" Â >>> RS
"3","31","1" Â >>> 1111111111
"A","16","2" Â >>> 1112
"2","122","A" Â >>> A
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)

