CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2008
    Posts
    2

    Talking Can someone explain what this function does?

    Hi guys,

    I need to re-write this function in scheme but I'm confused on what this function even does, can someone explain it to me?

    Thanks


    Code:
    int aFunction(int n) {
    int c;
    for (int c = 1; c != 0; ) {
    if (n > 100) {
    n = n - 10; c--; }
    else {
    n = n + 11; c++; }
    }
    return n;
    }

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Can someone explain what this function does?

    It looks some some simple numerical trickery. Rewriting it in a different language probably shouldn't require in-depth understanding of the mathematics.

    EDIT: Heh. I think it'll probably always return the same value if the initial n < 100.

    EDIT2: I'll give you this much: The function could be simplified to the form
    max(n-m,k). I'll let you figure out what m and k are.
    Last edited by Lindley; September 5th, 2008 at 10:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured