• Let's play "Name that code fragment"

    From James Dow Allen@21:1/5 to All on Sat Jul 18 01:26:46 2020
    The party game "Name that tune" is fun. Hum just a few notes and
    see who can guess the song. How about "Name that code fragment"?
    From a few lines of programming code can you guess what sort of
    application the code is from or what function is implemented?

    There are some top programmers who hang out in this ng, so this might
    be as good a newsgroup as any to try this game. PLEASE POST YOUR OWN
    CODE FRAGMENTS AS A CHALLENGE. But I will get us started with
    three examples.

    In every case, the code is taken from real code, but some of the
    identifier names are replaced with "FOO..." to make the application
    less obvious. And silly micro-optimizations are allowed to increase
    the challenge.

    REMEMBER: You needn't "debug" the code fragment, or reconstruct
    missing macros, etc. It's enough to just GUESS what sort of
    thing the code does.

    ~~~~~~~
    Fragment #01:
    int FOO_100(uint64 newboard)
    {
    uint64 y = newboard & (newboard >> HEIGHT);
    if ((y & (y >> 2 * HEIGHT)) != 0)
    return 1;
    y = newboard & (newboard >> H1);
    if ((y & (y >> 2 * H1)) != 0)
    return 1;
    y = newboard & (newboard >> H2);
    if ((y & (y >> 2 * H2)) != 0)
    return 1;
    y = newboard & (newboard >> 1);
    return (y & (y >> 2)) != 0;
    }

    ~~~~~~~
    Fragment #02:
    lg = long2 - long1;
    y = sin(lat1);
    t = cos(lat1);
    x = t * sin(lg);
    z = t * cos(lg);
    r = sqrt(y*y + z*z);
    a2 = cos(atan2(y, z) - lat2);
    y = - r * a2;
    return 10008 + 6371 * atan2(y, sqrt(1 - y*y));

    ~~~~~~~
    Fragment #03:
    #define DX(a,b) (Pt[a].x - Pt[b].x)
    #define DY(a,b) (Pt[a].y - Pt[b].y)
    #define NX(a,b,c) (DX(a,b) * DY(c,a) > DX(c,a) * DY(a,b))

    ...
    return 1 ^ NX(0,1,2) ^ NX(1,2,3) ^ NX(2,3,0) ^ NX(3,0,1);


    Hope to see some response!
    Yours truly,
    James Dow Allen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)