Programming Contest--The Problems

This is a discussion on Programming Contest--The Problems within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I just got back from a programming contest, figured some people here might like to try out some new problems. ...

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903

    Programming Contest--The Problems

    I just got back from a programming contest, figured some people here might like to try out some new problems. I personally found them both very easy, so I'm not sure how much of a challenge they'll be.
    Attached Images Attached Images  

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    problem #1's too big to fit here without making it unreadable, so it's hosted on my site:

    http://thejefffiles.com/viewimage.ph...s/prob1pg1.jpg
    http://thejefffiles.com/viewimage.ph...s/prob1pg2.jpg

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Ugly brute force gets the two pretty quick:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int compare(const void *a, const void *b)
    {
       const char *x = a, *y = b;
       return *x > *y ? 1 : *x < *y ? -1 : 0;
    }
    
    int main(void)
    {
       static const char key[] = "123456789";
       unsigned long i;
       for (i = 0; i < 32767; ++i)
       {
          char buffer[16];
          unsigned long i2 = i * i;
          int len = sprintf(buffer, "%lu%lu", i, i2);
          if ( len == 9 )
          {
             qsort(buffer, len, sizeof *buffer, compare);
             if ( strcmp(buffer, key) == 0 )
             {
                printf("%lu ** 2 == %lu\n", i, i2);
                fflush(stdout);
             }
          }
       }
       return 0;
    }
    Last edited by Dave_Sinkula; 02-27-2005 at 12:02 PM. Reason: [1] Added 'len' to minimize qsorting. [2] Corrected buffer size (thanks).
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Impressive programming, but I can do it in one line.
    Code:
    #include <windows.h>
    
    int main(void)
    {
        ShellExecute(NULL, TEXT("open"), TEXT("http://www.jobfood.com/mwBrainTeaser...er01.asp?Nr=13"), NULL, NULL, SW_SHOW);
        return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Expression Evaluator Contest
    By Stack Overflow in forum Contests Board
    Replies: 20
    Last Post: 03-29-2005, 09:34 AM
  2. New Monthly Contest!
    By PJYelton in forum Contests Board
    Replies: 50
    Last Post: 03-22-2005, 07:27 PM
  3. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 08:19 PM
  4. Intercollegiate programming contest problems
    By questionsForYou in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 01-13-2003, 02:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21