square() without memory restriction

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

square() without memory restriction

21 Mar 2014, 23:13

pardon my coding. will try to make it indented.
was excited to post it soon.

so here it is

Code: Select all

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
}
Last edited by smorgasbord on 25 Mar 2014, 02:38, edited 1 time in total.
John ... you working ?
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: square() without memory restriction

21 Mar 2014, 23:29

any examples? :geek:
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: square() without memory restriction

21 Mar 2014, 23:36

like so as to confirm?

one is already there in the script. just run it.

answer copied to clipboard after you close the messagebox.
John ... you working ?
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: square() without memory restriction

24 Mar 2014, 18:48

>> one is already there in the script. just run it.
doh!! but thanks for mentioning it!
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: square() without memory restriction

25 Mar 2014, 02:44

Guest10 wrote:any examples? :geek:
please check again. :ugeek:
John ... you working ?
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: square() without memory restriction

25 Mar 2014, 10:28

reminds me of a spigot approach
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: square() without memory restriction

25 Mar 2014, 21:26

@skeski
Thanks for posting. its an honor!
dont know what spigot approach is, bt what i have used is this: it does the multiplication in the same manner as a human would do.
slight differences are.
1. it first adds a 0 to the no. in the left.
2. the total is done every time a digit of the no. is multiplied with the complete no.

:)
John ... you working ?

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 263 guests