Post Reply 
Undoc'd Feature?
07-04-2022, 09:41 AM (This post was last modified: 07-04-2022 09:53 AM by toml_12953.)
Post: #16
RE: Undoc'd Feature?
(07-03-2022 06:24 PM)Wes Loewer Wrote:  
(07-03-2022 02:18 PM)toml_12953 Wrote:  Here's the entire C program:
Code:

main()
 {
   int x,y,r,s,t,n,a[9];

   for(n=1000;n>0;--n){
     r=8;
     s=0;
     x=0;
     do{
       a[++x]=r;
       do{
         ++s;
         y=x;
         while(y>1)
           if (!(t=a[x]-a[--y]) || x-y==abs(t)){
             y=0;
             while(!--a[x])
               --x;
           }
       } while(y!=1);
     } while(x!=r);
   }
   printf("%d",s);
 }

What an interesting little program. I cannot begin to image what it is trying to calculate. Whatever it is doing, it repeats the exact same calculation 1000 times, and a[0] never gets initialized or used.

Do tell, what is this?

The reason it performs the same calculation 1000 times is because it was written for a fast PC where the time for a single run isn't measurable. If you do the calculation 1000 times, you can then normalize the result by dividing the runtime by 1000 to get the time it took to run it once. For very fast PCs you might have to increase the 1000 to 10000 or even 1000000 to get a meaningful time measurement.

Here's an ANSI/ISO BASIC (ParactBASIC compiler) program to perform the same function. See how I had to use a larger number to get the result?

Result:
876
Time: 0.00001229 seconds

Code:
LET t0=time
DIM a(9)

FOR n=100000 TO 1 STEP -1
   LET r=8
   LET s=0
   LET x=0
   DO
      LET x=x+1
      LET a(x)=r
      DO
         LET s=s+1
         LET y=x          
         DO WHILE y>1
            LET y=y-1
            LET t=a(x)-a(y)
            IF t=0 OR x-y=ABS(t) THEN
               LET y=0
               LET a(x)=a(x)-1
               DO WHILE a(x)=0
                  LET x=x-1
                  LET a(x)=a(x)-1
               LOOP
            END IF
         LOOP 
      LOOP WHILE y<>1
   LOOP WHILE x<>r
NEXT n
PRINT s
LET t1=TIME-t0
PRINT USING "Time: %.######## seconds":t1/100000
END

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Undoc'd Feature? - toml_12953 - 07-03-2022, 03:42 AM
RE: Undoc'd Feature? - Wes Loewer - 07-03-2022, 09:14 AM
RE: Undoc'd Feature? - toml_12953 - 07-03-2022, 09:38 AM
RE: Undoc'd Feature? - Wes Loewer - 07-03-2022, 01:16 PM
RE: Undoc'd Feature? - Wes Loewer - 07-03-2022, 01:49 PM
RE: Undoc'd Feature? - toml_12953 - 07-03-2022, 02:18 PM
RE: Undoc'd Feature? - Wes Loewer - 07-03-2022, 06:24 PM
RE: Undoc'd Feature? - Albert Chan - 07-03-2022, 07:09 PM
RE: Undoc'd Feature? - toml_12953 - 07-04-2022, 01:49 AM
RE: Undoc'd Feature? - toml_12953 - 07-04-2022 09:41 AM
RE: Undoc'd Feature? - Wes Loewer - 07-04-2022, 03:40 PM
RE: Undoc'd Feature? - xerxes - 08-03-2022, 08:17 PM
RE: Undoc'd Feature? - parisse - 07-03-2022, 11:02 AM
RE: Undoc'd Feature? - Wes Loewer - 07-03-2022, 01:03 PM
RE: Undoc'd Feature? - parisse - 07-03-2022, 06:31 PM
RE: Undoc'd Feature? - Wes Loewer - 07-03-2022, 07:34 PM
RE: Undoc'd Feature? - jte - 07-08-2022, 03:15 AM
RE: Undoc'd Feature? - Wes Loewer - 07-08-2022, 05:00 AM
RE: Undoc'd Feature? - jte - 07-08-2022, 08:32 PM
RE: Undoc'd Feature? - Wes Loewer - 07-09-2022, 05:15 AM
RE: Undoc'd Feature? - RPNerd - 07-09-2022, 12:20 PM
RE: Undoc'd Feature? - Albert Chan - 07-09-2022, 05:10 PM
RE: Undoc'd Feature? - Wes Loewer - 07-10-2022, 05:22 AM
RE: Undoc'd Feature? - toml_12953 - 07-10-2022, 10:22 AM
RE: Undoc'd Feature? - RPNerd - 07-10-2022, 12:48 PM
RE: Undoc'd Feature? - Wes Loewer - 07-17-2022, 01:05 PM
RE: Undoc'd Feature? - jte - 07-31-2022, 02:12 AM
RE: Undoc'd Feature? - Wes Loewer - 07-31-2022, 06:43 PM
RE: Undoc'd Feature? - toml_12953 - 07-31-2022, 07:25 PM
RE: Undoc'd Feature? - Wes Loewer - 08-01-2022, 03:48 AM
RE: Undoc'd Feature? - ijabbott - 07-14-2022, 05:22 PM
RE: Undoc'd Feature? - toml_12953 - 07-10-2022, 05:36 PM
RE: Undoc'd Feature? - Albert Chan - 07-10-2022, 05:57 PM
RE: Undoc'd Feature? - Wes Loewer - 07-10-2022, 07:38 PM
RE: Undoc'd Feature? - ijabbott - 07-11-2022, 07:49 PM
RE: Undoc'd Feature? - RPNerd - 07-12-2022, 11:03 AM
RE: Undoc'd Feature? - ijabbott - 07-13-2022, 09:34 PM
RE: Undoc'd Feature? - Wes Loewer - 07-12-2022, 01:49 PM
RE: Undoc'd Feature? - ijabbott - 07-13-2022, 10:12 PM
RE: Undoc'd Feature? - toml_12953 - 07-13-2022, 10:50 PM
RE: Undoc'd Feature? - jte - 07-31-2022, 01:29 AM
RE: Undoc'd Feature? - Wes Loewer - 07-31-2022, 10:13 AM
RE: Undoc'd Feature? - OlidaBel - 07-04-2022, 09:11 AM
RE: Undoc'd Feature? - toml_12953 - 07-04-2022, 09:36 AM
RE: Undoc'd Feature? - ctrclckws - 07-13-2022, 12:44 PM
RE: Undoc'd Feature? - Wes Loewer - 07-13-2022, 08:01 PM



User(s) browsing this thread: 1 Guest(s)