Math Computing Challenge :D

Talk about anything
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Math Computing Challenge :D

18 Jun 2014, 01:31

I heard some of you guys like maths. :)
Thats why i'm here with a little challenge for you today. :D :geek:

Here is the mathematical problem:
Assume that we have a sum called "s" that equals:
Image
(n being every possible integer greater than zero)
Therefore, sum "s" should be an algebraic constant greater than zero.

Your challenge:
Are you able to compute the constant which sum "s" equals, precisely to 100 digits (hint: smartly rounded to 99 decimal places) only by the use of autohotkey?

If you do so, please show your code+result and how long it took to calculate.

Winner with the most efficient way gets glory, honor and 2 cookies. :!:
"Nothing is quieter than a loaded gun." - Heinrich Heine
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: Math Computing Challenge :D

18 Jun 2014, 02:01

Just tried this for fun, seemed that ahk couldn't handle the large floats, so I had to use libraries. But for some reason I got a negative result. I tried with both Avi's scientific maths library as well as Lazslo's long integer library. Both produced the same answer, although Laszlo's computed it much quicker (prob due to MCode). Also, didn't matter whether or not I used the MP_Divide func, still got the same answer, although even slower.

Code: Select all

s = -207151913161435000000000000000000000000000000000000000000000000000000000000000000000000000000.000000

Code: Select all


#include Maths.ahk    ;// https://github.com/aviaryan/autohotkey-scripts/blob/master/Functions/Maths.ahk

s := 0.0

while (StrLen(s) < 100)
{
   i := A_Index
   s += (SM_fact(i)/((i+1)**i))
   ;s += SM_Divide(SM_fact(i), (i+1)**i, 99)
}

msgbox s=%s%
;Clipboard := s
return

Last edited by guest3456 on 18 Jun 2014, 02:11, edited 1 time in total.

Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 02:08

Well, you made a simple mistake. Avis Lib actually is a good choice, but think again, where large integers in the formula are going to appear and you'll notice something. ;)
"Nothing is quieter than a loaded gun." - Heinrich Heine
guest3456
Posts: 3454
Joined: 09 Oct 2013, 10:31

Re: Math Computing Challenge :D

18 Jun 2014, 02:14

can't be fkd, someone smarter will solve it

User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 02:16

I see a problem in your code here:
(i+1)**i
Recommends AHK Studio
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 02:22

+1
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 02:39

0.86980432098765432098765432098765432098765432098765432098765432098765432098765432098765432098765432097
I am not sure though since it is difficult to tell if the nr. will still change or not.
This is my try:

Code: Select all

#include Maths.ahk    ;// https://github.com/aviaryan/autohotkey-scripts/blob/master/Functions/Maths.ahk
SetBatchlines,-1
s := 0
i:= 0

while (strlen(s)<100||(substr(olds,3,97)!=substr(s,3,97))||(substr(oldolds,3,97)!=substr(s,3,97))(substr(oldoldolds,3,97)!=substr(s,3,97)))
{
   i := SM_Add(i, 1)
   ;~ s += (SM_fact(i)/((i+1)**i))
   oldoldolds:=oldolds
   oldolds:=olds
   olds:=s
   s:=SM_Add(s, SM_Divide(SM_fact(i), SM_Pow(SM_Add(i, 1),i), 100))
}

msgbox s=%s%
Clipboard := s
return
It uses guest's code as a basis.

This is the result if you use 200 iterations:
0.87985386217525853348630614507096003881987340048928990482961766912229638666121421136175444468678831036107444534186281838788136229268292783649361640007316052957179562523544381769477304709
Recommends AHK Studio
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 03:04

Your result is slightly off of mine by approx. -0.01 but tbh i don't know why since i'm basically using the same technique as you.
But still, i'm sure yours is wrong, sorry. :D
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 03:06

Well i'm pretty sure that mine is too because I don't check properly if it stays the same.
my result after 200 iterations also looks differently.
Recommends AHK Studio
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 03:13

Well, thought about checking each result for each single n? ;)
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 03:15

Yeah didn't see anything.
Recommends AHK Studio
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 04:20

Here is my code in a faster version:

Code: Select all

#include Maths.ahk    ;// https://github.com/aviaryan/autohotkey-scripts/blob/master/Functions/Maths.ahk
SetBatchlines,-1

s := 0
i := 0

while (rep<20)
{
	i := SM_Add(i, 1)
	olds:=s
	s:=SM_Add(s, SM_Divide(SM_fact(i), SM_Pow(SM_Add(i, 1),i), 300))
	if (olds=s)
		rep++
	else
		rep:=0
}

msgbox s=%s%
Clipboard := s
return
Recommends AHK Studio
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 05:28

Do you still get the same result?
i think this one should be more precisely, bu i just realized you are missing the most important point! of course i won't simply tell you ;) but look at the division. :D
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 06:19

Better now?
Recommends AHK Studio
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: Math Computing Challenge :D

18 Jun 2014, 13:22

Sure, what is the result you get?
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Math Computing Challenge :D

18 Mar 2017, 23:31

Btw does anyone have the image for this:
http://kubli-verlag.com/challengesum.png
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Off-topic Discussion”

Who is online

Users browsing this forum: No registered users and 73 guests