1. Home >
  2. Apps >
  3. Groups >

Square of large numbers without any memory limit

Question asked by smorgasbord in #Coffee Room on Apr 23, 2014
smorgasbord
smorgasbord · Apr 23, 2014
Rank D2 - MASTER
...just a code written in www.ahkscript.org
setbatchlines -1

No = 1234567891234567891234567891234567891234567899

MsgBox % "Square of " . No . " is:`n" square(No)
exitapp

square(No)
{



No := "0" . No

Q := R := StrLen(No)

zeroes := StrLen(No) * 2 + 2

stringsplit, k, No

index := 1

Loop, % StrLen(No)
{
   
        Loop, % StrLen(No)
        {
            if ( append = "" )
                append = 0
        process := k%Q% * k%R% + append
        append =
        stringsplit, A, Process
            if ( A0 = 2 )
            {
                    digit := A2
                    Append := A1
            }  
            else
            {
                    digit := A1
                    Append :=
            }
;~ MsgBox % digit
        M%index% := digit M%index%
        digit =
        r--
        }

append_zeroes :=  index-1


loop, % append_zeroes
    app_zer .= 0

M%index% := M%index% . app_zer
app_zer =


loop, % zeroes - Strlen(M%index%) - 2
    Zer .= 0

M%index% := Zer . M%index%
ans .= M%index% "`n"


StringSplit, new_line, M%index%
StringSplit, ol_ne, old_line
damm := new_line0


if ( old_line != "" )
{
   
loop, % new_line0
{

if ( append2 = "" )
    append2 = 0

process2 := new_line%damm% + ol_ne%damm% + append2
append2 =
stringsplit, A_A, Process2
if ( A_A0 = 2 )
{
    digit2 := A_A2
    Append2 := A_A1
}
else
{
    digit2 := A_A1
    Append2 :=
}
damm--
final := digit2 final
}
append2 = digit2 =
}

if ( final = "" )
old_line := M%index%
else
    old_line := final
if ( A_index != StrLen(No) )
final =
Process = Append :=
Q--
R := StrLen(No)
index++
    Zer :=
}

StringSplit, the_end, m1

end := the_end%the_end0%

final := RegExReplace(final, "(0)+(\d+)0", "$2")

final := final . end

return final
}
Posted in: #Coffee Room
zaveri
zaveri · Apr 23, 2014
Rank A3 - PRO
So what
smorgasbord
smorgasbord · Apr 23, 2014
Rank D2 - MASTER
just ignore, right?

You must log-in or sign-up to reply to this post.

Click to Log-In or Sign-Up