Jump to content
MakeWebGames

Mathematical Puzzle


Alan

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.

Link to comment
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 ;)

Link to comment
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 ;)

Capture.JPG.816cc75ea8258552d0dfc6bee1db9c5b.JPG

Link to comment
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][0];
       $y += $matrix[$direction][1];
   }

   $direction = ++$direction % 4;
}

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...