Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions primer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)