A Euro-iginal Sequence Given a positive integer n output the n-th number of the euro-iginal sequence.

Calculating the Sequence

This sequence is equal to OEIS A242491.

A number is part of said sequence if the number can be made up by using as many different euro coins or notes, but only one of each. Note that you don't have to consider cents.

Example:

6 would be in the sequence, as it can consist of a 1-euro coin and a 5-euro-note.

4 would NOT be in the sequence, as it can't be formed with the given requirements.

To give everyone an overview, heres a list with euro values you have to consider:


  1€, 2€, 5€, 10€, 20€, 50€, 100€, 200€, 500€


Note that this sequence only ranges from 0 (yes, 0 is included!) to 888.



Here are the first 15 elements of this sequence:

0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, ...

Test Cases

Input -> Output

2 -&gt; 1
6 -&gt; 6
21 -&gt; 25
33 -&gt; 50
Jelly, 7 bytes

b8d4ḅ5Ḍ


Try it online!

How it works

b8d4ḅ5Ḍ  Main link. Argument: n (integer)

b8       Convert n from integer to base 8.
  d4     Divmod each base-8 digit by 4, mapping the digit d to [d / 4, d % 4].
    ḅ5   Convert the quotient-remainder pairs from base 5 to integer, mapping
         [d / 4, d % 4] to (d / 4 * 5 + d % 4).
         The last two steps establish the following mapping for octal digits.
             0 -&gt; [0, 0] -&gt; 0
             1 -&gt; [0, 1] -&gt; 1
             2 -&gt; [0, 2] -&gt; 2
             3 -&gt; [0, 3] -&gt; 3
             4 -&gt; [1, 0] -&gt; 5
             5 -&gt; [1, 1] -&gt; 6
             6 -&gt; [1, 2] -&gt; 7
             7 -&gt; [1, 3] -&gt; 8
      Ḍ  Convert the resulting array of digits from decimal to integer.