[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Uforståeligt program der ikke virker



torben fjerdingstad wrote:
> 
> Brug: kør programmet og indtast antal linjer, f.eks. 10.
> 
> maze.ansi.c
> 
> char*M,A,Z,E=40,J[80],T[3];main(C){for(M=J+E,*J=A=scanf("%d",&
> C)            ;--            E;J             [E            ]=M
> [E   ]=  E)   printf("._");  for(;(A-=Z=!Z)  ||  (printf("\n|"
> )    ,   A    =              39              ,C             --
> )    ;   Z    ||    printf   (T   ))T[Z]=Z[A-(E   =A[J-Z])&&!C
> &    A   ==             M[                                  A]
> |6<<11<rand()||!C&!Z?J[M[E]=M[A]]=E,J[M[A]=A-Z]=A,"_.":" |"];}
> 
> Jeg har ikke nogen C beautifier på min redhat, så jeg har
> forsøgt at gøre det pænere manuelt:
> 
> char*M,A,Z,E=40,J[80],T[3];
> main(C){
>         for(M=J+E,*J=A=scanf("%d",& C); --E; J[E]=M[E]=E)
>                 printf("._");
>         for(;(A-=Z=!Z) || (printf("\n|"), A=39, C--); Z || printf(T))
>         T[Z]=Z[A-(E=A[J-Z])&&!C & A == M[A]|6<<11<rand()||!C&!Z?J[M[E]=\
>         M[A]]=E,J[M[A]=A-Z]=A,"_.":" |"];
> }

Det hjalp ikke meget
 
> Men den laver ikke nogen lodrette vægge:

Jo den gør, men der er langt imellem:

sslug@sslug div]$ echo 400000 | ./laby | grep "[_ ]|[_ ]" | wc -l
     81

Programmet går ud fra en 16-bit oversættelse, hvor rand() giver mellem
0 og 64K. Hvis det oversættes med en 32-bit oversætter, giver rand()
værdier mellem 0 og 2G. Så der skal man være heldig for at få noget
under 6<<11 (=12288). Heldigvis kan det nemt rettes, oven i købet
uden at ødelægge det fine layout af programmet bare ved at ændre 11
til 27.

Et andet problem er imidlertid at labyrinterne ikke varierer fra
kørsel til kørsel. Der skulle nok suppleres med et kald til srand().

mvh
Peter Stubbe


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *