MakeWebGames

# Mathematical Puzzle

## Recommended Posts

Given the first few terms of y = f(x), can you determine what the function f() is?

```x = 1, 2, 3, 4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
y = 0, 1, 1, 0, -1, -1, -1,  0,  1,  2,  2,  2,  2,  1,  0, -1, -2, -2, -2, -2```

I should point out that I don't know the answer, although I have written a generator which works perfectly, however I'm specifically looking for a single formula.

##### Share on other sites

As it goes up and down it seems to be something related to a sin or cos. As the numbers are also int, I would say there is a rounding too as well as like a second sin to increase the effect over time. Remains to tweak all those to find the right effect. Other option use Mathlab and it's curve fitting to let it find it for you ;)

##### Share on other sites

Ah, I thought I was on to something, until I got to x=5.

```1/sqrt(1+0^0)
2/sqrt(2+1^1)
3/sqrt(3+2^2)
4/sqrt(4+3^3)

x / sqrt(x+(x-1)^(x-1))
```
##### Share on other sites

here is an approximation (a few values are not appearing at the right time but you can continue to tweak the formula):

a=1.1

b=0.08

c=0.46

d=1

e=0.28

y=round(sin((x-c)/a+(e*x)))*(x*b)+d))

[ATTACH=CONFIG]1234[/ATTACH]

Series 2 (and column C) are your original values, while column B and series 1 is my current approximation. Mathlab or excel can both help you ;) ##### Share on other sites

Some interesting suggestions, I hadn't considered trig functions.

@denb; yes only integers are produced.

For anyone who is curious:

```<?php

\$index     = 1;
\$x         = 0;
\$y         = 0;
\$direction = 0;
\$matrix     = array(array(1, 0), array(0, 1), array(-1, 0), array(0, -1));

for (\$i = 0; \$i < 10; \$i++) /* increment 10 to suit */
{
for (\$j = 0; \$j < floor((\$i + 2) / 2); \$j++)
{
echo sprintf("%d : ( %d , %d )\n", \$index, \$x, \$y);

\$index++;

\$x += \$matrix[\$direction];
\$y += \$matrix[\$direction];
}

\$direction = ++\$direction % 4;
}```

If you plot the generated coordinates; you end up with a rather remarkable and handy ""curve"".

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• #### Marketplace

• Discord Chat
• PBBG Directory
×
• Create New...