cancel
Showing results for 
Search instead for 
Did you mean: 

Drivers & Software

albert_redditt
Journeyman III

I beat the computer

'====================================================

'Code designed for FreeBASIC compiler  ,  FreeBASIC.net

'Geany IDE with build command set to   -gen GCC -w all -O 3

'====================================================

'My formula is faster than the computers built in MOD function...

screen 19

randomize

dim as double time1 , time2 , time3 , time4

do

   

    dim as ulongint a = rnd * 1e10

    dim as ulongint b = rnd * 1e10

    if b > a then swap b , a

   

    'computers MOD function

    dim as ulongint built_in_mod

    time1 = timer

        for x as longint = 1 to 1e6

            built_in_mod = a mod b

        next

    time2 = timer

    'Alberts MOD formula

    dim as ulongint Albert_mod

    time3 = timer

        for x as longint = 1 to 1e6

            Albert_mod = a - ( ( a \ b ) *b )

        next

    time4 = timer

    print a; " mod " ;b

    print "Built in MOD   "   ; built_in_mod , time2-time1 ,  (time2 - time1)  / 1e6

    print "Albert's MOD   "   ; Albert_mod   , time4-time3 ,  (time4 - time3)  / 1e6

    print

   

    sleep

   

loop until multikey(1)

sleep

end

0 Likes