View Full Version : Challenge!
DudeMiester
01-19-2005, 03:50 PM
Tell me what this code does!
I know, cause I wrote it myself, but can you unravel it's mysteries?
int* Loop(int* Array, int* ArraySize, int numDim)
{
int ResultSize=1;
for(int i=0; i<numDim; i++, ResultSize*=numDim[i]);
int* Result=new int[ResultSize*(numDim+1)];
DoLoop(Result, Array, ArraySize, numDim-1, 0, 0)
return Result;
}
void DoLoop(int* Result, int* Array, int* DimSize, int numDim, int CurrentDim, int StartAt)
{
if(numDim==CurrentDim)
{
for(int i=0; i<DimSize[CurrentDim]; i++)
{
Result[(StartAt+i)*(numDim+2)+CurrentDim]=i;
Result[(StartAt+i)*(numDim+2)+CurrentDim+1]=Array[StartAt+i];
}
}
else
{
for(int i=0; i<DimSize[CurrentDim]; i++)
{
for(int j=0; j<DimSize[CurrentDim+1]; j++)
Result[(StartAt+j)*(numDim+2)+CurrentDim]=i;
DoLoop(Result, Array, ArraySize, numDim, CurrentDim+1, StartAt+i*DimSize[CurrentDim]);
}
}
}
I'll give hints ... eventually http://forums.3drealms.com/ubbthreads/images/graemlins/wink.gif
DudeMiester
01-19-2005, 09:42 PM
You know the more I learn about the inner workings of C++ the more I realise how inherintly flawed it is as a language.
http://www.codeproject.com/cpp/FastDelegate.asp
One day I'll create my own language that solves these problems, and adds abitrary compile time (metaprograming) and run time code generation (allows for proper generics, ultimately optimised code that redesigned/compiled for each computer, and much more), clean up the function pointer mess, add virtual data members, adds as detailed type information as you require, efficent and customisable memory management, abstraction of data relationships rather then just code, built in customisable support for multi-process communication and interaction (parallel processing/distrubuted computing/networking), and easy macro-programming (arranging/controlling high level objects that represent the program) that can be done at runtime while maintaining a full spectrum of programmability (from macro to assembly, you can do it all). Oh and the option to compile to native right away, at run time (JIT), or run on a virtual machine.
That I think would be the ultimate computer language.
I've been trying to implement most of it in C++, but it's rather difficult. I've got type information, memory management, multi-process support (implemented as networks of objects that can interact with eachother regardless of the physical boundries between them), data relationship abstraction, and macro-programming planned out. Function pointer cleanup I'm probably going to use the 3rd party code from above, so that's taken care of. Now I need to code the thing out, I already know how it will work.
However, anything that involves proper generics especially abitrary code generation, and probably virtual data members, will involve making my own language. I will do this, but not today, don't know how.
Kevin Wolff
01-19-2005, 11:53 PM
One day I'll create my own language that solves these problems,
Yeah, you and a million other programmers. http://forums.3drealms.com/ubbthreads/images/graemlins/tongue.gif
Kevin Wolff
01-19-2005, 11:55 PM
Oh yeah...what the heck is this? http://forums.3drealms.com/ubbthreads/images/graemlins/tongue.gif
char a[80];
int e[4],g[5],c=100,h,i,j,k,b,f,s,t,p[4][1000];
int main(char*d){
return main((char*)(srand(time(&h)),
setjmp(p[2]),
(k=atoi((gets(a),
a+strspn(a," -"))))
&&(b=k),
b||++b,
j+=-j,
d=(char*)(&j),
setjmp(p[1]),
1<<1>j&&(k&=4>>3,
i=1<<k,
h<<=i+j,
setjmp(p[0]),
(h+=*d++-h)&&(-'1'^(h-='1'))&&(i<<=4,
setjmp(p[3]),
(i||!++i)&&(h--||(k|=i),
i/=2,
longjmp(p[3])),
longjmp(p[0])),
k^=-1,
k+=1<<037,
setjmp(p[3]),
k&&((--i<5&&1&k)&&(s=(rand()>>9)%0x4,
setjmp(p[0]),
t+=(rand()>>3)%015-t,
e[s]&(1<<t)&&longjmp(p[0]),
e[s]|=1<<t,
g[i]=t|++s<<"\004"["\004"[1]]|t),
k>>=1,
i+=1<<1,
longjmp(p[3])),
setjmp(p[0]),
putchar(0x20+!putchar(012+"(.7-A,G+@*J)/"[(017&(i=g[4-k]))*013%13])),
++k^005&&longjmp(p[0]),
putchar('\n'),
setjmp(p[3]),
putchar(0x1F+!!putchar(("BCDHS"[g[--k]>>4]))),
k&&longjmp(p[3]),
putchar('\n'),
j+=1<<0,
1^j||(d=(char*)gets(a)),
longjmp(p[1])),
s=1==(f=0),
i=0<<1,
setjmp(p[3]),
i<4&&(j=i+1,
setjmp(p[1]),
j<5&&((017&g[j])>(g[i]&15)&&(k=g[i],
g[i]=g[j],
g[j]=k),
j++,
longjmp(p[1])),
i++,
longjmp(p[3])),
setjmp(p[0]),
i--&&!((g[1+i]^g[i])>>4)&&longjmp(p[0]),
setjmp(p[1]),
--j&&(!(k=(g[j]&15)-(g[j-1]&017)+1)||(!(j-1)&&(8==-k)))&&longjmp(p[1]),
s+=3*!j|!(++i^17),
(j*=i*=4)&&(i=1),
setjmp(p[3]),
5-j<2&&(j=0,
setjmp(p[1]),
5-i>j&&((g[j]^g[j+1])&0xf?g[j]^=g[j]:(s+=((g[j]&0xf)>8&&f++,
!!g[j]*i)),
j++,
longjmp(p[1])),
i++,
longjmp(p[3])),
s=1^s?"AACEDJQZHello World"[s]-'A':!!f,
s+=(!i)*(6+12*s-!!s*(g[2]&017^0xa?8:-192)),
s--,
s*=b,
printf("$%d (%d) \n",
c+=s,
s+b),
i=0,
setjmp(p[0]),
6>i&&(j=1,
setjmp(p[1]),
0<=j&&(e[i+j]^=*(i-j+e+(j<<1)),
--j,
longjmp(p[1])),
i+=++i,
longjmp(p[0])),
longjmp(p[2])));
}
Kevin Wolff
01-19-2005, 11:56 PM
Or this? http://forums.3drealms.com/ubbthreads/images/graemlins/tongue.gif
#include <stdio.h>
#include <sys/time.h>
#include <X11/Xlib.h>
#include <X11/keysym.h>
#define Z(a)main(a,T)
Window L;
#define J (K,
GC N;
#define I ; for(
int g,h,i,j,k,l,m,n,p,q,r,v,w,x,y,z,
#define W(a)(y/v*!w+((S+1)>>a&255)*(D+y/(z|w-2))/D)<<a|
o,b,f,u,s,c,a,t,e,d, C
#define U (struct timeval*)H
[1<<18],A=100,B=4,D=200,E=53300,F=65793,H[4];
#define V(a)#a": %1d'%02d\"%02d "
Display*K; Pixmap M; char P[99]; int main
#define Y(a,b)(a<b?a:b)
(int S,char**T){
#define X(a)\
XDrawLine J M,N,D+l a m,o,D+l a n,o),
XEvent O I p=E/5; --S&~1?
XSetForeground J N,W(0)W(8)W(16)0),X(-)X(+)gettimeofday(U,0):S?z=97
== ** ++ T,w=A==z[*T],B-=w[z+*T]%3,S:++S;
XCopyArea J M,L,N,0,0,e,D,0,0),
XSync J 0),
XFlush (K),select(0,0,0,0,U+1)){ I 3[H]=F; p==++r?K=
XOpenDisplay (0),N=
XCreateGC J L=
XCreateSimpleWindow J RootWindow(K,0),0,0,e=D*2,D,0,0,0),0,0),
XSelectInput J L,KeyPressMask|KeyReleaseMask),
XMapWindow J L),M=
XCreatePixmap J L,e,d=D,DefaultDepth(K,0)),u=h=q=E:r<p?a=r/D%6,r[C
+p]=(l+=!a|a%2?g:a-3)/4,r[C]=2*r<=p?(n+=(i-=(i+34&&r
/149%B)-(i-34&&r/353%3)))/55:C[p-r],v=4-3*z:
XPending (K)?C[F+
XLookupKeysym (&O.xkey,0&
XNextEvent J&O))]^=O.type==KeyPress||O.type==KeyRelease,p:0;
/* Some more code */
)I k=C[F+XK_Right]-C[F+XK_Left],j=k?j+v*k*(j*k<8):j*.9,u+=(s=Y(C[F+XK_space]*
3+s-!!s,a))/9,c=u>p?q=Y(h,q),u%=p,Z(c=0):c,t+=j*(s+A)/e-s/i*(C[u+4]-C[u]),s=t
*t>p?t*=.97,s*.8:g>a&&b*b<D*9?i:s,i=k=l=0,o=n=e; i-5; Z((k/17?o++==y?m=n=D,f
-=A,o=30+9*i++:0,n-=2,m+=3,l=f/.7,y*F+A-i*k:k|!o?f=l=C[u]/-2-t,k+=17*w,o=k+++
20,n=k+k-k*k/9,F*p:o--<a?y=135,A*F|D:0)))I x=g=m=f=0,a=i=u+D,d+=9; o<f?n=2*e,
Z(z?r+k*F*8:E-k*A*A),n=9+x/D,Z(!k+z?r=D*F+9:A<<17),n-=x/9/D,Z(i%p>6?h=r*(3+z)
/5:r),n=x/13/e,Z(k?h:r),o++:(f=x/D+70+C[i+p]-C[u+p],o=x?o:f,k=2*i/41%2,l=C[--
i]-C[u]-t,x+=D-(y=i-u),g=(d-i)%410?g:(a=o,b=l+B*x/e,x)/A,i>u); )I k=i=0,x=g,
l=b; ++i==41+!f&&k?f=k=i=l=0,x=190,a=163:i==42?i=9,k=r:!k|i-41; n=(Y(Y(Y(75,A
-i)/3,95-2*i),r-k+2*i)-k/r)*x/D,m=i<9?x*14/D:k?(i-31)/5*(i%12)?0:n-1:0,o=a-i*
x/D,y=D-o,h=Z(k*r+k*f/F))I B=g?B:1-h%3,i=60,y=n=m,XDrawString J M,N,30,x,P,
sprintf(P,V(Time)V(High)"Speed: %03dmph",h/A/i,h/A%i,h%A,q/A/i,q/A%i,q%A,s,Z(
A<<17))),x=h; ++f<2*z*e; l=(x*=3)%e,o=x*x%a,Z(-1)); } return A**H+1[H]/p-c; }
Asmodeusz
01-20-2005, 04:58 AM
This thread is gay. Both codes do nothing, as they are not compiled http://forums.3drealms.com/ubbthreads/images/graemlins/tongue.gif
Now pwn me, as I know nothing about programming,
unless we're talking q-basic hahahaha http://forums.3drealms.com/ubbthreads/images/graemlins/grin.gif http://forums.3drealms.com/ubbthreads/images/graemlins/grin.gif http://forums.3drealms.com/ubbthreads/images/graemlins/grin.gif . Don't laugh I made a graphic adventure game in q-basic. http://forums.3drealms.com/ubbthreads/images/graemlins/frown.gif
Kristian Joensen
01-20-2005, 05:45 AM
Could you post the code for that game here ?
Asmodeusz
01-20-2005, 09:20 AM
Well I made it when I was around 14 yo, I doubt I'll find it somewhere, but I'll try. It was mega lame, but at least you'll have a laugh http://forums.3drealms.com/ubbthreads/images/graemlins/smile.gif I'll look for it when I arrive home.
Oh, wait. Now that I think of it, I have it on an old laptop! I'll post the code when I get back http://forums.3drealms.com/ubbthreads/images/graemlins/smile.gif FEAR!
DudeMiester
01-20-2005, 07:13 PM
Mine is actually a challenge because those other ones I can simply compile and see the results. This you have to figure out what the inputs and outputs do. However, obviously you guys aren't up to a challenge of this magnitude, so I'll just spell it out.
[b]It takes an n-dimensional array, it's dimensions and the number of dimensions as input. Then outputs a list of all the elements in that array plus the index vectors that correspond to those elements.[b]
The reason I made it was so that I guy at work could translates a set of n-dimensional arrays into a form that he could use to make a pivot table in Excel.
The code is one of those things that is so bizzare and complex that you can't just be told how it works, you have to understand it intuitively. Obviously since you guys couldn't figure it out I am 1337 and you are not! http://forums.3drealms.com/ubbthreads/images/graemlins/tongue.gif http://forums.3drealms.com/ubbthreads/images/graemlins/grin.gif
AlienAssKicker
01-23-2005, 09:11 PM
Would have been easier to do and understand with JAVA http://forums.3drealms.com/ubbthreads/images/graemlins/tongue.gif
DudeMiester
01-24-2005, 07:27 PM
No it wouldn't, the only possible difference would be that the arrays contain their own dimensional information. Then again, I could have just used a multidimensional array here, but then it wouldn't be pure C++, and less challenging.
vBulletin® v3.8.0 Release Candidate 2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.