#Python 3.5, 97 bytes
Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if math.gcd(a,i)<2<a<b==i:print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
#Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if math.gcd(a,i)<2<a<b==i:print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if math.gcd(a,i)<2<a<b==i:print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
- 23.6k
- 7
- 66
- 142
#Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b= c+=2;b=(c*c-a*a)**.5;i=int(b)
if if i==b>a>2>mathmath.gcd(a,i)<2<a<b==i:print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
#Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
#Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if math.gcd(a,i)<2<a<b==i:print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
#Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if mathi==b>a>2>math.gcd(a,i)<2<a<b==i:print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c
#Python 3.5, 97 bytes
Wrong output after 28455997
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if math.gcd(a,i)<2<a<b==i:print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
#Python 3.5, 97 bytes
Wrong output after 28455997
, because of the limits of the floating point data type. The sqrt
function isn't good enough, but if the precision was magically increased, it'd work.
Pretty simple to understand. Incrementing c
by two instead of one cuts the runtime in half, and only odd numbers need to be checked anyway, because the elements are always odd.
import math
c=a=3
while 1:
c+=2;b=(c*c-a*a)**.5;i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
The program cannot be run on Ideone, because Ideone uses Python 3.4
For output to stay accurate longer, I'd have to use decimal
:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b)
if i==b>a>2>math.gcd(a,i):print(a);a=c
To stay accurate indefinitely, I could do something horrid like this (increasing the precision required every single iteration:
import math
from decimal import*
c=a=3
while 1:
c+=2;b=Decimal(c*c-a*a).sqrt();i=int(b);getcontext().prec+=1
if i==b>a>2>math.gcd(a,i):print(a);a=c