[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I'm always ready to help a beginner, but this is the first time that it takes so much effort. It would be easier if you started with the simple problems you could handle. Even in simple cases you would be able to get tips that you can understand and gradua

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-22 Thread Ananthakrishnan
Ananthakrishnan added the comment: >>Sorry, Ananthakrishnan, but I think this problem is too difficult to you. >>Adding math.lcm() taken 2 weeks and produced 200 messages. It is simpler to >>implement this feature myself to me. I'm a beginner.Not everyone is perfect at begenning. I am start

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-22 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- pull_requests: +17970 pull_request: https://github.com/python/cpython/pull/18604 ___ Python tracker ___

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Sorry, Ananthakrishnan, but I think this problem is too difficult to you. Adding math.lcm() taken 2 weeks and produced 200 messages. It is simpler to implement this feature myself to me. -- ___ Python tracker <

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-21 Thread Ananthakrishnan
Change by Ananthakrishnan : -- keywords: +patch pull_requests: +17959 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18590 ___ Python tracker ___

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-21 Thread Ananthakrishnan
Ananthakrishnan added the comment: Thanks for the hint.Made changes. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Un

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-21 Thread Ananthakrishnan
Ananthakrishnan added the comment: Yes I know. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-20 Thread Mark Dickinson
Mark Dickinson added the comment: @Ananthakrishnan: Do you know how arrays and pointers work in C? -- ___ Python tracker ___ ___ Py

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-20 Thread Ananthakrishnan
Ananthakrishnan added the comment: This is my code for math.gcd: static PyObject * math_gcd(PyObject *module, PyObject *args, Py_ssize_t n) { PyObject *g = 0, *item, *in; Py_ssize_t i; for (i = 0; i < n; i++) { item = args[i]; in = PyNumber_Index(item);

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-20 Thread Mark Dickinson
Mark Dickinson added the comment: @Ananthakrishnan: Sure, go ahead. Let's make the process a bit more streamlined than last time around: see if you can put together a PR that passes all the CI checks before asking for review. If you get stuck, make a work-in-progress PR and ask for help in a

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-18 Thread Ananthakrishnan
Ananthakrishnan added the comment: Can I put together a PR for this issue? -- ___ Python tracker ___ ___ Python-bugs-list mailing l

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-17 Thread Bernardo Sulzbach
Bernardo Sulzbach added the comment: I think this might make sense because gcd() could have some optimizations for n > 2, such as sorting the numbers and starting by the smallest elements. However, I don't think gcd() and lcm() with more than two arguments are frequent use cases. --

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-17 Thread Ananthakrishnan
Ananthakrishnan added the comment: It should take variable number of positional arguments. it should return: >>math.gcd() 0 >>math.gcd(8) 8 >>math.gcd(-8) 8 -- ___ Python tracker

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Dennis Sweeney
Dennis Sweeney added the comment: Correction correction: returning zero preserves the invariant below. from math import gcd as GCD from functools import reduce from itertools import starmap, chain def gcd(*args): return reduce(GCD, args, 0) iterables = [[10, 20, 30], [],

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Dennis Sweeney
Dennis Sweeney added the comment: Correction: gcd(itertools.chain(iterables)) == gcd(*map(gcd, iterables)) -- ___ Python tracker ___ __

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Dennis Sweeney
Dennis Sweeney added the comment: I think the behavior of gcd() == 0 is correct, but it should be documented, because it isn't completely obvious. Arguments for gcd() == 0: - Preserves the invariant gcd(itertools.chain(iterables)) == gcd(itertools.starmap(gcd, iterables)) in the case that s

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Tim Peters
Tim Peters added the comment: This is almost all down to pragmatics for me. For sum() and prod(), if there are only two operands then there are trivial other ways to spell that (+ and *). So it makes most sense for them to accept iterables instead. Essentially, e.g., nobody would ever _wan

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Mark Dickinson
Mark Dickinson added the comment: What's slightly more interesting is the return value for a single argument `a`, where we should be careful to return `abs(a)` rather than simply `a`. -- ___ Python tracker ___

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Mark Dickinson
Mark Dickinson added the comment: > Should it take variable number of positional arguments or a single iterable > argument as max() and min()? Good question: the obvious extension to the current function would be to allow it to take multiple scalar arguments. But I don't much like the mismat

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Python as programming language provides builtin blocks. This is a good example of using functools.reduce(). But if you can provide an algorithm for calculating the GCD and LCM more efficient than sequential applying gcd() and lcm() for two arguments, it wo

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Should it take variable number of positional arguments or a single iterable argument as max() and min()? What should it return for 0 arguments? -- ___ Python tracker ___

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Raymond Hettinger
Raymond Hettinger added the comment: +1 This isn't hard for us to do and may be occasionally useful. -- nosy: +rhettinger, tim.peters ___ Python tracker ___ _

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread SilentGhost
SilentGhost added the comment: You could (should?) use reduce, then: >>> functools.reduce(math.gcd, (6, 30, 40, 60, 20, 40)) 2 -- nosy: +SilentGhost ___ Python tracker ___ __

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Ananthakrishnan
Ananthakrishnan added the comment: It will take more time to write the statement itself and there are chances of getting mistakes as the statement is complicated. -- ___ Python tracker _

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: What problems it will create? -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsub

[issue39648] Update math.gcd() to accept "n" arguments.

2020-02-16 Thread Ananthakrishnan
New submission from Ananthakrishnan : If we have to find the gcd of three or more numbers, now we should use gcd(a, gcd(b, gcd(c, gcd(d, e) which will create lot of problems. math.gcd should take "n" number of arguments,like: gcd(a,b,c,) gcd(4,6,8)//returns 2 gcd(2,5,8,6)//re