Qbasicnews.com

Full Version: Multiplication ultra_mega very very very... fast / rapida.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
CLS
'Multiplicacion ilimitada reducida Version 2.0
'Luis Belmonte Abellan
'lrcvs@yahoo.es
'Spain
'01.11.08

'>>>>>>>>>> Now is correct!!! <<<<<<<<<<<<



'Multiplication ultra_mega very very very............................... fast.

'The difference between this second method of multiplying, is that (no direct relizan amounts).
'It's very very very fast.

'On this occasion I want a program that is fast, which may be its operation
'and in turn I want it to be easily adaptable to all programs,
'values do not enter very large.

'You can make unlimited based on the previous method of multiplication.

'This example is 500 * 500 digits, for a value of 1,000 digits equally accurate
'as with the previous method, but much faster.

'I want to be liked around the world and having so much acceptance as the previous one.

'We hope your opinion.

'Description of program / algorithm:

'In summary, is based on the comparison of strings.

'So they can understand the program, commentators who are doing this at every stage.

'......................................................................................

'Multiplicacion ultra_mega muy muy muy............................... rapida.

'La diferencia entre este segundo metodo de multiplicar, es que (no se relizan sumas directas).

'En esta ocasion quiero que sea un programa rapido, y que pueda verse su funcionamiento
'y a su vez quiero que sea facilmente adaptable a todos los programas,
'no introduzco valores muy grandes.

'Puede hacerse ilimitada basandose en el metodo de la anterior multiplicacion.

'Este ejemplo es de 500 * 500 digitos, obteniendose un valor de 1000 digitos exactos igualmente
'como con el anterior metodo, pero muchisimo mas rapido.

'Deseo que sea del agrado de todo el mundo y que tenga tanta aceptacion como la anterior.

'Tambien espero vuestra opinion.

'Descripcion del programa / algoritmo:
'Sintetizando, esta basado en la comparacion de cadenas.

'Para que se pueda entender el programa, comentare que se esta haciendo en cada etapa.

'Este es el resultado exacto:
'6165397008516376051950033373390229410751004835184480902993233889710369853442160914070829560711954388202845672437699777
_724574178609761020197032714028763436485290911899016911654292780369329408420278089207740413533022343582011754442192646
_630048432066001919472495259780408247597789162925441368720910791989033373443178406504128959076249561119195229686338044
_776840493433526050315809483845056233579102799767568780497058577272091220272409584412185995143355050808442491190965525
_194426620450698104011148031190250554332112855736335856311075579186536466258812911235432997860922319582272578236517908
_182916819687586208248871942955712532502837965090365973298354642554544966629975422405378983221682560363976767936502027
_887563597060671565396832333032844305910414002652793328984553084566786432790065007631977057765602423492768674940668184
_401960674608457769027928903653508442277529794131241161270937140423443276790944962496842225436445454223036956765907801
_782244514221194140338134325170425519528078075499862592673625790

'Variables:
'a$ = Multiplicando
'b$ = Multiplicador
'c$ = Producto / Resultado / Solucion
'a = Acumulador de los decimales o lo que nos llevamos.
'h = Sirve para hallar la longitud del resultado
'f = Control de posicion de los resultados parciales
'j,k = Controladores de posicion para calcular el producto parcial
'r$ = Resultado parcial de la multiplicacion
'u$ = Valor de la unidades

'Variables:
'a$ = Multiplying
'b$ = Multiplier
'c$ = Output / Result / Solution
'a = Accumulator to decimals or what we carry.
'h = Allows you to find the length of the result
'f = Control position of the partial results
'j, k = controlling position to calculate the partial product
'r$ =  Result part of the multiplication
'u$ = Value of units

'Programa / program
'..............................................................

CLS
a$ = "7647646855315025252375547715121336113438250320678786462447786243067167026863833858561687104832136041376238345301112678
_57711205763004013302662462516040214152454603446105623786322220125113221516631431452200560484825321448578703377041685602055
_54532384145548407647646855315025252375547715121336113438250320678783238224554821744845703631610525338354872610814618154006
_013168880456254788725417727710604401383836268717201224702248733014640808068037718073844182081300773462526020082152455711456173634787322230"
b$ = "8061822316274315324633173702820153315483787014780216037107455563238224554821744845703631610525338354872610814618154006013
_16888045625478872541772771060440138383626871720122470224873301464080806803771807384418208130077346252602008215245571145617363
_47873222308061822316274315324633173702820153315483787014780216037107455563238224554821744845703631610525338354872610814618154
_006013168880456254788725417727710604401383836268717201224702248733014640808068037718073844182081300773462526020082152455711456173"
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$®)
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$
sleep
END
Now, is correct program.

It works / works perfectly well.

Apology, forgiveness.

...............................................................

Ahora si esta correcto el programa.

Trabaja perfectamente.

Disculpas.!!!
Luis:

What a great program!  But, I am having a problem with it, as my result and yours are:
Que buen programa!  Pero, tengo un problema, porque mi resultado y el suyo son:

[quote]
Program result is of length 626, and is:
6165397008516376051950033373390229410751004835184480902993233889710369853442160914070829560711954388202845672437
_699777724574178609761020197032714028763436485290911899016911654292780369329408420278089207740413533022343582011
_754442192646630048432065998247440802814189315284776103304253389595962591051353593479760520465112909818970173210
_180428548898151707969066507068484089566313081905857292345752807934207317815267994934345379576226777429262010764
_365422578919544431616442586215526371781960226716802840169505601443970881408344142333869995111882028659655222019
_2782413888627224499356283965740845273786366903769487705847603546255933

Luis shows result with length 759, and is:
6165397008516376051950033373390229410751004835184480902993233889710369853442160914070829560711954388202845672437
_699777724574178609761020197032714028763436485290911899016911654292780369329408420278089207740413533022343582011
_754442192646630048432066001919472495259780408247597789162925441368720910791989033373443178406504128959076249561
_119195229686338044776840493433526050315809483845056233579102799767568780497058577272091220272409584412185995143
_355050808442491190965525194426620450698104011148031190250554332112855736335856311075579186536466258812911235432
_997860922319582272578236517908182916819687586208248871942955712532502837965090365973298354642554544966629975422
_40537898322168256036397676793650202788756359706067156539683233303284430591041400265279332898
[\quote]
Hi Ralph!

I do not know, but the first program that put him in the forum, had an error, was proof of work.

After I changed, it works very well and has no errors.

You can check with the Windows calculator.

Greetings.
Spanish:  No, Luis, mi problema es que yo use su program, tal cual lo anuncio usted.  Yo solamente quiero saber por que su program no trabaja bien con mi QuickBASIC 4.5.

English: No, Luis, my problem is that I used your program, as you posted it, and got the result I posted.  I just want to know why your program didn't work with my QuickBASIC 4.5.
Hi, Ralph!

I do not know.

I can not know.

This post of the program is Ok.

It works well with QB 4.5 and FreeBASIC.

The program is Ok!

............................................................

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$®)
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$
sleep
END
Ok!