. I think it would have been difficult for anyone to write a faster script. My script (which, much to my embarrassment, I will post) performs the prescribed calculation in about 10 seconds. Your script does the calculation in 2 to 3 tenths of a second. My script does the math exactly the way one would do it with a pencil and paper. I have not yet taken the time to study your script to ascertain what mathematical magic you're using.
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 644
Top = 113
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Multiply Long Numbers'
ClientHeight = 397
ClientWidth = 1056
Color = clBtnFace
Position = poScreenCenter
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
DesignSize = (
1056
397)
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 40
Top = 8
Width = 59
Height = 13
Caption = 'First Number'
end
object Label2: TLabel
Left = 40
Top = 56
Width = 77
Height = 13
Caption = 'Second Number'
end
object Label3: TLabel
Left = 40
Top = 200
Width = 37
Height = 13
Caption = 'Product'
end
object Label4: TLabel
Left = 368
Top = 128
Width = 63
Height = 13
Caption = 'Product Time'
end
object Label5: TLabel
Left = 976
Top = 128
Width = 77
Height = 13
Caption = 'Character Count'
end
object Label6: TLabel
Left = 376
Top = 152
Width = 6
Height = 13
Caption = '0'
end
object Label7: TLabel
Left = 984
Top = 152
Width = 6
Height = 13
Caption = '0'
end
object Label8: TLabel
Left = 840
Top = 128
Width = 47
Height = 13
Caption = 'Sum Time'
end
object Label9: TLabel
Left = 848
Top = 152
Width = 6
Height = 13
Caption = '0'
end
object Label10: TLabel
Left = 904
Top = 128
Width = 47
Height = 13
Caption = 'TotalTime'
end
object Label11: TLabel
Left = 912
Top = 152
Width = 6
Height = 13
Caption = '0'
end
object Edit1: TEdit
Left = 14
Top = 28
Width = 1034
Height = 21
TabOrder = 0
end
object Edit2: TEdit
Left = 14
Top = 74
Width = 1030
Height = 21
TabOrder = 1
end
object MSButton1: tMSButton
Left = 476
Top = 361
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = 'Multiply'
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
object MSMemo1: tMSMemo
Left = 14
Top = 216
Width = 1027
Height = 130
WordWrap = True
VertScrollBarStyles.ButtonSize = 16
HorzScrollBarStyles.ButtonSize = 16
Anchors = [akLeft, akTop, akBottom]
TabOrder = 3
end
object ProgressBar1: TProgressBar
Left = 128
Top = 177
Width = 785
Height = 16
TabOrder = 4
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,Multiply
Show>Dialog1,
Exit>
SRT>Multiply
Timer>StartTime
SetDialogProperty>Dialog1,Label9,Caption,0
SetDialogProperty>Dialog1,Label7,Caption,0
SetDialogProperty>Dialog1,Label6,Caption,0
SetDialogProperty>Dialog1,Label11,Caption,0
SetDialogProperty>Dialog1,MSMemo1,Text,
GetDialogProperty>Dialog1,Edit1,Text,no1
GetDialogProperty>Dialog1,Edit2,Text,no2
GoSub>Works
Timer>EndTime
Let>ProdTime={(%EndTime%-%StartTime%)/1000}
SetDialogProperty>Dialog1,Label6,Caption,ProdTime
Timer>StartTime
Let>CycleCount=0
GoSub>NewAdd
Length>Answer,CharCount
Let>dotpos=%CharCount%-%DecimalPlaces%
Midstr>Answer,1,dotpos,integer
Midstr>Answer,dotpos,DecimalPlaces,decimal
If>decimal=
Else
Let>Answer=%Integer%.%decimal%
EndIf
Timer>EndTime
Let>SumTime={(%EndTime%-%StartTime%)/1000}
Let>TotalTime=%SumTime%+%ProdTime%
SetDialogProperty>Dialog1,Label9,Caption,SumTime
SetDialogProperty>Dialog1,Label7,Caption,CharCount
SetDialogProperty>Dialog1,Label11,Caption,TotalTime
SetDialogProperty>Dialog1,MSMemo1,Text,%Answer%
END>Multiply
SRT>Works
Position>.,no1,1,dotpos1
If>dotpos1>0
StringReplace>no1,.,,no1
RegEx>.,No1,0,Digit_1,Digit_1_count,0
Let>decimalPlaces1={%Digit_1_Count%-%dotpos1%+1}
Else
Let>decimalplaces1=0
EndIf
Position>.,no2,1,dotpos2
If>Dotpos2>0
StringReplace>no2,.,,no2
RegEx>.,No2,0,Digit_2,Digit_2_count,0
Let>decimalPlaces2={%Digit_2_Count%-%dotpos2%+1}
Else
Let>decimalplaces2=0
EndIf
Let>DecimalPlaces=%decimalPlaces1%+%decimalPlaces2%
RegEx>.,No1,0,Digit_1,Digit_1_count,0
RegEx>.,No2,0,Digit_2,Digit_2_count,0
Let>AnswerStr=
Let>Progressadd={30/%Digit_1_Count%}
Let>kk1={%Digit_1_count%+1}
Let>Cycles=digit_1_count
Repeat>kk1
Sub>kk1,1
Let>AnswerStr_%kk1%=
Let>PrevStr=
Let>CarryOver=0
Let>kk2={%Digit_2_count%+1}
Repeat>kk2
Sub>kk2,1
If>kk2=0
If>CarryOver<>0
Let>AnswerStr_%kk1%=%CarryOver%%PrevStr%
EndIf
Else
Let>product=Digit_1_%kk1%*Digit_2_%kk2%
Add>product,%CarryOver%
If>Product>9
RegEx>.,Product,0,Char,Char_count,0
Let>AnswerStr_%kk1%=%Char_2%%PrevStr%
Let>CarryOver=%Char_1%
Else
Let>AnswerStr_%kk1%=%Product%%PrevStr%
Let>CarryOver=0
EndIf
Let>PrevStr=AnswerStr_%kk1%
EndIf
Until>kk2=0
Let>Value=AnswerStr_%kk1%
Let>Places={%Digit_1_count%-%kk1%}
If>Places>0
Let>kkp=0
Repeat>kkp
Add>kkp,1
Let>Value=%value%0
Until>kkp=Places
EndIf
Let>AnswerStr_%kk1%=Value
Let>Progress={round(%Progressadd%*((%Digit_1_Count%+1)-%kk1%))}
SetDialogProperty>Dialog1,ProgressBar1,Position,Progress
Until>kk1=1
Let>Progress=30
SetDialogProperty>Dialog1,ProgressBar1,Position,Progress
END>Works
SRT>NewAdd
Repeat>CycleCount
Add>CycleCount,1
If>CycleCount=1
If>Cycles=1
Let>Answer=AnswerStr_1
Goto>NewAddComplete
Else
Let>Term_1=AnswerStr_1
Let>Term_2=AnswerStr_2
Add>CycleCount,1
EndIf
Else
Let>Term_1=Answer
Let>Term_2=AnswerStr_%CycleCount%
EndIf
Let>ProgressAdd={70/%Cycles%}
VBEval>StrReverse("%Term_1%"),Term_1
VBEval>StrReverse("%Term_2%"),Term_2
RegEx>.,Term_1,0,Digit_1,Digit_1_count,0
RegEx>.,Term_2,0,Digit_2,Digit_2_count,0
If>{%Digit_1_Count%>=%digit_2_Count%}
Let>MaxLength=Digit_1_Count
If>{%Digit_1_Count%=%digit_2_Count%}
Else
Let>Places=%Digit_2_count%
If>Places>0
Repeat>Places
Add>Places,1
Let>Digit_2_%Places%=0
Until>Places=Digit_1_Count
EndIf
EndIf
Else
Let>MaxLength=Digit_2_Count
Let>Places=%Digit_1_count%
If>Places>0
Repeat>Places
Add>Places,1
Let>Digit_1_%Places%=0
Until>Places=Digit_2_Count
EndIf
EndIf
Let>CarryOver=0
Let>DD=0
Repeat>DD
Add>DD,1
Let>Sum_%DD%=Digit_1_%DD%+Digit_2_%DD%
Let>Sum_%DD%=Sum_%DD%+%CarryOver%
If>Sum_%DD%>9
RegEx>.,Sum_%DD%,0,Char,Char_count,0
Let>Sum_%DD%=Char_2
Let>CarryOver=Char_1
Else
Let>CarryOver=0
EndIf
Until>DD=%MaxLength%
If>CarryOver>0
Add>DD,1
Let>Sum_%DD%=CarryOver
EndIf
Let>Answer=
Let>FF=0
Repeat>FF
Add>FF,1
Let>Value=Sum_%FF%
Let>Answer=%Value%%Answer%
Until>FF=DD
Let>Progress={30+(round(%Progressadd%*%CycleCount%))}
SetDialogProperty>Dialog1,ProgressBar1,Position,Progress
Until>CycleCount=Cycles
Label>NewAddComplete
Let>Progress=100
SetDialogProperty>Dialog1,ProgressBar1,Position,Progress
END>NewAdd