[prev] 54 [next]

Generate and Test (cont)

Simple example: checking whether an integer n is prime
  • generate/test all possible factors of n
  • if none of them pass the test  ⇒ n is prime
Generation is straightforward:
  • produce a sequence of all numbers from 2 to n-1
Testing is also straightfoward:
  • check whether next number divides n exactly