Like Tree1Likes

Almost Daily Contest #4

This is a discussion on Almost Daily Contest #4 within the Contests Board forums, part of the Community Boards category; For Everyone Given an array of strings in the form of a word search game, write a function: int wordSearch(const ...

  1. #1
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796

    Almost Daily Contest #4

    For Everyone

    Given an array of strings in the form of a word search game, write a function:

    int wordSearch(const char **tab, const char *word, int *indices);

    That finds any occurance of 'word' in the table 'tab'. The function will return 0 if the word does not exist in the table and 1 if the word is found. The two-dimensional indices of the word will be placed in the array 'indices'. The list of indices will be terminated by an invalid index, -1.

    Words can be found forward, backward, up, down, and diagonal in any direction. You may assume that all input will be correct and valid with the exception of a word not being present.

    Example:
    Given the following declarations:
    Code:
    char *tab[] = {
        "abcde",
        "bcdef",
        "caefg",
        "dtfgh",
        "efghi",
        ""
    };
    
    int indices[11] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
    the function call wordSearch(tab, "cat", indices); will return 1 and indices will contain the following: {1,1,2,1,3,1,-1,-1,-1,-1,-1}

    Testing Categories
    Code brevity. The smallest source file (in number of characters) with correct output wins.

    Contest Ends: Wednesday, August 27, 2003
    My best code is written with the delete key.

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Will you ignore whitespace and new lines when counting characters?
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >Will you ignore whitespace and new lines when counting characters?
    The table will contain only letters in the latin alphabet, case sensitive. The string to be searched for will be the same.
    My best code is written with the delete key.

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I meant when counting the characters in the submitted source code.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I meant when counting the characters in the submitted source code.
    Oh. Yes, whitespace counts.
    My best code is written with the delete key.

  6. #6
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Prelude, I'm not sure that's such a good idea :P People are going to use #defines and random obfuscation tricks now. ...At least, I would, if I was going to try this
    Away.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >People are going to use #defines and random obfuscation tricks now.
    That's fine. No matter how much you crush your code down, the truly elegant solutions will still be smaller.
    Matticus likes this.
    My best code is written with the delete key.

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I'm a little confused about the index array. When the word is found, will the location for the letters be stored in the index array? Like: X1, Y1, X2, Y2, X3, Y3 etc...?

    When counting the characters (of the source file), is it only the characters found in the function? If it includes the entire file, can we leave int and return 0 out of main to reduce the size? ^^
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Salem
    > is it only the characters found in the function?
    Well I'm just going to post a function with the defined interface.
    Yes, that may be wise. On the other hand, Prelude may claim that it is "uncompilable"...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  10. #10
    Wen Resu
    Join Date
    May 2003
    Posts
    219
    I'm a bit confused,
    is the table going to contain what was defined above, or is it a user inputed.
    thanks

  11. #11
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    And also, is it fixed length to that size?

  12. #12
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    :: double post, sorry ::

  13. #13
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I assumed that the table could be variable in size.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  14. #14
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    Oh I see, the empty string at the end. But will all the rows have the same number of characters?

  15. #15
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    I have already submitted my entry - I haven't time to work on it later anyway. I assumed that all lines were of equal size.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Almost Daily Contest Details
    By dagdarian in forum Contests Board
    Replies: 4
    Last Post: 01-25-2005, 05:03 AM
  2. Almost Daily Contest Details
    By Prelude in forum Contests Board
    Replies: 29
    Last Post: 09-19-2004, 11:32 PM
  3. Almost Daily Contest #3
    By Prelude in forum Contests Board
    Replies: 29
    Last Post: 08-16-2003, 09:48 PM
  4. Almost Daily Contest #2
    By Prelude in forum Contests Board
    Replies: 37
    Last Post: 08-09-2003, 11:51 PM
  5. Almost Daily Contest #1
    By Prelude in forum Contests Board
    Replies: 32
    Last Post: 08-05-2003, 09:34 AM

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