Thread: Sigmaze! -- Second Attempt.

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by major_small
    I would consider that hardcoding... to me, hardcoding would be like to use a random number generator or use a config file or ask the user for input every time...

    or did you mean just make it easy for you to change because you have the source?
    Right, easy to change. That takes an edit of 2 variables, where as if I replaced every instance of X with the number 10 in my source code, that would not be "easy" to change. (I'd have to go hunting to figure out everywhere it's supposed to be changed.) Poor wording on my part.

    Actually though, the reason I didn't use integers instead of defines, is because even in C99 if I do, it won't compile without warnings.

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

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Sang-drax
    OK, that makes sense. With that definition of 'perfect maze' I have made a program that generates a random perfect maze. It's currently 415 bytes, but I haven't done any optimizations like removing newlines and removing cin.get() at the end.
    I will submit it before the contest ends.

    I find it a bit strange that the creator of the contest participtes himself, but I guess we could live with it.
    Well you shouldn't worry, you can see in my sig where I'm at byte wise, so it really doesn't matter if I participate, since I'm losing.

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

  3. #18
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by quzah
    Well you shouldn't worry, you can see in my sig where I'm at byte wise, so it really doesn't matter if I participate, since I'm losing.
    Well, my solution is much simpler than yours, but as long as it meets the criterias, I guess it's OK.
    It's nothing I'm proud of though.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  4. #19
    Registered User
    Join Date
    Oct 2004
    Posts
    26
    This looks like a cool contest! I hope you will post the winning programs, which should be very instructive. Related to which, can I suggest a slight change in the rules? For people to be able to comprehend the programs, they have to be nicely spaced. So instead of how many bytes the file occupies on disk, can you make the shortness criterion the number of nonspace characters? Otherwise, you're going to get code that looks like this:

    Code:
    #include<whatever>
    #define X 10
    #define Y 12
    #define F(u,U) for(u=0;u<U;u++)
    int main(){int a[X][Y],b[X*Y],c,d,e,f,g,h[4],i,j,k;
    F(c,X)F(d,Y)a[c][d]=magicnumber;srand(time(NU
    LL));c=rand()%X;d=rand()%Y;F(e,X*Y){f=c?c-1:
    c+1;g=d?d-1:d+1;otherincomprehensiblegobble
    dygook}F(i,X){F(j,Y)printf(a[i][j]&bitdiddle?"##"
    :"  ");F(j,Y)printf(a[i][j]&diddlebit?"#  ":"   ");}ret
    urn 0;}
    which no one will get anything out of.

  5. #20
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by zzzaaahhh
    This looks like a cool contest! I hope you will post the winning programs, which should be very instructive. Related to which, can I suggest a slight change in the rules? For people to be able to comprehend the programs, they have to be nicely spaced. So instead of how many bytes the file occupies on disk, can you make the shortness criterion the number of nonspace characters? Otherwise, you're going to get code that looks like this:

    ...snip...

    which no one will get anything out of.
    What's wrong with that? I've yet to see an entry which meets the requirements at all. I don't care what it looks like, as long as it gives appropriate output. It just has to fit in the sig. You can make it look like whatever you want if you're so inclined.

    I may hand out some extra "style points" if it looks slick. But don't count on that alone to win. I'm thinking something along the lines of:

    1000 base points.
    +10 points per character under 500.
    -10 points per character over.
    -N points for unreached cells in the maze.
    Code:
    #####
    ##  #
    ## ##
    #   #
    #####
    -N points for unconnected paths/cells in the maze.
    Code:
    #####
    #   #
    #####
    #   #
    #####
    I'll likely give bonus points for anything really slick either in the output or the code itself.

    I'll probably just compile as-is, with given values, and see the output, then I'll change to a few given sets of values (yet to be determined, probably with the roll of a dice or two) to see what that gives for output, scoring all output. Broken output or incorrect output also will detract.

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

  6. #21
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by quzah
    I've yet to see an entry which meets the requirements at all.
    I've sent you a PM.
    Please don't change the requirements now
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #22
    Registered User
    Join Date
    Oct 2004
    Posts
    26
    Quote Originally Posted by quzah
    I don't care what it looks like, as long as it gives appropriate output. It just has to fit in the sig....

    ...I'm thinking something along the lines of:

    1000 base points.
    +10 points per character under 500.
    -10 points per character over.
    -N points for unreached cells in the maze. ....
    -N points for unconnected paths/cells in the maze. ....

    I'll likely give bonus points for anything really slick either in the output or the code itself.

    I'll probably just compile as-is, with given values, and see the output, then I'll change to a few given sets of values (yet to be determined, probably with the roll of a dice or two) to see what that gives for output, scoring all output. Broken output or incorrect output also will detract.

    Quzah.
    Ok, readability is not a criterion for the contest. But if/when you do post the winners, can you ask the winners to decompress & comment them?

    Also, you didn't mention whether there would be any penalties for compiler warnings. Is it better to be <500 characters, with a couple noncritical warnings, or a couple characters >500, with no warnings?

  8. #23
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well if it is over 500, then it doesn't fit in the sig box which is the whole purpose of the contest. However, it should compile without warnings with "-Wall -pedantic" as stated. As to commenting, I'll leave it as an exercise for the reader.

    As of yet, I don't have an entry which will qualify for the 500 character mark. It turns out a nice looking maze though. I'm on my third maze generation algorithm now, trying to get into 500 characters.

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

  9. #24
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well I gave up on the fractal version. So I'm back to my old stand-by, which I have down (as of typing) to 548! If I leave out the #includes, I can make it with four warnings. *sob*

    There seems to be some confusion as to how the entries relate to the sig space. So, to clarify again, the code will be pasted into my sig box, and from there into a .c or .cpp file, and then compiled. So when testing your code, do it that way to see if it turns out like you want it to. Because that's what I'll be doing. I believe that was all covered in the initial post regarding the contest.

    If your code requires code tags, make sure it's small enough to fit after you subtract the amount of room the code tags absorb. (I will be taking my count from the copy-paste from the sig box to tally up your byte total. Thus, if you did in fact use code tags, your code would clock in easily under 500, since the code tags themselves eat up some of the 500 bytes the sig uses.)

    I have two submissions so far for #2, both of which do things differently than I do. There are no submissions for #1 yet. If I can squeeze another 48 bytes out of my code I'll try for a slick looking maze for #1.

    Have fun and good luck.

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

  10. #25
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Ok, posted my entry. Just north of the limit at approximately 530 characters and unfortunately I'm stumped how to lose the last few bytes. Oh well, at least it makes a pretty maze.

  11. #26
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Great. Keep those entries headed my way. If you come up with a new version before the end of the month, send it on over.

    I get 556 with an "ls -al" on yours PJ, after pasting it in from your PM.

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

  12. #27
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Since the forum has been down for a week or so, I'll give everyone a few days to get any entries in to me. Then I'll start posting the code I received and my comments on them, points, etc.

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

  13. #28
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by quzah
    I may hand out some extra "style points" if it looks slick. But don't count on that alone to win. I'm thinking something along the lines of:

    1000 base points.
    +10 points per character under 500.
    -10 points per character over.
    -N points for unreached cells in the maze.
    Alright, let's put up an entry and see what we get...
    e:~/programming/maze/shang$ ls -al shang*
    -rwxrwxr-x 1 root windows 15527 Nov 4 22:55 shang
    -rwxrwxr-x 1 root windows 417 Oct 10 20:43 shang.cpp
    -rwxrwxr-x 1 root windows 15345 Nov 4 22:56 shang2
    -rwxrwxr-x 1 root windows 352 Nov 4 22:56 shang2.cpp
    The executable size doesn't matter. Shang sent in two versions. The second is the one we'll use, because it was done after a bit of shrinking. This gives us the following output:
    Code:
    :~/programming/maze/shang$ g++ -o shang2 shang2.cpp -Wall -pedantic
    :~/programming/maze/shang$ ./shang2
    ##############################
    #                            #
    ## ###########################
    #                            #
    ##### ########################
    #                            #
    ###### #######################
    #                            #
    ################# ############
    #                            #
    ################## ###########
    #                            #
    ############# ################
    #                            #
    ######################## #####
    #                            #
    ##############################
    Compiles witout warnings (and naturally without errors, otherwise it wouldn't compile). Shang's version has the simplest interpretation of a 'true maze'. However it does meet the requirement. As far as that goes, it is in fact quite good at interpreting my words of what a maze was. It is the minimalist approach. The bare minimum needed to be considered a maze. The break poin in the horizontal row ends up randomly placed, and that's all it needs to do.

    Resizing was simple as it was supposed to be, and didn't give any unexpected results. Space wise, it's the winner of what I was sent.

    Given the above scoring:

    1000 base + ((500 - 352) * 10) = 2480 points.

    Here's his code, which works in a sig as it should:
    Code:
    #include <iostream>
    #include <iomanip>
    #include <cstdlib>
    #include <ctime>
    using namespace std;
    int w=30;
    int h=15;
    void c(int n,char q='#'){cout<<setw(n)<<setfill(q)<<"";}int main()
    {srand(time(0));c(w);for(int y=1;y<=h;y++){cout<<endl;c(1);c(w-2,' '),
    c(1);if(++y>=h)break;cout<<endl;int s = 1+rand()%(w-2);c(s);c(1,' ');
    c(w-s-1);}cout<<endl;c(w);}
    It doesn't require any code tags or anything wrapping it for it to work.

    I also received an entry from zzzaaahh. Here's what we have:
    :~/programming/maze/zzzaaahhh$ ls z* -al
    -rwxrwxr-x 1 root windows 13709 Oct 13 17:06 zzzaaahh2
    -rwxrwxr-x 1 root windows 487 Oct 13 17:06 zzzaaahh2.cpp
    -rwxrwxr-x 1 root windows 501 Oct 11 22:35 zzzaaahhh.cpp
    The first character had problems with the way whitespace is handled in the sig box, so a second version was sent. It's the version we're using for judging.
    Code:
    :~/programming/maze/zzzaaahhh$ g++ -o zzzaaahh2 zzzaaahh2.cpp -W
    all -pedantic
    :~/programming/maze/zzzaaahhh$ ./zzzaaahh2
    ###############################
    #        #  #  #              #
    #  ####  #  #  #  ##########  #
    #     #  #  #           #     #
    ####  #  #  #  ##########  #  #
    #  #  #  #  #  #        #  #  #
    #  #  #  #  ####  ####  #  #  #
    #     #     #     #  #  #  #  #
    #  ##########  ####  #  #  #  #
    #     #        #     #  #  #  #
    ####  #  #######  #  #  #  ####
    #  #     #     #  #     #     #
    #  #######  ####  ##########  #
    #     #     #     #        #  #
    ####  #  #  #  ####  ####  #  #
    #     #  #  #  #     #     #  #
    #  ####  #  #  ####  #  ####  #
    #        #  #        #     #  #
    #  #######  #############  #  #
    #        #                    #
    ###############################
    It turns out a nice looking maze. This is more of what I had in mind when I was thinking along the lines of making a maze generator, but Shang's does in fact fill the requirements. We don't gain or lose anything by resizing the maze, and it is equally as easy to resize as Shang's code.

    However, we have one requirement for this code to be functional when copied from the sig box: It requires code tags. Without it, we have problems with the white space getting eaten, and the maze doesn't turn out right. However! The code, with code tags, is exactly 500 bytes in size. Code tags take a total of 13 characters.

    While it wasn't a requirement that you have room for code tags, or that they be present at all, this code does both, and is exactly 500 characters doing so. That's pretty snazzy.

    Here's the code:
    Code:
    [code]#include<cstdio>
    #include<cstdlib>
    #include<ctime>
    #define I(u,v) if(c u&&m[v+c]&1)a[k++]=v+c;
    #define F for(n=0;n<H;n++)printf
    #define X printf("#\n");
    const int V=10,H=10;int m[V*H],a[4],n=0,t=0;
    void f(int c){int k=1;m[c]&=6;
    while(k){k=0;I(%H,-1)I(/H,-H)I(%H<H-1,1)I(/H<V-1,H)
    if(k){n=a[rand()%k];m[n<c?c:n]&=(n-c)%H?3:5;f(n);}}}
    int main(){while(n<V*H)m[n++]=7;srand(time(NULL));f(rand()%H);
    for(;t<V;t++){F(m[t*H+n]&2?"###":"#  ");X;F(m[t*H+n]&4?"#  ":"   ");X}
    F("###");return X}
    [/code]
    At a glance, they could have shaved off another 3 bytes by changing NULL to a zero. But I like the fact that it's exactly 500 this way. At any rate...

    1000 + ((500 - 500)*10) = 1000 + 250 bonus snazzy points.


    My entry doesn't meet the 500 character requirement. My entry is in C, where as these are both in C++. (Not that it matters.) Mine is 24 characters too big. If only I hadn't mentioned the "without warnings" part.
    :~/programming/maze/quzah$ ls wsig* -al
    -rwxrwxr-x 1 root windows 14685 Oct 19 21:26 wsig
    -rwxrwxr-x 1 root windows 524 Oct 19 21:34 wsig.c
    :~/programming/maze/quzah$
    I had worked on a few versions of it prior to receiving any entries. I had a recursive version early on, and then went to a non-recursive version. Here's the output of my current code:
    Code:
     gcc -o wsig wsig.c -Wall -pedantic
    quzah@greenhouse:~/programming/maze/quzah$ ./wsig
    
    ###############################################
    # #     # # #         #         # # #     #   #
    # ##### # # ### # # # # # # # # # # ### # ### #
    #               # # # # # # # # # # # # # #   #
    # # # # # # # # ####### ######### # # # ### # #
    # # # # # # # # # #   # # # #   #     #     # #
    # ### # # ####### ### # # # # # # # # # # # # #
    # #   # #   # #               #   # #   # # # #
    # # # # # # # # # # # # # # # # # # # # # #####
    # # # # # #     # # # # # # # # # # # # #     #
    # # # ### # # # # # # ### # ### # ##### # # # #
    # # #   # # # # # # # #   # # # #   # # # # # #
    # # # # ##### ##### # # # ### ### # # ### # # #
    # # # #     # # # # # # #       # #     # # # #
    # # # # # # ### # ### # # # # # ### # # ### # #
    # # # # # #     #   # # # # # # #   # #   # # #
    # # # # ### # # # # ### # # # # ### ### # # ###
    # # # # #   # #   #   # # # # # # # # # # # # #
    # # ### # # # ### # # ### # # ### ### ####### #
    # #   # # # #   # # #   # # #       # #   # # #
    # # # ##### # # # ### # # ### # # # # ### # # #
    # # #   #   # # #   # # #   # # # #           #
    ###############################################
    Blah blah, resizable without any problems. Mine is rather scrunched, and here it is:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #define Y 11
    #define X 23
    #define A _[y][x]
    #define C(D,E,F,G,H)if(D&&_[E][F]){A|=G;_[E][F]|=H;}else
    #define I(J,K)printf(y<0?"#":y&1 J!(_[y/2][x]&K)?"#":" ")
    #define L for(x=0;x<X;x++)
    int y,x,z,_[Y][X]={{16}};int U(){for(y=0;y<Y;y++)L if(!A)return 1;return 0;}int
    main(){srand(time(0));for(;U();){y=rand()%Y;x=rand()%X;if(!A){C(y>0,y-1,x,1,4)C
    (x<X-1,y,x+1,2,8)C(y<Y-1,y+1,x,4,1)C(x>0,y,x-1,8,2);}}for(y=-1;y<Y+Y;y++){
    printf("\n#");L{I(&&,4);I(||,2);}}return 0;}
    If I knock off the #include lines, I can fit it, and that's probably what I'll do when I do stick it in my sig. I have some rather fun lines of code which I'll expand slightly so you can read them. I'll go into depth a bit on this particular entry because... it's mine. Duh!

    I have scrunched this up pretty good. Here are two macros I like a great deal:
    Code:
    #define C(D,E,F,G,H)if(D&&_[E][F]){A|=G;_[E][F]|=H;}else
    Used here, slightly "clarified" so you can see it:
    Code:
        for(;U();)
        {
             y=rand()%Y;x=rand()%X;
            if(!A)
            {
                C(y>0,y-1,x,1,4)
                C(x<X-1,y,x+1,2,8)
                C(y<Y-1,y+1,x,4,1)
                C(x>0,y,x-1,8,2);
            }
        }
    Basicly all this does is, as long as there's an unused cell in the array, it randomly picks one cell, and if it's empty, checks all of its neighbors. If a neighbor is not empty, it marks this as used, and knocks out the wall between the cells.

    That's the non-recursive solution I used. I couldn't seem to get the recursion trimmed down as much as I liked. I was probably over complicating it, but I couldn't seem to get it any smaller than this non-recursive version. I'm rather fond of that macro.

    I like this one even more:
    Code:
    #define I(J,K)printf(y<0?"#":y&1 J!(_[y/2][x]&K)?"#":" ")
    Don't ask me what it does. I have tried and tried to rewrite this again simpler, and I'll be damned if I can do it. It's used like so:
    Code:
    for(y=-1;y<Y+Y;y++){
        printf("\n#");
        L{
            I(&&,4);
            I(||,2);
        }
    }
    That prints the maze. I really like this macro. I like the fact that the first argument is an operator. The values "2" and "4" are the bit values for the directions "east" and "south" respectively. At any rate, it's fun code.

    I had to hard code the values for the starting point of the maze (the 16 in the array initialization), which normally would have been set randomly, but I couldn't afford the space to do it that way. Still, that it works. The maze doesn't look quite as good as if I had done it though. It's still passable though. Also, in shrinking the C and L macros and it slightly detracted from the "nice looking" part of the output. But it still turns out a perfect maze.

    Anyone who was working on their version, feel free to send it in. Don't just take someone else's code and rename the variables if you do though, because it'll be posted here.

    Also, feel free to toot your own horn and tell us all the finer points of your code as I've done to mine.

    Oh, I guess I need a score:

    1000 - (24 * 10) = 760. I lose. Ah well, it was fun.

    I was considering getting rid of the time function, and hard coding a value for the random number seed. Getting a "random" maze would mean you recompiled every time you wanted a new maze. Not a big deal, but since I didn't feel that truely met my requirement, I didn't. However, had I done so... snazzy!
    Code:
    ls -al vsig.c 
    -rwxrwxr-x    1 root     windows       500 Nov  4 23:37 vsig.c
    Which I'll stick in my sig now for the hell of it.

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

  14. #29
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I have decided that the sig engine hates me. It's fact. Take Z's code, wrap it in code tags, save it to a file: 500 bytes exactly. Now paste that into your sig. It fits. The sig allows it, and you can in fact have it as your sig.

    Now try mine. Take my code:
    1) Remove the "#include <time.h>" line.
    2) Remove the "time(0)" portion, and simply replace it with a 0.

    Save the file. 500 bytes exactly.

    Now try to make it your sig. You can't. It won't let you. You have to remove NINE bytes for it to fit. WHY?

    The fact is, the sig engine doesn't want ME to make SigMaze! Anyone else can, oh, sure. But not me.

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

  15. #30
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Yay!

    Nice solution by zzzaaahh as well.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

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