TheAlgorithms / Python

All Algorithms implemented in Python

Home Page:https://the-algorithms.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New Algorithm - Pythagoras Generator

Naman-Singla777 opened this issue · comments

commented

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!

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

I can complete it. Please assign it to me

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 can complete this Pythagoras Generator, Please assign this to me
I am new to opensource and I am willing to learn and contribute.

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.

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!

I am new on python

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

"""
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!

commented

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.

Hello,
Can you assign this issue to me?