Your Base to 1-2-3-Tribonacci to Binary back to Your Base Background

The 1-2-3-Tribonacci Sequence

Imagine for a second that you could make a fibonacci sequence by replacing the standard iteration formula with the following:



Basically, instead of summing the last two to get the next, you sum the last three. This is the basis for the 1-2-3-Tribonacci sequence.

Brown's Criterion

Brown's Criterion state that you may represent any integer value as a sum of members of a sequence provided that:



For all n greater than 1, 


What this means for the challenge

You may describe any positive integer as a sum of members of the 1-2-3-Tribonacci sequence formed by the following initial conditions:



This is known as, for every value in this sequence, the ratio between terms is never greater than 2 (the ratio averages out at about 1.839).

How to write in this numerical representation system

Let's say that you use a little-endian representation. Line up members of the sequence like so:

1  2  3  6 11 20 37 68


Then, you take your number to be represented (for our tests, let's say it's 63) and find the values of the given 1-2-3-Tribonacci which sum to 63 (using the largest values first!). If the number is part of the sum, put a 1 under it, 0 if not.

1  2  3  6 11 20 37 68
0  0  0  1  0  1  1  0


You may do this for any given integer - just verify that you use the largest values below your given input first!

Definition (finally)

Write a program or function that will do the following given some positive integer input n (written in any standard base) between 1 and your language's maximum value: 


Convert the value into the defined 1-2-3-Tribonacci's numerical representation. 
Using this binary-like representation, and read it as if it were binary. This means that the digits stay the same, but what they mean changes. 
Take this binary number and convert it into the base of the original number.
Output or return this new number.


However, as long as the output is valid, you needn't follow these steps. If you magically find some formula that is shorter (and mathematically equivalent), feel free to use it.

Examples

Let the function f be the function described by the definition, and let [] represent steps taken (as little-endian, though it shouldn't matter) (you do not need to follow this process, this is just the process described):

&gt;&gt;&gt; f(1)
[1]
[1]
[1]
1

&gt;&gt;&gt; f(5)
[5]
[0, 1, 1]
[6]
6

&gt;&gt;&gt; f(63)
[63]
[0, 0, 0, 1, 0, 1, 1]
[104]
104
Javascript 117 111 bytes

Thanks to @theonlygusti for helping golf off 5 bytes



x=&gt;{r=0;a=[1,2,3];i=1;while(a[++i]&lt;x)a[i+1]=a[i]+a[i-1]+a[i-2];for(;x;i--)if(x&gt;=a[i]){r+=1&lt;&lt;i;x-=a[i]}return r}


How It Works

First, the function generates all tribonacci numbers until it finds one greater than the input

a=[1,2,3];i=1;for(;a[++i]&lt;x;)a[i+1]=a[i]+a[i-1]+a[i-2];


Next, it reverse searches the list of numbers. If a number is less than the input, it adds 2^(index of that number) to the return value and reduces the input by that number.

for(;x;i--)if(x&gt;=a[i]){r+=1&lt;&lt;i;x-=a[i]}


Finally it returns the result.

Try it Online