Thread: A problem I can't figure out at all!

  1. #16
    Registered User Stormboy's Avatar
    Join Date
    Aug 2013
    Location
    Planet Earth
    Posts
    12
    Quote Originally Posted by oogabooga View Post
    Here's a fix-up of the code from post #5.
    It gets the same answer as yours.
    Code:
    #include <stdio.h>
    
    int main(void) {
        unsigned t = 287, p = 165, tri, pent;
    
        do {
            p++;
            pent = p * (3 * p - 1) / 2;
            t -= 2;
            do {
                t += 2;
                tri  = t * (t + 1) / 2;
            } while (tri < pent);
        } while (tri != pent);
    
        printf("t=%u p=%u result=%u\n", t, p, tri);
    
        return 0;
    }
    /* Output:
    t=55385 p=31977 result=1533776805
    */
    Holy cow. Even if its in C, its way shorter than mine and works correctly. ;O. Nice one man.

  2. #17
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by MutantJohn View Post
    Wait, if we have 3 equations with 3 unknowns, can't we just represent this as a linear system of equations?
    You're right about the 3 equations and 3 unknowns, but the equations are quadratic not linear.
    Code:
    t * (t + 1) / 2 == p * (3 * p - 1) / 2 == h * (2 * h - 1)
    
    or (using ** to mean "to the power of")
    
    t**2 + t == 3*p**2 - p == 4*h**2 - 2*h
    One of the math gurus here can tell us if this is solvable as a system of equations.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #18
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by oogabooga View Post
    You're right about the 3 equations and 3 unknowns, but the equations are quadratic not linear.
    Code:
    t * (t + 1) / 2 == p * (3 * p - 1) / 2 == h * (2 * h - 1)
    
    or (using ** to mean "to the power of")
    
    t**2 + t == 3*p**2 - p == 4 h**2 - 2 h
    This could be written as 3 equations, 4 unkowns

    t**2 + t == 2 s
    3*p**2 - p == 2 s
    4*h**2 - 2*h == 2 s

    Some solutions for (h, p, t, s):
    (0, 0, 0, 0)
    (143, 165, 285, 40755)
    (27693, 31977, 55385, 1533776805)
    (5372251, 6203341, 10744501, 57722156241751)
    (1042188953, 1203416145, 2084377905, 2172315626468283465)
    Last edited by rcgldr; 08-30-2013 at 10:54 AM.

  4. #19
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by rcgldr View Post
    This could be written at 4 equations, 3 unkowns

    t**2 + t == 2 s
    3*p**2 - p == 2 s
    4*h**2 - 2*h == 2 s

    Solutions so far for (h, p, t, s) == (0, 0, 0, 0) , (143, 165, 285, 40755), (27693, 31977, 55385, 1533776805)
    Arghh! You're right, I wasn't thinking.
    Although it's 3 equations and 4 unknowns.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  5. #20
    Registered User
    Join Date
    Jan 2011
    Posts
    144
    how in the world did you get up to question 45? I'm still on qn 3 lol... :|

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cannot figure out my problem can anyone help?
    By caffrea4 in forum C++ Programming
    Replies: 3
    Last Post: 04-20-2011, 01:50 PM
  2. figure - problem
    By jamesfisher in forum C++ Programming
    Replies: 6
    Last Post: 11-10-2009, 05:28 PM
  3. I cant figure the problem out!
    By jturner38 in forum C Programming
    Replies: 5
    Last Post: 03-25-2009, 01:13 AM
  4. strcmp problem, whats the problem, i cant figure it out!
    By AvaGodess in forum C Programming
    Replies: 14
    Last Post: 10-18-2008, 06:45 PM
  5. Can'nt figure out problem
    By HAssan in forum C Programming
    Replies: 7
    Last Post: 12-26-2005, 08:11 PM

Tags for this Thread