Author Topic: Praying Pythagorean triples  (Read 8490 times)

jbk

  • Guest
Re: Praying Pythagorean triples
« Reply #15 on: January 22, 2016, 10:49:32 PM »
that's a very fast algorithm, here's the python equivalent
Code: [Select]
# 100000 Pray Pyth Tri using sbmeTW method.txt  for Python very modified for timed tests 2016-01-22

import time
start = time.time()
a=6 ;b=5;c=1;s=5
for p in range(100000):
    s=(a*b)-c
    c=b;b=s
   
end = time.time()-start
print c
cs = str(c)
print len(cs), "digits"
print end, "seconds"
76556 digits
1.43 seconds
« Last Edit: January 23, 2016, 04:42:19 PM by jbk »

B+

  • Guest
Re: Praying Pythagorean triples
« Reply #16 on: January 23, 2016, 12:21:14 AM »
Hi jbk,

I am starting to suspect your machine, is what? a 486  ;)

I would think Python would be at least be comparable in times to JB and more likely to be faster like Tomaaz results.

EDIT:

Hi Tomaaz, I tried to copy your 1000th PT to JB forum, I thought I broke my browser!
« Last Edit: January 23, 2016, 02:13:10 AM by B+ »

Tomaaz

  • Guest
Re: Praying Pythagorean triples
« Reply #17 on: January 23, 2016, 09:05:42 AM »
I am starting to suspect your machine, is what? a 486  ;)
I would think Python would be at least be comparable in times to JB and more likely to be faster like Tomaaz results.

Do you realize that this program is calculating 100000 numbers and the final one is more than 70000 digits long? That's pretty fast.  Also, the program comes from a year 2106. I'm pretty sure that folks there have much faster computers and they don't care that much about optimization. ;D

Hi Tomaaz, I tried to copy your 1000th PT to JB forum, I thought I broke my browser!

 ;D Don't try to copy the 7000 digits long. It will destroy your machine probably. And the 70000 digits long may take down the whole Internet. ;D
« Last Edit: January 23, 2016, 09:08:33 AM by Tomaaz »

jbk

  • Guest
Re: Praying Pythagorean triples
« Reply #18 on: January 23, 2016, 04:45:47 PM »
Also, the program comes from a year 2106. I'm pretty sure that folks there have much faster computers and they don't care that much about optimization. ;D
;D
I copied and pasted from B+ post, hadn't noticed.

B+

  • Guest
Re: Praying Pythagorean triples
« Reply #19 on: January 23, 2016, 05:29:05 PM »
I am starting to suspect your machine, is what? a 486  ;)
I would think Python would be at least be comparable in times to JB and more likely to be faster like Tomaaz results.

Do you realize that this program is calculating 100000 numbers and the final one is more than 70000 digits long? That's pretty fast.  Also, the program comes from a year 2106. I'm pretty sure that folks there have much faster computers and they don't care that much about optimization. ;D

Hi Tomaaz, I tried to copy your 1000th PT to JB forum, I thought I broke my browser!

 ;D Don't try to copy the 7000 digits long. It will destroy your machine probably. And the 70000 digits long may take down the whole Internet. ;D

 :-[  Wow, I am not so sharp after supper, I missed the part where jbk had changed the Pray PT count, ehh... Python code everything is in the wrong place except where it isn't. No, I did not realize jbk was calculating so many Pray PTs, I was still working on paradigm of taking 77 secs for 100 Pray PT which I probably got wrong too.

Yes, the year was typo, supposed to be 1206, the secret is out now.   :-X

Tomaaz

  • Guest
Re: Praying Pythagorean triples
« Reply #20 on: January 23, 2016, 05:40:14 PM »
Yes, the year was typo, supposed to be 1206, the secret is out now.   :-X

Wow! I knew BASIC was old, but 1206? BTW Fantastic backward compatibility!  ;D

B+

  • Guest
Re: Praying Pythagorean triples
« Reply #21 on: January 23, 2016, 05:55:04 PM »
Yes, the year was typo, supposed to be 1206, poor Louis, just lost his wife.   :-X

Was the 77 sec thing straightened out, it still looks like 100 Pray PTs in the code of that reply? Even 77ms might be a long time with numbers you guys are running but it might take some time for Python to get started on anything. Oh, the precision was 100,000 eeh... was it the precision or a mistake with units (or both?)

B+

  • Guest
Re: Praying Pythagorean triples
« Reply #22 on: January 23, 2016, 06:01:17 PM »
Yes, the year was typo, supposed to be 1206, the secret is out now.   :-X

Wow! I knew BASIC was old, but 1206? BTW Fantastic backward compatibility!  ;D

BASIC the PL? or basic the principle?


Tomaaz

  • Guest
Re: Praying Pythagorean triples
« Reply #23 on: January 23, 2016, 06:03:49 PM »
Was the 77 sec thing straightened out...

There was never 77 sec. on my computer, so I can only guess and my guess is:

1. Precision
2. Overheated CPU
3. Both

:)

Tomaaz

  • Guest
Re: Praying Pythagorean triples
« Reply #24 on: January 23, 2016, 11:00:01 PM »
Ruby version:

Code: [Select]
a, b, c, s = 6, 5, 1, 5
100.times {s = a * b - c; c, b = b, s; puts c}

jbk, have you tried to write it in Julia? It seems to be good choice for tasks like that.

jbk

  • Guest
Re: Praying Pythagorean triples
« Reply #25 on: January 24, 2016, 02:40:36 AM »
Hi Tomaaz
I have only recently started with Julia, so the following is a quick and dirty solution, unlike your Ruby version.

Code: [Select]
function pytriple(n)
a=BigInt(6) ;b=BigInt(5);c=BigInt(1);s=BigInt(5)
for p = 1:n
s=(a*b)-c
c=b;b=s
end
print(c)
end

first run
tic();pytriple(100000);toc()
1.22063574 seconds

thereafter about 1.13517414 seconds
« Last Edit: January 24, 2016, 03:39:44 AM by jbk »

Tomaaz

  • Guest
Re: Praying Pythagorean triples
« Reply #26 on: February 13, 2016, 11:20:55 AM »
Pike

Code: [Select]
void main() {
int a, b, c, s, x;
a = 6;
b = 5;
c = 1;
s = 5;
for(x = 0; x < 100; x++) {
s = a * b - c;
c = b;
b = s;
write("%d\n", c);
}
Stdio.Readline()->read();
}