From 5c3f0ccb9ad2a190b20efad4b0682e1b9829c0a5 Mon Sep 17 00:00:00 2001 From: starkpa <49409857+starkpa@users.noreply.github.com> Date: Mon, 3 Jun 2019 07:35:07 +0530 Subject: [PATCH] Update primer.py Solution for C-1.27 problem --- primer.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/primer.py b/primer.py index f862866..6208eb1 100644 --- a/primer.py +++ b/primer.py @@ -301,5 +301,29 @@ def dot_product(a, b): print(count) +#C-1.27 +#InSection 1.8, weprovided three different implementations of agenerator that computes factors of a given integer. +#The third of those implementations, from page 41, was the most efficient, but we noted that it did not yield the factors inincreasing order. +#Modify the generator s othat it reports factors in increasing order, while maintaining its general performance advantages. + +#Not sure this preserves the general performance or not. + +input =10 + +def factorial_check(n): + k=1 + while k*k < n: + if n % k == 0: + yield k + yield n // k + k+=1 + if k*k == n: + yield k + +print(sorted(factorial_check(input))) + +#for printing normally(Unsorted manner) +#for i in factorial_check(n): +# print(i)