Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help solving math problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 lomateron   Members   -  Reputation: 329

Like
0Likes
Like

Posted 16 October 2012 - 08:32 AM

I have this relation of numbers
0 - 1 ---> 0
1 - 2 ---> 1
0 - 2 ---> 2
2 - 3 ---> 3
1 - 3 ---> 4
0 - 3 ---> 5
3 - 4 ---> 6
2 - 4 ---> 7
1 - 4 ---> 8
0 - 4 ---> 9
4 - 5 ---> 10
3 - 5 ---> 11
2 - 5 ---> 12
1 - 5 ---> 13
0 - 5 ---> 14
...
...
...

Finally
a - b ---> x
so i want an equation were i put the values 'a' and 'b' and it gets me x, I know how to solve this using loops but i am dealing with x numbers of 500,000 so my loop will have to do 500,000 loops and you know that's not good.
I can't find the recurrence relation too.

Edited by lomateron, 16 October 2012 - 08:43 AM.


Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 12916

Like
0Likes
Like

Posted 16 October 2012 - 09:13 AM

x = b*(b+1)/2 -a -1;

#3 lomateron   Members   -  Reputation: 329

Like
0Likes
Like

Posted 16 October 2012 - 09:16 AM

SOLVED:
Having 'a' and 'b', I compare who is the biggest, then I put the biggest in the equation (n^2+n)/2=h
then i take h put it in this other equation: h-'the smallest between and b'-1 = x
thats all.

#4 lomateron   Members   -  Reputation: 329

Like
0Likes
Like

Posted 16 October 2012 - 09:21 AM

Alvaro i am curious of how you solved it, i was posting my solution when you posted yours.

Edited by lomateron, 16 October 2012 - 09:22 AM.


#5 Álvaro   Crossbones+   -  Reputation: 12916

Like
1Likes
Like

Posted 16 October 2012 - 09:31 AM

Let's call F(a,b) = x. I put your examples into a table, I observed that F(n-1,n) are triangular numbers, and it was simple manipulation from there. I verified the result with this command line:
> perl -e 'for ($b=1; $b<6; ++$b) {for ($a=$b-1; $a>=0; $a--){$x = $b*($b+1)/2-$a-1; print "$a - $b ---> $x\n"}}'
0 - 1 ---> 0
1 - 2 ---> 1
0 - 2 ---> 2
2 - 3 ---> 3
1 - 3 ---> 4
0 - 3 ---> 5
3 - 4 ---> 6
2 - 4 ---> 7
1 - 4 ---> 8
0 - 4 ---> 9
4 - 5 ---> 10
3 - 5 ---> 11
2 - 5 ---> 12
1 - 5 ---> 13
0 - 5 ---> 14

Edited by alvaro, 16 October 2012 - 09:32 AM.


#6 Emergent   Members   -  Reputation: 971

Like
0Likes
Like

Posted 17 October 2012 - 06:27 PM

Hah! So now we all know how to index upper-triangular matrices. Or store edge weights for undirected graphs. Same difference. :-)

#7 lomateron   Members   -  Reputation: 329

Like
0Likes
Like

Posted 17 February 2013 - 07:37 PM

now i wanna know the opposite way, now i have "x" and i want "a" and "b"

I have a solution, want to know if there is a faster way

 

v=sqrt(2*(x+1)-0.25)+0.5

take out the decimals of that "v" and its the correct "b"

a= (b*(b+1)/2) - (x+1)


Edited by lomateron, 18 February 2013 - 07:09 AM.


#8 Álvaro   Crossbones+   -  Reputation: 12916

Like
0Likes
Like

Posted 17 February 2013 - 09:19 PM

Nevermind, I am not sure of what I wrote. I'll check more carefully before posting again.

Edited by Álvaro, 17 February 2013 - 09:20 PM.


#9 lomateron   Members   -  Reputation: 329

Like
0Likes
Like

Posted 18 February 2013 - 04:49 AM

I edited my last post thinking i was wrong, now i want to know what it says



#10 Álvaro   Crossbones+   -  Reputation: 12916

Like
0Likes
Like

Posted 18 February 2013 - 01:16 PM

I edited my last post thinking i was wrong, now i want to know what it says

There is a `History' button below the post. Doesn't that work?




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS