3
$\begingroup$

Please help find Hidden algorithm:

In:    Out:
 4 ->   36
21 ->  693
35 -> 1155
36 -> 2340
43 -> ????
$\endgroup$
4
  • $\begingroup$ It would probably be more pleasurable if you embellished your puzzle with some story or background — even if that was all fluff, but better yet if that background provided some clues. $\endgroup$ Sep 13, 2017 at 16:10
  • 3
    $\begingroup$ Then again, as much as I enjoy catchy dressings on puzzles, as has been evident, and on solutions too, some of us don't miss them at all when not present $\endgroup$
    – humn
    Sep 13, 2017 at 18:17
  • 5
    $\begingroup$ @can-ned_food How would a story improve this puzzle? It's a self-contained math question. We're asked to find a pattern, and adding fluff would just make that more confusing. $\endgroup$
    – MikeQ
    Sep 13, 2017 at 18:18
  • 1
    $\begingroup$ @MikeQ (@humn too, but less so) — I was attempting to be helpful to an apparently new user in response to someone else's downvotes. I didn't know that most number-sequence or mathematics aficionados prefer bare questions; I guess they were downvoting for different reasons. At first glance, it appeared decent enough to me, so I was suggesting other possible causes. $\endgroup$ Sep 13, 2017 at 21:40

4 Answers 4

6
$\begingroup$

SirGrapefruit has observed that

the output always seems to be a multiple of the input.

Note also that

the ratio is always a power of 2, plus 1.

If we write

$f(x) = (2^{g(x)}+1)x$ where perhaps $g$ always yields positive integers,

then we need

g(4) = 3, g(21) = g(35) = 5, g(36) = 6.

We may for instance take

$g(n)=\left\lfloor\frac{\left\lfloor\sqrt{8n+1}\right\rfloor-1}4\right\rfloor+2$ [EDITED to add:] where, as Kruga observes in a comment on another answer, the inner flooring is redundant so we could instead just write $g(n)=\left\lfloor\frac{\sqrt{8n+1}-1}4\right\rfloor+2$

which is

one more than the number of even-index triangular numbers (0, 3, 10, 21, 36, ...) up to $n$.

[EDITED to add:] Oops, I hadn't noticed that we were asked for f(43) as well as f. With the formula I gave above,

g(43)=g(36) since there are no triangular numbers at all between 36 exclusive and 43 inclusive, so f(43)=65×43=2795.

$\endgroup$
3
$\begingroup$

Partial Observation:

In all examples, the output is divisible by the input.

Therefore the problem may be able to be reduced to the following:

With $f(x) = x * g(x)$, find a Function $g$ that maps $g(4)=9$, $g(21)=33$, $g(35)=33$ and $g(36)=65$.

$\endgroup$
3
$\begingroup$

I don't know if my solution and solution of @Gareth McCaughan are similar, but just posting since I find my proof more intuitive.

In:    Out: 
 4 ->   36  
21 ->  693
35 -> 1155
36 -> 2340
43 -> ????

Now we observe following pattern (please refer to link as I'm unable to hide the table):

Table1

Let's discuss following properly:

Table2

Consider the following function which defines LHS and RHS of Table2 given in the hint above.

On an input n and it returns smallest number k = 2*m + 1 such that (2*m - 1)*(2*m + 1) upper-bounds the input, where m and n are natural numbers.

We observe that Table2 follows the above function.

Hence for n = 4,

It should be 5, since 4 <= 5*3 and 3*1 < 4.

For n = 21,

It should be 7, since 21 <= 7*5 and 5*3 < 21.

For n = 35,

It should be 7, since 35 <= 7*5 and 5*3 < 35.

For n = 36,

It should be 9, since 36 <= 9*7 and 7*5 < 36.

For n = 43,

It should be 9, since 43 <= 9*7 and 7*5 < 43.

Now since,

Since sqrt(Out/In + 16) = 9

Therefore,

Out = 65 * In = 65 * 43 = 2795.

$\endgroup$
2
  • 1
    $\begingroup$ No, your answer isn't equivalent to mine, though it yields the same result for 43; mine grows faster for large inputs than yours does. The fact that two fairly simple (and roughly equally simple) answers are possible suggests, as should be no surprise, that we weren't really given enough (input,output) pairs to determine a clear right answer. $\endgroup$
    – Gareth McCaughan
    Sep 14, 2017 at 11:16
  • 1
    $\begingroup$ For what it's worth, I think your answer is a little nicer than mine. $\endgroup$
    – Gareth McCaughan
    Sep 14, 2017 at 11:16
2
$\begingroup$

According to Gareth, $g(n)$ can be represented as

$(\left\lfloor(\left\lfloor\sqrt{8n + 1}\right\rfloor - 1)/4\right\rfloor) + 2$

If we use 43 as $n$, we get 6.

$2^6+1=65$

Hence,

$43*65=2795$, So the answer is $2,795$.

$\endgroup$
1

Your Answer

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

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