'Non-UI application (console / server application)
Sub AppStart (Args() As String)
Log(SplitMultiply("1234", "0002", 4))
Log(SplitMultiply("80001", "12341", 5))
End Sub
Sub SplitMultiply (x As String, y As String, n As Int) As String
If n = 1 Then
Return GetDigitFromString(x, 0) * GetDigitFromString(y, 0) 'one digit * one digit
Else
Dim m As Int = Ceil(n / 2)
Dim a As String = DivideBy10M(x, m)
Dim b As String = Modulo10M(x, m)
Dim c As String = DivideBy10M(y, m)
Dim d As String = Modulo10M(y, m)
Dim e As String = SplitMultiply(a, c, m)
Dim f As String = SplitMultiply(b, d, m)
Dim g As String = SplitMultiply(b, c, m)
Dim h As String = SplitMultiply(a, d, m)
End If
'the strings will be parsed here and later converted back to a string.
'we use NumberFormat2 to control the formatting.
Return NumberFormat2(ShiftByM(e, 2 * m) + ShiftByM(g + h, m) + f, 0, 0, 0, False)
End Sub
Sub GetDigitFromString(s As String, index As Int) As Int
Return "" & s.CharAt(index)
End Sub
Sub DivideBy10M (s As String, m As Int) As String
If s.Length <= m Then Return "0"
Return s.SubString2(0, s.Length - m)
End Sub
Sub Modulo10M (s As String, m As Int) As String
Return s.SubString(s.Length - m)
End Sub
Sub ShiftByM(s As String, m As Int) As String
For i = 0 To m - 1
s = s & "0"
Next
Return s
End Sub