C 844
#include <stdlib.h>
#include <time.h>
h,w,*m,y,x,z;d(t,b,l,r){int i=b-t,j=r-l;if(i>1&&j>1){i=(rand()%--i)|1;j=(rand()%--j)|1;z=rand()%4;x=rand()%i+t;x|=1;for(y=t;y<i+t;y++)if(y!=x||!z)m[y*w+j+l]=124;x=rand()%(b-i-t)+i+t;x|=1;for(y=t+i;y<b+1;y++)if(y!=x||!(z-1))m[y*w+j+l]=124;y=rand()%j+l;y|=1;for(x=l;x<j+l;x++)if(y!=x||!(z-2))m[(i+t)*w+x]=45;y=rand()%(r-j-l)+j+l;y|=1;for(x=l+j;x<r+1;x++)if(y!=x||!(z-3))m[(i+t)*w+x]=45;m[(i+t)*w+j+l]=43;m[(t-1)*w+l+j]=43;m[(b+1)*w+j+l]=43;m[(i+t)*w+l-1]=43;m[(i+t)*w+r+1]=43;d(t,t+i-1,l,l+j-1);d(t+i+1,b,l,l+j-1);d(t,t+i-1,l+j+1,r);d(t+i+1,b,l+j+1,r);}}main(int c,char**v){h=atoi(v[1]),w=atoi(v[2]),m=calloc(h*w,4);srand(time(0));while(y<h){while(x<w){m[y*h+x]=(!y||y==h-1)?(!x||x==w-1)?43:45:(!x||x==w-1)?124:32;x++;}y++;x=0;}d(1,h-2,1,w-2);z=rand()%(w-2);z|=1;m[z]=32;z=rand()%(w-2);z|=1;m[h*(w-2)+z]=35;}
To Test:
#include <stdio.h>//beginning
for(y=0;y<h;y++){for(x=0;x<w;x++){putchar(m[y*h+x]);}putchar('\n');}getchar();//end
3x3
+ +
|#|
+-+
7x8
+-+-- -+
| |
+ +-+--+
| |
| +-+ -+
| | # |
+-+-+--+
18x20
+-+-+ +---+---+-+--+
| | | | |
| + + +-- +---+ +--+
| | | |
+ + +-+---+-- +-+ -+
| | | |
+-+ +-+-+-+---+-+--+
| | | | | |
| + + + +-+-- --+ |
| | | | |
| | | +-+-+ ----+ |
| | | | |
+ + +-+-+-+-- --+ -+
| | | | |
| + +-+-- +-- --+ |
| | | | |
| | | | #| | |
+-+-+-+---+-----+--+
Interesting challenge. I'll put something together later today when I have access to a usable Java IDE. – SuperJedi224 – 2015-08-04T16:56:53.417
must there be at least 1 path open from the entrance to treasure? or we don't have to consider this? – mauris – 2011-03-21T11:48:19.577
+1 Great Question. A few points though. 1: How is the exit marked? Is it a symbol like
*
or is there two separate entrances? 2: You should probably specify that the exit must be reachable. – snmcdonald – 2011-01-30T19:50:42.7601@snmcdonald: let's make it fun and add a treasure :). – Alexandru – 2011-01-30T20:36:16.370
1The puzzle type is unspecified here. I see that people answered it as if it were a [code-golf]. Was that the intent? If so, please tag it as such? – dmckee --- ex-moderator kitten – 2011-06-01T13:25:36.190
2I can see a follow up golf, about solving them... :) – st0le – 2011-02-01T06:22:50.197
@st0le: I already have some ideas. Mail me if you want to discuss. – Alexandru – 2011-02-01T17:48:15.200