19
3
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):
>>> f(1)
[1]
[1]
[1]
1
>>> f(5)
[5]
[0, 1, 1]
[6]
6
>>> f(63)
[63]
[0, 0, 0, 1, 0, 1, 1]
[104]
104
Can I submit a separate program which while not as short will solve the question faster? log(log(n))+n time as opposed to log(n)+n time. Go go Nth power matrix. – fəˈnɛtɪk – 2017-02-07T16:20:11.160
@LliwTelracs I cannot stop you from posting your solutions. Just make that solution method target as concise to your knowledge as you can to make sure you're competing in the right field still. – Addison Crump – 2017-02-07T16:22:35.843
Well, not going to do this one at least. Fast exponentiation of this matrix is ridiculously verbose – fəˈnɛtɪk – 2017-02-07T16:38:39.740
2@LliwTelracs Maybe just add it as an addendum to your existing post then. – Jonathan Allan – 2017-02-07T16:39:54.007
your challenge is illegible for those that can't show images. – Mindwin – 2017-02-08T13:45:49.957
Unfortunately, all my base are belong to somebody else, and I don't think it would be a good idea to change them without consulting the owner. – David Richerby – 2017-02-08T14:14:02.133
This could use a few more test cases. I'd add at least 2 to 10 (quite a few edge cases there) and 231 (first input for which output > 2 × input). – Dennis – 2017-02-09T04:30:26.207