CISC 260 Lecture Notes - Lecture 7: Prime Number, Prime Factor, Parsing

39 views4 pages

Document Summary

More recursion examples hasfactor: returns true if n is evenly divided hasfactor :: int -> int -> int-> bool hasfactor n l h. | mod n 1 == 0 = true. Preview and lists and list comprehension isprime :: int -> bool isprime n. Where introot n = floor (sqrt fromintegral n) primesless100 :: [int] primesless100 = [n | n int numprimes n. | isprime n = 1 + numprimes (n-1) | otherwise = numprimes (n-1) firstprimegreatereq n = the first prime number >= than n firstprimegreatereq :: int -> int firstprimegreatereq n. | (mod n m == 0) && (isprime m) = m. | otherwise = smallestfactorinrange (m+1) n numfactors1 : number of prime factors of n using "smallest factor" numfactors1 :: int -> int numfactors1 n.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents