Maths

Discuss other useful utilities, general computing tips & tricks, Internet resources, etc.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Maths

07 Oct 2013, 10:08

Practise Installment questions ( Simple Interest, Compound Interest, Amount Due in, Amount taken as loan )
Spoiler
Solve Installment Problems, Currently only solves for The equal repayment installment
Spoiler
Quadratic Equation Solver
Spoiler
Factors Of A Number
Spoiler
Time and Work by GeekDude
Spoiler
Massive Human Multiplier by Frozenthia
Spoiler
LCM
Spoiler
WeekDay On Any date (without using any built-in thing, i.e. it merely calculates the No. of ODD days and tells the Day).Though the final result is verified the comments needs to be more elaborative.
Spoiler
GCD or HCF
Spoiler
2D
Spoiler
3D (rotation only)
Spoiler
determinant ( order 3 )
Spoiler
combinations (edited)

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
InputBox, nCr, Enter R and N separated with comma
StringSplit, ncr, ncr, `,
if (ncr1 = 1 OR ncr2 - ncr1 = 1)
{
    MsgBox % ncr2
exitapp
}
else
{
n := ncr2,
r := ncr2 - ncr1 > ncr1 ? ncr2 - ncr1 : ncr1
r1 := ncr2 - ncr1 < ncr1 ? ncr2 - ncr1 : ncr1
f_r := 1
n_r := 1
;;;calculating numerator;;;;;;;;;
loop % n - r
n_r := n_r * n, n := n -1
;;;;;;;;;calculating denominator;;;;;;;;;;
loop % ncr2 - r
f_r := f_r * r1, r1 := r1 - 1
;;;result;;;;;;;;;;;;;;;;;
MsgBox % floor(n_r / f_r)
exitapp
}
Vedic maths to get squares on tips
http://ahkscript.org/boards/viewtopic.php?f=6&t=231

Permutations ( 3rd post by nimda )
http://www.autohotkey.com/board/topic/7 ... n-o1-time/

Angle Between hour hand and minute hand of a clock

Code: Select all

InputBox, k, enter time separated by :
StringSplit, k, k, :
MsgBox % Abs(k1 * 30 + k2/2 - k2 * 6) >= 180 ? 360 - Abs(k1 * 30 + k2/2 - k2 * 6) : Abs(k1 * 30 + k2/2 - k2 * 6)
Last two digit solver

Code: Select all

SetFormat, float, 02.0
gui, add, text, section center, LAST TWO DIGIT SOLVER (unit's digit also)
gui, add, text, section, please enter BASE:  ; Save this control's position and start a new section.
gui, add, text,, Enter POWER of base:

gui, add, edit, ys vA ; Start a new column within this section.
gui, add, edit, vB

Gui, Add, Button, section xm default, SUBMIT

Gui, Show,, Simple Input Example
return

ButtonSUBMIT:
Gui, Submit

base := mod(a, 100)
ans := 1
;msgbox, base is %base% 
;msgbox, loop will run for %B% times
loop, %B%
{
ans := ans * Base
ans := mod(ans, 100)
;msgbox, %A% raise to power %A_index% is %ans%
}
ans += 0.0
msgbox, last two digits are `n`n %ans%
return
Remainder Theorum etc.

Code: Select all

gui, add, text, section center, REMAINDER TELLER eg. (56)^57 / 57 = 56 
gui, add, text, section, please enter BASE:  ; Save this control's position and start a new section.
gui, add, text,, Enter POWER of base:
gui, add, text,, Enter the divisor:

gui, add, edit, ys vN ; Start a new column within this section.
gui, add, edit, vP
gui, add, edit, vD

Gui, Add, Button, section xm default, SUBMIT
Gui, Show,, Simple Input Example
return

ButtonSUBMIT:
Gui, Submit
a := 1
l := mod(n, d)
;msgbox, remainder is %l%
loop, %p%
{	
m := l * a	
a := mod(m, d)
;msgbox, remainder %A_index% is %a%
}
msgbox, REMAINDER OF `n`n(%n%)^%p% / %d% `n`nIS `n`n %a%
return
To get square roots of perfect squares orally
Spoiler
Last edited by smorgasbord on 02 Dec 2013, 21:11, edited 37 times in total.
John ... you working ?
Alibaba
Posts: 479
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Maths

07 Oct 2013, 12:50

Don't you know about our awesome codebox!? ;) :D
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

07 Oct 2013, 20:49

[quote="Alibaba"]Don't you know about our awesome codebox!? ;) :D

Code: Select all

[/quote]
I wish more Info is viewable per  screenshot. :|
John ... you working ?
User avatar
TLM
Posts: 1418
Joined: 01 Oct 2013, 07:52
GitHub: TLMcode
Contact:

Re: Maths

07 Oct 2013, 22:20

Alibaba wrote:Don't you know about our awesome codebox!? ;) :D
Agree!
Spoiler
for direct help, tweet at me: https://twitter.com/CW_DTech
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

08 Oct 2013, 02:34

@TLM thanks for telling how to do it.
@Alibaba : thanks anyways lol. :-p
John ... you working ?
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Oct 2013, 08:14

2D

new coordinates, After Shifting of axes and rotation of axes,
I could not find any stuff related to the same on both forums. :)
See original post soon
John ... you working ?
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: Maths

10 Oct 2013, 11:07

I could not find any stuff related to the same on both forums.
Search for "autohotkey dr_holle pinrotate," then, go to post 2.
Your theta is not correct in general. Overall I have some issues with the style that I hopefully can explain by facing another style (untested):

Code: Select all

x := 2
y := 0
a := 0 ; origin_x
b := 0
rot := -50
;-------------------------------------------------------
shift(x, y, a, b)
msgbox,% x "`n" y
rotate(x, y, rot)
msgbox,% x "`n" y
;-------------------------------------------------------
shift(ByRef x, ByRef y, a = 0, b = 0){
	x -= a, y -= b
}
rotate(ByRef x, ByRef y, phi_in_deg = 0){
	static k := atan(1)/45
	s := sin(k*phi_in_deg), c := cos(k*phi_in_deg)
	, z := x, x := c*x-s*y, y := s*z+c*y
}
Thanks for bringing up this topic (wrong section?) and I'd like to see more content.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Oct 2013, 11:44

strobo wrote:
I could not find any stuff related to the same on both forums.
Search for "autohotkey dr_holle pinrotate," then, go to post 2.
Your theta is not correct in general. Overall I have some issues with the style that I hopefully can explain by facing another style (untested):

Code: Select all

x := 2
y := 0
a := 0 ; origin_x
b := 0
rot := -50
;-------------------------------------------------------
shift(x, y, a, b)
msgbox,% x "`n" y
rotate(x, y, rot)
msgbox,% x "`n" y
;-------------------------------------------------------
shift(ByRef x, ByRef y, a = 0, b = 0){
	x -= a, y -= b
}
rotate(ByRef x, ByRef y, phi_in_deg = 0){
	static k := atan(1)/45
	s := sin(k*phi_in_deg), c := cos(k*phi_in_deg)
	, z := x, x := c*x-s*y, y := s*z+c*y
}
Thanks for bringing up this topic (wrong section?) and I'd like to see more content.
http://www.autohotkey.com/board/topic/9 ... ten-punkt/


this? i understand only english
John ... you working ?
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: Maths

10 Oct 2013, 11:51

Yes, the function is plain ahk, but I already posted here sth similar, so, You can equally well skip that.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Oct 2013, 11:58

strobo wrote:Yes, the function is plain ahk, but I already posted here sth similar, so, You can equally well skip that.
Thanks for posting and indulging in :) :) :)

more stuff

3D rotation now!!
John ... you working ?
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Oct 2013, 12:06

@strobo
friend if you also have maths stuff do post in here.

Also suggest which topics should/may/can ( all modal verbs ) be coded.

:):-p
John ... you working ?
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: Maths

10 Oct 2013, 13:28

If I find sth relevant for the ahk universe I will post it, though, atm I have no idea.
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Maths

10 Oct 2013, 13:32

This is a faster way to find the factors of a number:

Code: Select all

SetBatchLines, -1
SetFormat, Float, 0.0
InputBox, n,, Enter a number to find its factors.
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
MsgBox, % factors
This is a function to check if a number is prime:

Code: Select all

SetBatchLines, -1
Loop, 2000 {
	if (IsPrime(A_Index))
		Primes .= A_Index ","
}
MsgBox, % Primes
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
	}
}
This thread probably belongs in the Scripts/Functions section.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Oct 2013, 21:34

kon wrote:This is a faster way to find the factors of a number:

Code: Select all

SetBatchLines, -1
SetFormat, Float, 0.0
InputBox, n,, Enter a number to find its factors.
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
MsgBox, % factors
This is a function to check if a number is prime:

Code: Select all

SetBatchLines, -1
Loop, 2000 {
	if (IsPrime(A_Index))
		Primes .= A_Index ","
}
MsgBox, % Primes
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
	}
}
This thread probably belongs in the Scripts/Functions section.
I came to know about the "while" command after i coded that. I AGREE WITH YOU 100% :) and am THANKFUL to you for pointing that.

I shall rewrite the code again :)
John ... you working ?
kon
Posts: 1756
Joined: 29 Sep 2013, 17:11

Re: Maths

10 Oct 2013, 22:41

Hi smorgasbord,
I want to explain why the code I posted for finding the factors of a number is fast. For each factor it finds, it adds two factors to the list of factors: f and n/f. This means that it only needs to check Sqrt(n) numbers, instead of (n/2) numbers. This makes for a big difference in speed, especially with large numbers. For example, to find the factors of 1234567890, my function checks Sqrt(n) = 35136 numbers which takes about 350ms on my PC. But (n/2) = 617283945 requires many more calculations and takes about 7.5 minutes. And as the numbers get larger the time gap increases.

Also, I should note that the admins seem to be working on the codeboxes, so the built in variables are not displaying properly currently. ex. in the "IsPrime" function that I posted above "hotkey.com/docs/Variables.htm#A_Index">A_Index" should just be "A_Index".
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

10 Oct 2013, 22:47

kon wrote:Hi smorgasbord,
I want to explain why the code I posted for finding the factors of a number is fast. For each factor it finds, it adds two factors to the list of factors: f and n/f. This means that it only needs to check Sqrt(n) numbers, instead of (n/2) numbers. This makes for a big difference in speed, especially with large numbers. For example, to find the factors of 1234567890, my function checks Sqrt(n) = 35136 numbers which takes about 350ms on my PC. But (n/2) = 617283945 requires many more calculations and takes about 7.5 minutes. And as the numbers get larger the time gap increases.

Also, I should note that the admins seem to be working on the codeboxes, so the built in variables are not displaying properly currently. ex. in the "IsPrime" function that I posted above "hotkey.com/docs/Variables.htm#A_Index">A_Index" should just be "A_Index".
i think i could further optimize it.. in a couple of hours

thanks
John ... you working ?
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

11 Oct 2013, 07:08

IsPrime optimization, kindly tell if it can further be improved, checked for a very large prime number i.e. 6746328388801 , kindly put that in input box
@Kon ; i used exactly the same method in the code that u suggested but please tell if i made any drastic change. I am using the array method to find out
Please kindly drop your suggestions :)
eagerly waiting

kon's method Vs. Array method
Spoiler
Array method Vs. Kon's method
Spoiler
On my laptop array method takes about 11 seconds whereas the method in which we check for the divisor when it is just less than or equal to sqrt(number_to_be_checked) takes 12 seconds,

eagerly waiting comments :)
John ... you working ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Facebook: avi.aryan.ap
Google: +AviAryan
GitHub: aviaryan
Location: India
Contact:

Re: Maths

11 Oct 2013, 08:34

Related: Scientific Maths Library - Functions for infinite calculation and precision
Writes at Dev Letters

Clipjump Clipboard Manager : More Scripts (updated 2019)

Image
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: Maths

11 Oct 2013, 09:00

Please remove the spoilers and only use code tags.
The 3D code is MUCH better formatted. Though, the (rotation) formulas are not valid.
Last edited by strobo on 27 Oct 2013, 04:45, edited 1 time in total.
User avatar
smorgasbord
Posts: 490
Joined: 30 Sep 2013, 09:34

Re: Maths

11 Oct 2013, 11:04

@Avi thanks for the link :)

@strobo :( if it is wrong, i shall change it and mark it as edited "as advised by strobo" later :)

thanks guys for guiding me :)
John ... you working ?

Return to “Other Utilities & Resources”

Who is online

Users browsing this forum: No registered users and 3 guests