Thread: Does this problem have more than what it seems to me ?

  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    Does this problem have more than what it seems to me ?

    Does this problem have more than what it seems to me ?-prob7-png
    It seems, to me that the program/function always terminates.
    (Though it doesn't produce the intended result (the function is named 'mu' which I guess, is for multiplication) for a < 0).
    And the 'Q' required is just the Loop Invariant (right?), which I think is "y=i*b".

    Or am I missing something large, considering that this is for a post grad paper and I've just begun my college education(two weeks, to be exact).

    (The whole question paper is here)
    Attached Images Attached Images Does this problem have more than what it seems to me ?-prob7-png 
    Last edited by manasij7479; 07-16-2012 at 10:42 AM.

  2. #2
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    I have a hunch that condition P is about finding/avoiding boundary conditions to get an infinite loop, but that is most likely wrong.
    If the loop invariant were say
    i <= a
    instead of
    i < a
    , then we have an infinite loop at
    mu(INT_MAX,x)
    .
    For the given case though, I couldn't find any.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Yeah, I'm not getting it either; the instructions are crazy vague.

    Code:
    if (0 = 0) do exit
    Does that insanity actually fit both roles?

    Soma

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Q should be some expression involving a,b,i,y (those things involved in the loop)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Q should be some expression involving a,b,i,y (those things involved in the loop)
    Bwahahaa!

    Okay, so, just to confirm here, this isn't about writing code at all is it? It is about reasoning through existing code isn't it?

    Soma

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    I think so.
    Something conceptually similar to assert.
    Thats why I think Q will be "y==i*b".
    But I have no idea what P can be.

    (W.r.t the first comment, shouldn't language/implementation based things like INT_MAX, be left out of consideration in algorithms? )

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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
  2. Replies: 4
    Last Post: 10-16-2008, 07:30 PM
  3. sturct/pointer problem, and fscanf problem
    By hiphop4reel in forum C Programming
    Replies: 6
    Last Post: 07-28-2008, 09:40 AM
  4. Visual Studio Linker problem or my problem?
    By OOPboredom in forum C Programming
    Replies: 2
    Last Post: 04-13-2004, 12:32 AM
  5. syntax linked list problem & struct problem
    By beely in forum C Programming
    Replies: 5
    Last Post: 11-11-2002, 09:14 AM