Archive: Math tricks and examples


Math tricks and examples
Math final attached.
May be I'll post here some useful scripts...

Let's start with Position function, use like pos=P(text,subs) and it will place position of first occurrence of subs at text or -1 if not found.
Use example:

Math::Script"r0=P('Whereitis?','it')"

will place 6 to $0.
Source (should be defined before use of course):
Math::Script/NOUNLOAD"P(s,e,p,i)(p=-1;i=0;#{(i<l(s))&&(p<0),#***91;s***91;i,i+l(e)-1***93;==e,p=i***93;;i++};p)"

The second one is Search And Replace, result=SaR(text,s,r). s and r are the arrays of search and replace text pairs.
Example:
Math::Script"a='Hello\r\nWorld!!!';a=SaR(a,{'\r','\n'},{'$\r','$\n'});r0=a"

this will place hello world with real $\r and $\n to $0.
Source:
Math::Script/NOUNLOAD'SaR(s,fa,ra,i,f,r,e,p)(i=0;#{i<l(fa),e=l(f=fa***91;i***93;);r=ra***91;i***93;;p=0;#{p<l(s),#***91;s***91;p,p+e-1***93;==f,s=(s***91;,p-1***93;)+r+(s***91;p+e,***93;);p+=l(r),p++***93;};i++};s);'


Fuh... it looks terrible.
Anyway, I've forgotten mathtest.


Thanks Nik, uploaded.


sorry for being slightly? ;) off topic, but i just wanted to thank you brainsucker for this plugin, and all your other work too.

i can't imagine how you thought of and wrote system.dll, just using it is cryptic enough - lol. i saw your work on that system tray plugin, and the banner plugin too... we're really lucky to have contributors like yourself. thanks. :)

and kichik, no praise is enough for you. ;) all this work on the nsis core (and plugins etc.), and so patient and helpful with people in the forums, you're an example to everyone, really. :)

many thanks to joost for his hard work on MUI which has raised NSIS above all criticisms in terms of it's appearance. I think NSIS installers look better than those of the competitors now. ;)

my apologies to other contributors, even those who write scripts and the like for the archive, you're too numerous to mention, but i thank you too. :)

salaam/peace


Thank you very much psyke! :D


psyke: thanx ;)

KichiK: calc.exe ;)


I was actually thinking of something like this:

http://education.ti.com/images/produ...92pluscalc.jpg

or this one: http://www.technoplaza.net/images/89large.jpg

;)


heh, they are not cool enough (for me).
I prefer something like that [IMG]http://www.computer-museum*****images/precomp/felix.jpg[/IMG], or even that [IMG]http://www.savel*****museum/soviet_calc/abac.jpg[/IMG].

Have you ever programmed something like that? ;) It gives you not only moral pleasure, but also forces you to do some physical exercises... Really cool :))) I'll think about introducing something like that in to the next version of Math ;)


:D


"Math" plugin will be a wrong name if you add much of other things than the mathematics things (i.e. Search & Replace). If is called "Math", have to be focused on all things in the mathematics subject. (Things like that, you should put in other dll, isn't it?)


good i have taken a look into this thrad, deguix is right, i thought it is something like a calculator to solve my math problems :D


SaR is just demonstration of posibilities. Since I wrote a expression parser for math, it took almost nothing to include the support for string operations, on the other side if I am using math anyway, it comes more naturally to me to work with strings using C style scripting, than to write such functions in NSIS script language.

Btw, fast prime numbers function (use PN(from, to), returns array):
PN(f,t, m,a,b,c,n,i,d,k) (m=sqt(t)+1;a={};b={};c=n=0; i=2; #{i<t, d=k=0; #{(!k)&&(d<n), #[i%(a[d++])==0, k++]}; #[!k,#[i>=f,b[c++]=i];#[i<=m,a[n++]=i,#[i<f,i=f-1]]]; i++}; b);

Example of use:
r0='Res: '; a=PN(1000000,1010000); i=-10;l=l(a); #{(i+=10)<l, r0+= a[i] + ' '}


Maybe it can be more simpler... You know how to use the C style scripting, but I'm not. Please, make macros or defines for the codes... Or put all in the documentation (if isn't here).


Macros or defines for what? It's obvious enough at simple level, and I couldn't write macros for advanced cases since they are countless.
For example we want to take square root from the result of division of the sum of $0 and $1 by $2, and place it into $3. Here it is:

r3=sqt((r0+r1)/r2)

since the parcer will treat numbers as int if it will not meet . or e sign, you could add f to calculate division right anyway:

r3=sqt(f(r0+r1)/r2)

I don't know what to place in macros or defines here :)


Macros or defines for what?
For easily put big codes as the Search and Replace. I.e.:

!define Search&Replace 'SaR(s,fa,ra, i,f,r,e,p) (i=0;#{i<l(fa),e=l(f=fa[i]);r=ra[i];p=0;#{p<l(s),#[s[p,p+e-1]==f,s=(s[,p-1])+r+(s[p+e,]);p+=l(r), p++]}; i++}; s);'

Section
Math::Script "${Search&Replace}"
SectionEnd

Huh :)
Idea :)
Anyway, using system.dll as an example, I know that nobody uses include files (beside MUI of course :)

On the other hand such a call could be done once for the script with /NOUNLOAD param (for example at OnInit), and then the "SaR(,{},{})" function could be simply used.
So, thank you for idea, I'll think...