Python icon indicating copy to clipboard operation
Python copied to clipboard

New Algorithm - Pythagoras Generator

Open Naman-Singla777 opened this issue 3 years ago • 11 comments

I've written an algorithm which when given input, will return you a pythagorean triplet including that number. It works for EVERY number (provided n > 2). Do let me know if you guys are interested, I'll make a PR with my code attached!

Naman-Singla777 avatar Sep 21 '21 00:09 Naman-Singla777

I am new to open-source.Please assign me.

CoderDaicho avatar Oct 01 '21 02:10 CoderDaicho

I can complete it. Please assign it to me

rutujak24 avatar Oct 01 '21 02:10 rutujak24

Bro, so you are saying you have written pythagoras genrator. And you will make PR. Then why you are listing this as issue. Please tell me . I am new to open source, i dont dont how this works

abhijitgawai avatar Oct 01 '21 10:10 abhijitgawai

I can complete this Pythagoras Generator, Please assign this to me I am new to opensource and I am willing to learn and contribute.

driptanil avatar Oct 01 '21 13:10 driptanil

Bro, so you are saying you have written pythagoras genrator. And you will make PR. Then why you are listing this as issue. Please tell me . I am new to open source, i dont dont how this works

I think @Naman-Singla777 is asking the maintainers to accept his proposal so he can make a pullrequest. He is not asking anyone to collaborate with him or solve this issue.

k-stz avatar Oct 02 '21 09:10 k-stz

Bro, so you are saying you have written pythagoras genrator. And you will make PR. Then why you are listing this as issue. Please tell me . I am new to open source, i dont dont how this works

I think @Naman-Singla777 is asking the maintainers to accept his proposal so he can make a pullrequest. He is not asking anyone to collaborate with him or solve this issue.

So where is his proposal? I can't find anything here!

SadeghPouriyanZadeh avatar Dec 14 '21 07:12 SadeghPouriyanZadeh

I am new on python

rajadhruwe-ui avatar Jan 09 '22 13:01 rajadhruwe-ui

I can do this work! I love python. I am new to open source I am a college student pursuing CSE

AK16092003 avatar May 06 '22 14:05 AK16092003

"""
Description: triplet(n) function displays all the possible pythagorean triplets where one of the number is n

>>> triplet(5)
5 12 13
3 4 5
Count:  2
>>> triplet(17)
17 144 145
8 15 17
Count:  2
>>> triplet(35)
35 84 91
35 120 125
12 35 37
35 612 613
21 28 35
Count:  5
>>> triplet(31)
31 480 481
Count:  1
>>> triplet(30)
30 40 50
30 224 226
16 30 34
30 72 78
18 24 30
Count:  5
>>>

"""

def triplet(n):
    ans = set()
    for i in range(1,int(n)+1):                              # triplets where a^2 + n^2 = b^2
        if (n*n)%i == 0:
            c = i
            d = (n*n)//i
            a = (c+d)/2
            b = (d-c)/2
            if a%1 == 0 and b%1 == 0 and a>0 and b>0:
                ans.add(tuple(sorted([a,b,n])))

                
    for a in range(1 , n+1):                                # triplets where a^2 + b^2 = n^2
        b = (n**2 - a**2)**0.5
        if b%1 == 0 and b>0:
            ans.add(tuple(sorted([a,b,n])))
    c = 0
    for (x,y,z) in ans:
        print(int(x) , int(y)  , int(z))
        c += 1
    print("Count: ",c)
    

I've written an algorithm which when given input, will return you a Pythagorean triplet including that number. It works for EVERY number (provided n > 2). Do let me know if you guys are interested, I'll make a PR with my code attached!

AK16092003 avatar May 06 '22 15:05 AK16092003

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 10 '22 15:07 stale[bot]

Hello, Can you assign this issue to me?

nfarhaan avatar Oct 11 '22 21:10 nfarhaan