Maths

Discuss other useful utilities, general computing tips & tricks, Internet resources, etc.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Maths

11 Oct 2013, 11:56

Using "SetBatchLines, -1" will speed up the run times.
If you just want to determine if a number is prime instead of finding all the factors, the second chunk of code I posted is faster than the first. Here they are with some speed tests. The first one takes about 1 second, the second one takes about 250-300ms:

Code: Select all

#NoEnv
SetBatchLines, -1
SetFormat, Float, 0.0
n := 6746328388801
Tick := A_TickCount
f := 2, x := Sqrt(n)
while, (f <= x) {
	if (!Mod(n, f))
		factors .= f "`n" (n / f) "`n"
	f++
}
Sort, factors, N U
factors := !factors ? "Prime" : factors
Tick := A_TickCount - Tick
MsgBox, % factors "`nComputed in " Tick "ms."

Code: Select all

#NoEnv
SetBatchLines, -1
Tick := A_TickCount
p := IsPrime(6746328388801)
Tick := A_TickCount - Tick
if (p)
	MsgBox, % "The number is prime.`nComputed in " Tick "ms."
else
	MsgBox, % "The number is not prime.`nComputed in " Tick "ms."
return

IsPrime(n) {
	if (n < 2)
		return, 0
	else if (n < 4)
		return, 1
	else if (!Mod(n, 2))
		return, 0
	else if (n < 9)
		return 1
	else if (!Mod(n, 3))
		return, 0
	else {
		r := Floor(Sqrt(n))
		f := 5
		while (f <= r) {
			if (!Mod(n, f))
				return, 0
			if (!Mod(n, (f + 2)))
				return, 0
			f += 6
		}
		return, 1
	}
}
Edit: The "IsPrime" function uses the rule which says every prime except 2 and 3 can be written as n = 6k ± 1 where k is an integer and n is the prime number. So the function only has to check (at most) one third of the numbers between 0 and Sqrt(n).
Reference: https://en.wikipedia.org/wiki/Primality ... ve_methods
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

12 Oct 2013, 10:43

kon wrote:Using "SetBatchLines, -1" will speed up the run times.
If you just want to determine if a number is prime instead of finding all the factors, the second chunk of code I posted is faster than the first. Here they are with some speed tests. The first one takes about 1 second, the second one takes about 250-300ms:

Code: Select all

#NoEnv
SetBatchLines, -1
SetFormat, Float, 0.0
n := 6746328388801
Tick := A_TickCount
f := 2, x := Sqrt(n)
while, (f <= x) {
	if (!Mod(n, f))
		factors .= f "`n" (n / f) "`n"
	f++
}
Sort, factors, N U
factors := !factors ? "Prime" : factors
Tick := A_TickCount - Tick
MsgBox, % factors "`nComputed in " Tick "ms."

Code: Select all

#NoEnv
SetBatchLines, -1
Tick := A_TickCount
p := IsPrime(6746328388801)
Tick := A_TickCount - Tick
if (p)
	MsgBox, % "The number is prime.`nComputed in " Tick "ms."
else
	MsgBox, % "The number is not prime.`nComputed in " Tick "ms."
return

IsPrime(n) {
	if (n < 2)
		return, 0
	else if (n < 4)
		return, 1
	else if (!Mod(n, 2))
		return, 0
	else if (n < 9)
		return 1
	else if (!Mod(n, 3))
		return, 0
	else {
		r := Floor(Sqrt(n))
		f := 5
		while (f <= r) {
			if (!Mod(n, f))
				return, 0
			if (!Mod(n, (f + 2)))
				return, 0
			f += 6
		}
		return, 1
	}
}
Edit: The "IsPrime" function uses the rule which says every prime except 2 and 3 can be written as n = 6k ± 1 where k is an integer and n is the prime number. So the function only has to check (at most) one third of the numbers between 0 and Sqrt(n).
Reference: https://en.wikipedia.org/wiki/Primality ... ve_methods
beautiful it is :) keep guiding :)
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

17 Oct 2013, 02:58

added
determinant ( order 3) solver and combination main formula calculator
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

17 Oct 2013, 05:08

added Permutation stuff
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

19 Oct 2013, 09:40

added three more scripts,
John ... you working ?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Maths

19 Oct 2013, 11:26

nice 3d rotation script.
if you add an equal offsets for each dimensions to the coordinates, you could create a nice orthographic map view.
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

19 Oct 2013, 11:38

Alibaba wrote:nice 3d rotation script.
if you add an equal offsets for each dimensions to the coordinates, you could create a nice orthographic map view.
Thanks :o :o , just putting all stuff at one place, i haven't tested if it works 100%, :cry: :cry:

your second line makes no sense to a noob as myself :? :?
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

23 Oct 2013, 10:51

added :
To get square roots of perfect squares orally
John ... you working ?
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

25 Oct 2013, 07:40

added:

Sum of first N natural numbers, sum of their squares/cubes....till power 7
John ... you working ?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Maths

26 Oct 2013, 07:30

smorgasbord wrote:just putting all stuff at one place, i haven't tested if it works 100%, :cry: :cry:
I tested it. Sorry, it doesn't work... :(
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

26 Oct 2013, 08:11

@alibaba which one?
tell soon
:-p
John ... you working ?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Maths

26 Oct 2013, 11:23

smorgasbord wrote:@alibaba which one?
tell soon
:-p
3D rotation
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

26 Oct 2013, 23:20

@Alibaba
http://www.siggraph.org/education/mater ... 3drota.htm
i coded as per this.
Please elaborate a bit :-p
btw: Where are your forty thieves?
John ... you working ?
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: Maths

27 Oct 2013, 06:08

Using other vars, say, x1, y1, z1 instead of xyz on the left hand side will fix it.
Btw 2d rot was and is also wrong.
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

27 Oct 2013, 06:47

@Strobo and alibaba
could you kindly edit them ?
and comment the edited part.
:)
thanks in advance.
John ... you working ?
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Maths

27 Oct 2013, 11:12

smorgasbord wrote:Where are your forty thieves?
I never saw them again, since there was this guy handing out free beer.
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

27 Oct 2013, 11:17

Alibaba wrote:
smorgasbord wrote:Where are your forty thieves?
I never saw them again, since there was this guy handing out free beer.
Actually i am that beer guy! lol

:x :x :x :oops: :oops: :cry: :cry:
These emoticons are awesome! :twisted: :twisted:
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Location: India
Contact:

Re: Maths

30 Oct 2013, 07:54

Sum of first N natural numbers, sum of their squares/cubes....till power 7
The code what I see is the following . I dont think this is the code you have wrote --
Spoiler
The &#40 looks to be added due to some syntax highlight problems ... Please post the correct code.
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
User avatar
smorgasbord
Posts: 493
Joined: 30 Sep 2013, 09:34

Re: Maths

30 Oct 2013, 11:51

@AVI
Thanks for pointing that out, :(
i think that is the only place where i store stuff, so i might need some time to edit it.
i reported the same(Almost) bug in here http://ahkscript.org/boards/viewtopic.php?f=5&t=314
But as i could circumvent the bug i put it as [solved]
:(:(
Sorry.
John ... you working ?
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Maths

31 Oct 2013, 09:04

You'll have to repost your stuff.
Recommends AHK Studio

Return to “Other Utilities & Resources”

Who is online

Users browsing this forum: No registered users and 5 guests