Qbasicnews.com
August 18, 2018, 01:29:31 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Big Multiplication Limitless (Collection)  (Read 7447 times)
lrcvs
Member
*
Posts: 56


« on: December 27, 2009, 08:59:58 PM »

'PROGRAM : MULTIPLICATION LIMITLESS VER #1

'LRCVS 01.01.2010

'THIS PROGRAM SIMPLY MAKES A MULTIPLICATION

'WITH ALL THE PARTIAL PRODUCTS.
'............................................................


DECLARE SUB A.INICIO (A$, B$)
DECLARE SUB B.STORE (CAD$, N$)
DECLARE SUB C.PIZARRA ()
DECLARE SUB D.ENCABEZADOS (A$, B$)
DECLARE SUB E.MULTIPLICACION (A$, B$)
DECLARE SUB G.SUMA ()
DECLARE FUNCTION F.INVCAD$ (CAD$)


CALL A.INICIO(A$, B$)
CALL B.STORE(A$, "A")
CALL B.STORE(B$, "B")
CALL C.PIZARRA
CALL D.ENCABEZADOS(A$, B$)
CALL E.MULTIPLICACION(A$, B$)
CALL G.SUMA

SUB A.INICIO (A$, B$)
CLS
INPUT "NUMERO DE MUPLICACIONES  "; S
CLS
A$ = ""
B$ = ""
FOR N = 1 TO S
RANDOMIZE TIMER
A$ = A$ + LTRIM$(STR$(INT(RND * 9)))
NEXT N
FOR N = 1 TO S
RANDOMIZE TIMER
B$ = B$ + LTRIM$(STR$(INT(RND * 9)))
NEXT N

END SUB

SUB B.STORE (CAD$, N$)
'AQUI GUARDAMOS LOS DATOS EN UN FICHERO
OPEN "O", #1, N$
FOR M = LEN(CAD$) TO 1 STEP -1
WRITE #1, MID$(CAD$, M, 1)
NEXT M
CLOSE (1)
END SUB

SUB C.PIZARRA
'INICIAMOS LA PIZZARA
OPEN "A", #3, "R"
WRITE #3, ""
CLOSE (3)
KILL "R"
END SUB

SUB D.ENCABEZADOS (A$, B$)
'AQUI ESCRIBIMOS LOS DATOS EN EL FICHERO FINAL
'VARIABLES
'LT :NUM,LONGITUD TOTAL DEL MULTIPLICANDO + MULTIPLICADOR
'L$ :TEX, CADENA PATRON
LT = LEN(A$) + LEN(B$) + 1
'ESCRIBIMOS EL MULTIPLICANDO
L$ = STRING$(LT, " ")
OPEN "A", #3, "R"
MID$(L$, LT - LEN(A$) + 1) = A$
WRITE #3, L$
CLOSE (3)
'ESCRIBIMOS EL MULTIPLICADOR
L$ = STRING$(LT, " ")
OPEN "A", #3, "R"
MID$(L$, LT - LEN(B$) - 1) = "X " + B$
WRITE #3, L$
CLOSE (3)
END SUB

SUB E.MULTIPLICACION (A$, B$)
'AQUI HACEMOS LA MULTIPLICACION
'VARIABLES
'LT : NUM, LONGITUD TOTAL DEL MULTIPLICANDO + MULTIPLICADOR
'RP : NUM, RESULTADO PARCIAL
'ACUM : NUM, ACUMULADOR DE LAS MULTIPLICACIONES
'LS : TEX, CADENA PATRON
'C$ : TEX, CADENA DE TEXTO DEL RESULTADO PARCIAL
'D$ : TEX, VALOR DE LAS UNIDADES
'E$ : TEX, VALOR DE LO QUE NOS LLEVAMOS
LT = LEN(A$) + LEN(B$) + 1
L$ = STRING$(LT, " ")
C$ = ""
D$ = ""
E$ = ""
CT1 = 1
ACUM = 0
OPEN "I", #2, "B"
WHILE EOF(2) <> -1
INPUT #2, B$
OPEN "I", #1, "A"
WHILE EOF(1) <> -1
INPUT #1, A$
RP = (VAL(A$) * VAL(B$)) + ACUM
C$ = LTRIM$(STR$(RP))
IF EOF(1) <> -1 THEN D$ = D$ + RIGHT$(C$, 1)
IF EOF(1) = -1 THEN D$ = D$ + F.INVCAD$(C$)
E$ = LEFT$(C$, LEN(C$) - 1)
ACUM = VAL(E$)
WEND
CLOSE (1)
MID$(L$, LT - CT1 - LEN(D$) + 2) = F.INVCAD$(D$)
OPEN "A", #3, "R"
WRITE #3, L$
CLOSE (3)
L$ = STRING$(LT, " ")
ACUM = 0
C$ = ""
D$ = ""
E$ = ""
CT1 = CT1 + 1
WEND
CLOSE (2)
END SUB

FUNCTION F.INVCAD$ (CAD$)
'AQUI INVERTIMOS UNA CADENA DE TEXTO
'VARIABLES
'LCAD : NUM, LONGITUD CADENA ENTRANTE
'CADTEM$ : TEX, ACUMULADOR CADENA TEMPORAL
LCAD = LEN(CAD$)
CADTEM$ = ""
FOR CAD = LCAD TO 1 STEP -1
CADTEM$ = CADTEM$ + MID$(CAD$, CAD, 1)
NEXT CAD
F.INVCAD$ = CADTEM$
END FUNCTION

SUB G.SUMA
'AQUI SUMAMOS LA MULTIPLICACION

'VARIABLES
'CF: NUM, CONTADOR DEL NUMERO DE FILAS
'AN: NUM, LONGITUD DEL REGISTRO
'ST: NUM, RESULTADO PARCIAL
'ACUS: NUM, ACUMULADOR DE LAS QUE NOS LLEVAMOS
'K: NUM, CONTADOR DE FILAS
'W$: TEX, RESULTADO FINAL
'R$: TEX, REGISTRO

'AQUI CALCULAMOS EL ANCHO DEL REGISTRO

CF = 0
OPEN "I", #3, "R"
WHILE EOF(3) <> -1
INPUT #3, R$
CF = CF + 1
AN = LEN(R$)
WEND
CF = CF - 2
CLOSE (3)

W$ = ""
ST = 0
ACUS = 0
FOR P = 1 TO AN
K = 0
OPEN "I", #3, "R"
WHILE EOF(3) <> -1
INPUT #3, R$
K = K + 1
IF K > 2 THEN ST = ST + VAL(MID$(R$, AN - P + 1, 1))
IF K > 2 THEN M$ = LTRIM$(STR$(ST + ACUS))
WEND
'COLOR 10: LOCATE CF + 3, AN - P + 1: PRINT RIGHT$(M$, 1); : COLOR 7
W$ = W$ + RIGHT$(M$, 1)
ACUS = VAL(LEFT$(M$, LEN(M$) - 1))
CLOSE (3)
ST = 0
NEXT P

'AQUI ESCRIBIMOS EL RESULTADO EN EL FICHERO
OPEN "A", #3, "R"
WRITE #3, " " + RIGHT$(F.INVCAD(W$), AN - 1)
CLOSE (3)
CLS
PRINT "LA SOLUCION A ESTA MULTIPLICACION SE ENCUENTRA EN UN FICHERO DE TEXTO LLAMADO: R"
END SUB


'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


'PROGRAM: FAST MULTIPLICATION.

'LRCVS 01.01.2010

'THIS PROGRAM SIMPLY MAKES A FAST MULTIPLICATION.

'HERE IS ONLY THE SOLUTION.
'......................................................

CLS

'SOLUTION : 1676419739507419737831

A$ = "123456789123456789"
B$ = "13579"
C$ = STRING$(LEN(A$)+LEN(B$)," ")
A = 0
H = (LEN(A$)+LEN(B$))
F = H
FOR J = LEN(B$) TO 1 STEP -1
FOR K = LEN(A$) TO 1 STEP -1
R = (VAL(MID$(B$, J, 1)) * VAL(MID$(A$, K, 1))) + (A + VAL(MID$(C$, H, 1)))
R$ = LTRIM$(STR$(R))
U$ = RIGHT$(R$, 1)
IF LEN(R$) >= 1 THEN A = VAL(LEFT$(R$, (LEN(R$)-1)))
IF K = 1 AND LEN(R$) > 1 THEN H = H - 1
IF K = 1 THEN MID$(C$, H) = R$
IF K > 1 THEN MID$(C$, H) = U$
IF K > 1 THEN H = H -1
NEXT K
A = 0
F = F - 1
H = F
NEXT J
PRINT C$
END

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

'PROGRAM: MULTIPLICATION LIMITLESS VER # 2

'LRCVS 01/01/2010

'THIS PROGRAM SIMPLY MAKES A MULTIPLICATION
'WITHOUT THE PARTIAL PRODUCTS.

'HERE SEE ONLY THE SOLUTION.

'HERE THERE IS NO LIMIT ON DIGITS.

'IS VERY FASTER AND AVOIDS MAKING REPEATED MULTIPLICATION.
'...............................................................

CLS
PRINT "WAIT"
T1 = TIMER
NA = 1000 'NUMERO DE ELEMENTOS DEL MULTIPLICANDO, SIN LIMITE.
NB = 100 'NUMERO DE ELEMENTOS DEL MULTIPLICADOR, SIN LIMITE.

PRINT "MULTIPLICANDO = "; NA; " DIGITOS"
PRINT "MULTIPLICADOR = "; NB; " DIGITOS"
PRINT "NUMERO DE MULTIPLICACIONES = "; NA * NB
PRINT "NUMERO DE DIGITOS EXACTOS = "; NA + NB
PRINT "HORA INICIAL = "; TIME$
'......................................................
'AQUI ELIMINAMOS LOS POSIBLES CALCULOS ANTERIORES
OPEN "X" + ".MLT" FOR BINARY AS #1
CLOSE (1)
KILL "*.MLT"
'......................................................
'MULTIPLICANDO >>> A
'MULTIPLICADOR >>> B
FOR N = 1 TO 2
IF N = 1 THEN F$ = "A" + ".MLT": NN = NA
IF N = 2 THEN F$ = "B" + ".MLT": NN = NB
    OPEN F$ FOR BINARY AS #1
        FOR N2 = 1 TO NN
        RANDOMIZE TIMER
        X$ = LTRIM$(STR$(INT(RND * 10)))
        SEEK #1, N2: PUT #1, N2, X$
        NEXT N2
    SEEK #1, N2
    CLOSE (1)
NEXT N

'.....................................................
'AQUI HACEMOS LAS MULTIPLICACIONES PARCIALES
OPEN "A" + ".MLT" FOR BINARY AS #1
FOR K = 0 TO 9
NUM$ = "": Z$ = "": ACU = 0: GG = NA
C$ = LTRIM$(STR$(K))
    OPEN C$ + ".MLT" FOR BINARY AS #2
        'OPEN "A" + ".MLT" FOR BINARY AS #1
            FOR N = 1 TO NA
            SEEK #1, GG: GET #1, GG, X$
            NUM$ = X$
            Z$ = LTRIM$(STR$(ACU + (VAL(X$) * VAL(C$))))
            L = LEN(Z$)
            ACU = 0
            IF L = 1 THEN NUM$ = Z$: PUT #2, N, NUM$
            IF L > 1 THEN ACU = VAL(LEFT$(Z$, LEN(Z$) - 1)): NUM$ = RIGHT$(Z$, 1): PUT #2, N, NUM$
            SEEK #2, N: PUT #2, N, NUM$
            GG = GG - 1
            NEXT N
        IF L > 1 THEN ACU = VAL(LEFT$(Z$, LEN(Z$) - 1)): NUM$ = LTRIM$(STR$(ACU)): XX$ = XX$ + NUM$: PUT #2, N, NUM$
        'CLOSE (1)
    CLOSE (2)
NEXT K
CLOSE (1)

'......................................................
'AQUI CREAMOS EL RESULTADO FINAL DE LA MULTIPLICACION EN: "D"
ACU = 0
LT5 = 1
LT6 = LT5
'AQUI BUSCAMOS LOS ELEMENTOS DE B
OPEN "B" + ".MLT" FOR BINARY AS #1
    OPEN "D" + ".MLT" FOR BINARY AS #3
        FOR JB = NB TO 1 STEP -1
        SEEK #1, JB
        GET #1, JB, X$

            OPEN X$ + ".MLT" FOR BINARY AS #2: LF = LOF(2): CLOSE (2)

            OPEN X$ + ".MLT" FOR BINARY AS #2
                FOR KB = 1 TO LF
                SEEK #2, KB
                GET #2, , NUM$
                SEEK #3, LT5
                GET #3, LT5, PR$
                T$ = ""
                T$ = LTRIM$(STR$(ACU + VAL(NUM$) + VAL(PR$)))
                PR$ = RIGHT$(T$, 1)
                ACU = 0
                IF LEN(T$) > 1 THEN ACU = LEFT$(T$, LEN(T$) - 1)
                SEEK #3, LT5: PUT #3, LT5, PR$
                LT5 = LT5 + 1
                NEXT KB
                IF ACU <> 0 THEN PR$ = LTRIM$(STR$(ACU)): PUT #3, LT5, PR$
            CLOSE (2)
        LT6 = LT6 + 1
        LT5 = LT6
        ACU = 0
        NEXT JB
    CLOSE (3)
CLOSE (1)

OPEN "D" + ".MLT" FOR BINARY AS #3: LD = LOF(3): CLOSE (3)

'AQUI INVERTIMOS EL RESULTADO FINAL
ER = 1
OPEN "D" + ".MLT" FOR BINARY AS #3
    OPEN "R" + ".MLT" FOR BINARY AS #4
        FOR N = LD TO 1 STEP -1
        SEEK #3, N: GET #3, N, PR$
        SEEK #4, ER: PUT #4, ER, PR$
        ER = ER + 1
        NEXT N
    CLOSE (4)
CLOSE (3)

'AQUI ELIMINAMOS LOS PRODUCTOS PARCIALES
KILL "D.MLT"
FOR N = 0 TO 9
C$ = LTRIM$(STR$(N))
KILL C$ + ".MLT"
NEXT N

T2 = TIMER
PRINT "END"
PRINT "HORA FINAL = "; TIME$
PRINT "DIFERENCIA = "; T2 - T1; "SEGUNDOS"
PRINT "SOLUTION IN THE FILE: R.MLT "

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

IN THIS DIRECTION WE CAN SEE THE PHOTOGRAPH OF THE FIRST MULTIPLICATION THAT DID.

http://HTTP://LH5.GGPHT.COM/_QM8LM2MCLBE/SF3X6CY26OI/AAAAAAAAAHG/H9XQFQXBXMA/BIG+MULTIPLICATION.JPG

'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Thancks all Friends !!!!
Logged
BigBadKing
New Member

Posts: 3


« Reply #1 on: December 28, 2009, 12:46:15 PM »

Nice work!
Logged
lrcvs
Member
*
Posts: 56


« Reply #2 on: December 28, 2009, 03:21:12 PM »

Thancks !!!

Regards

lrcvs
Logged
lrcvs
Member
*
Posts: 56


« Reply #3 on: December 28, 2009, 07:42:41 PM »

Address of the image cache of the Post:

Big Multiplication ...

Parte 1
 
http://74.125.77.132/search?q=cache:t9xfKa_ISYMJ:forum.qbasicnews.com/index.php%3Ftopic%3D13202.0+%22big+multiplication+of+numbers+integers%22&cd=1&hl=sv&ct=clnk&gl=se
 
Parte 2

http://209.85.229.132/search?q=cache:Whue3RdktPEJ:forum.qbasicnews.com/index.php%3Ftopic%3D13202.15+big+multiplication&cd=2&hl=es&ct=clnk&gl=es


The direction of the photo does not work.

Writing on Google image: Big multiplication

It is the first

Regards

lrcvs
« Last Edit: December 29, 2009, 07:20:40 AM by wildcard » Logged
lrcvs
Member
*
Posts: 56


« Reply #4 on: January 04, 2010, 07:48:46 PM »

Attachment file format "*. ZIP" of the cached copy of the original file.

They are all friends who helped create this "short" multiplication.

Thank you all.

lrcvs
Logged
lrcvs
Member
*
Posts: 56


« Reply #5 on: January 15, 2010, 10:43:25 AM »

'Program multiplication simple
'lrcvs
'(MU) Spain
'13 Jan 2010

'This program is based on: a * b = c   >>>   a = c / b

CLS

a$ = "9876543298789"
b$ = "2468013"

la = LEN(a$) + LEN(b$)
c$ = STRING$(la, "0")

FOR r = 1 TO la
    FOR s = 0 TO 9
       MID$(c$, r) = LTRIM$(STR$(s))
       v$ = LTRIM$(STR$(VAL(c$) / VAL(b$)))
       IF v$ = a$ THEN PRINT "Prog = "; VAL(c$): PRINT : PRINT "Comp = "; VAL(a$) * VAL(b$): END
       IF VAL(a$) > VAL(v$) THEN MID$(c$, r) = LTRIM$(STR$(s))
       IF VAL(a$) < VAL(v$) THEN MID$(c$, r) = LTRIM$(STR$(s - 1)): EXIT FOR
    NEXT s
NEXT r
SLEEP
END

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!