Thread: Sigmaze! -- Second Attempt.

  1. #31
    Registered User
    Join Date
    Oct 2004
    Posts
    26
    Yay, the board is working!

    Kudos to sang-drax, for working SMART as opposed to hard! Congrats.

    quzah, C++ vs C actually did make a little difference in shaving some characters off:
    1) for each of your 3 includes, use
    Code:
    #include<c*>
    instead of
    Code:
    #include <*.h>
    which will save 6 characters (3 spaces, 3 characters)

    2) replace the two-line X and Y #define directives (26 chars) with a single line const
    declaration
    Code:
    const int Y=11,X=23;
    (20 chars).

    That's 12 characters trimmed. One of the rare instances in which C++ is not biggified compared to C!!

    Also, I have a question about your two macros:

    Code:
    #define A _[y][x]
    #define C(D,E,F,G,H)if(D&&_[E][F]){A|=G;_[E][F]|=H;}else
    Is that "A" in the second line supposed to be substituted from the first line? I didn't know you could do that (macros within macros). Is that standard, or implementation dependent?

  2. #32
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Congrats zzzaaahhh, great looking code!

    Quzah, did you post all of the entries you recieved? Can't tell if you are still writing results or not and I'd be curious to see how mine fared even though I know I didn't come close to winning.

  3. #33
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    zzzaaahhh, if you use the cstdlib header instead of stdlib.h, the names in the header will reside in the std namespace. If you use the C++ versions of the C headers, you'll have to access the names with std:: or use 'using namespace std;'.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #34
    Registered User
    Join Date
    Oct 2004
    Posts
    26
    Quote Originally Posted by Sang-drax
    zzzaaahhh, if you use the cstdlib header instead of stdlib.h, the names in the header will reside in the std namespace. If you use the C++ versions of the C headers, you'll have to access the names with std:: or use 'using namespace std;'.
    Didn't know that. I've experienced that with C++ names like cout or cin, but the GNU compiler has always let me use things out of <clibrary> (corresponding to <library.h>) without specifying the namespace. e.g., I used printf, srand, and time from <cstdio>, <cstdlib>, and <ctime> without specifying 'std::', and it compiled without even a warning, even with the -ansi and -pedantic flags.

    But if that's nonstandard, then it just goes to show that C++ really is biggified compared to C!

  5. #35
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by zzzaaahhh
    Also, I have a question about your two macros:
    Code:
    #define A _[y][x]
    #define C(D,E,F,G,H)if(D&&_[E][F]){A|=G;_[E][F]|=H;}else
    Is that "A" in the second line supposed to be substituted from the first line? I didn't know you could do that (macros within macros). Is that standard, or implementation dependent?
    Yes and yes, it's standard. You can even have macros with the name of the macro appearing in the macro itself. However, some old compilers may not like it and try to continually expand it. So that's generally avoided.

    Quote Originally Posted by PJYelton
    Quzah, did you post all of the entries you recieved? Can't tell if you are still writing results or not and I'd be curious to see how mine fared even though I know I didn't come close to winning.
    I wasn't sure if you wanted it entered. Here it is:
    :~/programming/maze$ ls -al pjyelton.cpp
    -rwxrwxr-x 1 root windows 556 Oct 12 19:06 pjyelton.cpp
    As is, the output was:
    Code:
    *****************************************
    *.*.....................*.....*.........*
    *.*.*****************.*.*.*****.*******.*
    *.*...*.............*.*...*.....*.....*.*
    *.***.*.***********.*.*****.*****.***.*.*
    *.*...*.......*.*...*.....*.*.*.....*.*.*
    *.*.*********.*.*.*******.*.*.*.*****.*.*
    *.*.........*...*.*.....*.*.*...*.....*.*
    *.*********.*.***.*.***.*.*.*.***.***.*.*
    *.*.....*...*.*...*...*...*.*...*...*.*.*
    *.*****.*.***.*.*****.*****.*******.*.*.*
    *.*.....*...*.*...*...*.....*.......*.*.*
    *.*.*******.*.***.*.***.*****.*********.*
    *.*.......*.*.*.*.*.*...*.....*.......*.*
    *.***.***.*.*.*.*.*.*.***.*****.*****.*.*
    *...*.*...*.*.*.*.*...*...*.....*.......*
    ***.***.***.*.*.*.*****.***.***********.*
    *...*...*...*...*.*.......*...*.......*.*
    *.***.***.*****.*.*.*****.***.*.*****.***
    *.*...........*.*.......*...*.*.*...*...*
    *.***********.*********.*.*.*.*.*.*****.*
    *.......*.....*.......*.*.*.*...*.....*.*
    *******.***.***.*****.***.*.*****.***.*.*
    *.....*...*.*.......*.....*.*.....*...*.*
    *.***.***.*.*******.*******.*.*****.***.*
    *.*.*.....*...*.....*...*...*.*...*...*.*
    *.*.*********.*.*****.*.***.*.*.*.***.*.*
    *.....*.....*.*.......*...*.*...*...*.*.*
    *****.*.*.*.*.*.*********.*.*****.***.*.*
    *.....*.*.*.*.*...*.....*.*...*...*...*.*
    *.*****.*.***.***.*.***.*.***.*.***.***.*
    *.*...*.*.*...*...*...*.*...*.*.*...*...*
    *.*.***.*.*.*****.*****.***.*.*.*.***.***
    *.*.....*...*...*.*...*...*.*.*.*...*...*
    *.***.*******.*.*.*.*.*.***.*.*****.***.*
    *...*.........*.*...*...*...*.......*.*.*
    ***.*.*********.*********.*.*******.*.*.*
    *.*.*.*.....*.............*.*...*.....*.*
    *.*.***.***.*****************.*.*******.*
    *.......*.....................*.........*
    *****************************************
    It also meets the requirements as far as resizability and the like. The code itself is:
    Code:
    #include<iostream>
    #include<time.h>
    #define X 20
    #define Y 20
    #define c std::cout<<
    #define i int
    #define M m[x][y]
    #define U m[x+e[v][0]][y+e[v][1]]
    #define u x+e[v][0],y+e[v][1]
    #define v z%4
    #define f(o,p) for(o=0;o<p;o++)
    char m[X][Y]={0};bool w(i x,i y){return(x<0||y<0||y==Y||x==X);}i e[4][2]={{0,-1},{-1,0},{0,1},{1,0}};void R(i x,i y){i z=rand()%4;i q;f(q,4){z++;if(!w(u)&&!U){M|=1<<v;U|=1<<(v+2)%4;R(u);}}}i main(){srand(time(0));i x,y;R(0,0);c"*";f(x,X)c"**";c"\n";f(y,Y){f(x,X)(M&2)?c"..":c"*.";c"*\n";f(x,X)(M&4)?c"*.":c"**";c"*\n";}return 0;}
    Pointwise, we'd end up with:

    1000 - (56 * 10) = 440 points.

    However, that one huge line of code would anger everyone if you did manage to fit it in your sig.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #36
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Heh, thanks

    Not sure why it came out on one line like that, it didn't appear like that to me.

  7. #37
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well, the only reason I mention the line length, is because apparently everyone hated my 300 line sig I had. So I assumed they'd hate that too.

    Quzah.
    Hope is the first step on the road to disappointment.

  8. #38
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    You don't need bool, use 'i' (int)... 3 bytes spared. Is srand(time(0)); really necessary to be called?? You don't need to add i in the declaration of main, because most compilers, which include the ones we use, use int as default return type, me thinks. And you have at the end return 0;. Ok, is good practice, but not 100% necessary... I think the point where is to squeze the code.

  9. #39
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    The code in question was to compile without warnings. That was part of the requirement. Furthermore, since the maze to be generated was supposed to be random, yes, seeding rand was also necessary.

    Quzah.
    Hope is the first step on the road to disappointment.

  10. #40
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    but I'll guess you'll agree with this one
    You have
    #define f(o,p) for(o=0;o<p;o++)
    Put instead
    #define f(p) for(i o=0;o<p;o++)
    So you don't need to declare any vars for the cicle.

    Look here:
    return x<0||y<0||y==Y||x==X;
    No parenthesis, 1 byte spared.

    Here's another stuff
    http://www.cppreference.com/operator_precedence.html
    So
    (M & 2) ? c".." : c"*.";
    (M & 4) ? c"*." : c"**";
    become
    M&2 ? c".." : c"*.";
    M&4 ? c"*." : c"**";
    No parenthesis, 4 bytes spared.
    Last edited by xErath; 11-09-2004 at 04:02 PM.

  11. #41
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'll agree that they actually made an entry. I didn't see yours any place.

    Quzah.
    Hope is the first step on the road to disappointment.

  12. #42
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Well said Quzah

    Hell, considering I'd never written code like this before, I'm pretty proud I got to within 56 bytes even if I could have shaved an extra couple here and there.

  13. #43
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    I'm not compeeting, nor have time.. I have lots of homework to do.. bah!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with my first linked list attempt.
    By SlyMaelstrom in forum C++ Programming
    Replies: 3
    Last Post: 11-09-2005, 04:33 AM
  2. Naming folders after the date - my futile attempt
    By shoobsie in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2005, 09:50 AM
  3. *NOOB* attempt to make a calc prog
    By Inferno in forum C Programming
    Replies: 3
    Last Post: 08-30-2004, 10:38 AM
  4. switch - first attempt...
    By Nutka in forum C Programming
    Replies: 4
    Last Post: 10-04-2002, 09:58 PM