Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Language For Number Crunching
#1
QBasic is slow. That's what I hear anyway. Below is a program I wrote. It generates all 649 combos in ascending order. I'm still pretty new to QBasic so it may not be as efficient as possible. Anyway, I think I estimated that for this program to finish (on my 1200 MHZ PC) it would take over 24 hours, something like that.

I'm just wondering what you guys think would be the fastest programming language to do the following types of programs in. I don't care about graphics or flash, and all the programs would be Console programs.

What language would run lottery programs like the one below the fastest? C++, Java, Python, VB, QB, C#, PowerBasic, others.


CLS

PRINT " "
PRINT "Welcome to 649.exe."
PRINT " "
PRINT "The program will now generate all possible 6/49 combinations"
PRINT "in ascending order."
PRINT " "
PRINT "Sit back and relax while this process takes place."
PRINT " "

FOR loop1 = 1 TO 44
FOR loop2 = 2 TO 45
FOR loop3 = 3 TO 46
FOR loop4 = 4 TO 47
FOR loop5 = 5 TO 48
FOR loop6 = 6 TO 49

IF loop6 <> loop5 AND loop6 <> loop4 AND loop6 <> loop3 AND loop6 <> loop2 AND loop6 <> loop1 THEN
IF loop6 > loop5 AND loop6 > loop4 AND loop6 > loop3 AND loop6 > loop2 AND loop6 > loop1 THEN
IF loop5 <> loop4 AND loop5 <> loop3 AND loop5 <> loop2 AND loop5 <> loop1 THEN
IF loop5 > loop4 AND loop5 > loop3 AND loop5 > loop2 AND loop5 > loop1 THEN
IF loop4 <> loop3 AND loop4 <> loop2 AND loop4 <> loop1 THEN
IF loop4 > loop3 AND loop4 > loop2 AND loop4 > loop1 THEN
IF loop3 <> loop2 AND loop3 <> loop1 THEN
IF loop3 > loop2 AND loop3 > loop1 THEN
IF loop2 <> loop1 THEN
IF loop2 > loop1 THEN

OPEN "649.txt" FOR APPEND AS #1
PRINT #1, loop1; loop2; loop3; loop4; loop5; loop6
CLOSE #1

LET counter = counter + 1
PRINT counter; " Combinations have been generated so far"

ELSE
END IF
ELSE
END IF
ELSE
END IF
ELSE
END IF
ELSE
END IF
ELSE
END IF
ELSE
END IF
ELSE
END IF
ELSE
END IF
ELSE
END IF
NEXT
NEXT
NEXT
NEXT
NEXT
NEXT

PRINT "Done Generating ALL 6/49 combinations in Ascending order"

END
Reply
#2
ASM Big Grin
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#3
Isn't Assembly processor specific? What happens when I upgrade my Duron processor to an Athlon XP? Will assembly programs I wrote still run? What happens if I take it from my AMD processor to a computer with an Intel processor? Will it work? If not - although I appreciate your response - I won't be choosing that option.
Reply
#4
I think that the ASM stuff you have to use for your program is standard and will work with every CPU (AMD, Intel,...)
B 4 EVER
Reply
#5
What would be next best after ASM? C++ right?
Reply
#6
Quote:What would be next best after ASM? C++ right?

C
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#7
There are some very fast C compilers, but if it's not machine code, the language itself doesn't matter because it doesn't translate directly into machine code. It only depends on how optimized your compiler is. (Of course, interpreted scripting languages like PHP are excluded here).

The fastest compiler out there is either Intel's C/++ compiler or Borlands C/C++ compiler, I can never remember which. They're both commercial complers, though. The fastest free compiler is probably GCC, which has a few languages, doesnt it? A popular front-end/ide for it is Bloodshed's Dev-C++.
Reply
#8
Always optimize your algorithm first.

Code:
DEFINT A-Z
CLS

PRINT
PRINT "Welcome to 649.exe."
PRINT
PRINT "The program will now generate all possible 6/49 combinations"
PRINT "in ascending order."
PRINT
PRINT "Sit back and relax while this process takes place."
PRINT

OPEN "649.txt" FOR OUTPUT AS #1

FOR loop1 = 1 TO 44
  FOR loop2 = 2 TO 45
    FOR loop3 = 3 TO 46
      FOR loop4 = 4 TO 47
        FOR loop5 = 5 TO 48
          FOR loop6 = 6 TO 49

            IF loop2 > loop1 AND loop3 > loop2 AND loop4 > loop3 AND loop5 > loop4 AND loop6 > loop5 THEN
              PRINT #1, loop1; loop2; loop3; loop4; loop5; loop6
              counter& = counter& + 1
            END IF

          NEXT
        NEXT
      NEXT
    NEXT
  NEXT
  PRINT counter&; "Combinations have been generated so far ("; INT(loop1 / 44 * 100); "%)"
NEXT

PRINT "Done Generating ALL 6/49 combinations in Ascending order"

END

(This runs in under 2 minutes on my machine.)
Reply
#9
Quote:It only depends on how optimized your compiler is.

Hmm, that makes sense. The language itself is irrelevant, it's the compiler that makes the difference. So Microsoft technically could release a superfast QuickBasic 8.0 Compiler tommorow which would be faster than C++, etc., and then it would run faster than C++?

I guess it's all in how efficient the Compiler is in turning the code into machine language, and not the actual language.
Reply
#10
Quote:Always optimize your algorithm first.

Code:
DEFINT A-Z
CLS

PRINT
PRINT "Welcome to 649.exe."
PRINT
PRINT "The program will now generate all possible 6/49 combinations"
PRINT "in ascending order."
PRINT
PRINT "Sit back and relax while this process takes place."
PRINT

OPEN "649.txt" FOR OUTPUT AS #1

FOR loop1 = 1 TO 44
  FOR loop2 = 2 TO 45
    FOR loop3 = 3 TO 46
      FOR loop4 = 4 TO 47
        FOR loop5 = 5 TO 48
          FOR loop6 = 6 TO 49

            IF loop2 > loop1 AND loop3 > loop2 AND loop4 > loop3 AND loop5 > loop4 AND loop6 > loop5 THEN
              PRINT #1, loop1; loop2; loop3; loop4; loop5; loop6
              counter& = counter& + 1
            END IF

          NEXT
        NEXT
      NEXT
    NEXT
  NEXT
  PRINT counter&; "Combinations have been generated so far ("; INT(loop1 / 44 * 100); "%)"
NEXT

PRINT "Done Generating ALL 6/49 combinations in Ascending order"

END

(This runs in under 2 minutes on my machine.)

??????????????????

It generated nearly 14,000,000 combos in 2 minutes??? I gotta try it!

Yeah, I don't know yet what "DEFINT A-Z" and what "counter& = counter& + 1" are, but i'll try this and see how fast it runs.

Thanks!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)