8
\$\begingroup\$

The Lost Numbers are 4, 8, 15, 16, 23, 42. Your goal is to create an expression to output them all.

Your allowed characters are 0123456789, ^+-*/, (), % for modulo and n as the single variable allowed. Modified PEMDAS ()^*/%+- is the precedence and / is normal division (3/2 = 1.5). 0^0 = 1 although division by 0 is undefined.

Create the shortest expression (in characters) such that for n = 0..5 (or 1..6 for 1-indexing) the nth Lost Number will be the result of the expression. Shortest expression wins.

\$\endgroup\$
13
  • \$\begingroup\$ What if the language can't handle the size of the number :P? \$\endgroup\$
    – math scat
    Commented Jul 1, 2021 at 13:14
  • 1
    \$\begingroup\$ Relevant OEIS \$\endgroup\$
    – user100752
    Commented Jul 1, 2021 at 13:23
  • \$\begingroup\$ What's the precedence of the operators? (e.g. does 17%4*3 evaluate as 3 or 5?) \$\endgroup\$
    – Arnauld
    Commented Jul 1, 2021 at 13:58
  • \$\begingroup\$ Parentheses Exponents Multiply Divide Add Subtract \$\endgroup\$ Commented Jul 1, 2021 at 14:02
  • 1
    \$\begingroup\$ @Arnauld edited post to clarify precedence \$\endgroup\$ Commented Jul 1, 2021 at 14:18

3 Answers 3

9
\$\begingroup\$

20 characters

Assuming that the precedence of the operators is similar to JS. The input is expected to be 1-indexed.

n*4+16%n*3+6*0^(6-n)

Try it online! (interpreted in JS ES7)

Breakdown

 n           |  1 |  2 |  3 |  4 |  5 |  6 | (x4)
 16 % n      |  0 |  0 |  1 |  0 |  1 |  4 | (x3)
 0 ^ (6 - n) |  0 |  0 |  0 |  0 |  0 |  1 | (x6)
-------------+----+----+----+----+----+----+------
             |  4 |  8 | 15 | 16 | 23 | 42 |
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Brilliant! It looks like n*4+16%n*8%13%7*3 works. \$\endgroup\$
    – lynn
    Commented Jul 1, 2021 at 16:10
  • 4
    \$\begingroup\$ @Lynn This is clearly pushing it a step further, so feel free to post it as a new answer. \$\endgroup\$
    – Arnauld
    Commented Jul 1, 2021 at 16:12
9
\$\begingroup\$

16 15 characters

6704196%(n*8+3)

One-indexed. A simple application of a generalisation of the Chinese Remainder Theorem, with the formula n*8+3 chosen to make it work (that is, where moduli have a common factor, the corresponding values' difference is also divisible by that factor), as well as to get a shorter number on the left.

Previously: 485559068%(n+41), zero-indexed

\$\endgroup\$
2
  • \$\begingroup\$ Have you tried expressions of the form a%(b-n)? \$\endgroup\$
    – Neil
    Commented Jul 1, 2021 at 17:01
  • \$\begingroup\$ @Neil I just tried that, and found nothing better than the original from it. \$\endgroup\$
    – m90
    Commented Jul 1, 2021 at 17:49
8
\$\begingroup\$

15 bytes

n*4+703%n^3%7*3

Try it online!

Based off @Arnauld's answer.

The idea was to look for a magic formula A%n^B%C that maps (1, 2, 3, 4, 5, 6) to (0, 0, 1, 0, 1, 6) to combine the last two terms in Arnauld's formula into one:

 n           |  1 |  2 |  3 |  4 |  5 |  6 | (x4)
 703%n^3%7   |  0 |  0 |  1 |  0 |  1 |  6 | (x3)
-------------+----+----+----+----+----+----+------
             |  4 |  8 | 15 | 16 | 23 | 42 |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.