Exercise #3

A credit-card supplier -- let's call it ``Blovmark Banking Systems'' -- wants to choose the numbering system for its new line of NeodymiumCards in such a way that it is easy for a machine to distinguish a valid number from a fake. A designer at BBS has proposed the following test: A number is valid if it is evenly divisible by 13, but not by 2, 3, 5, 7, or 11. For instance, the number 1000051 is valid, but the number 1000571 is not (since 1000571 = 11 * 90961).

Write and test a Scheme procedure called valid? that determines whether a given integer is a valid number by this test. (Hint: There is a predefined Scheme procedure, remainder, that divides one integer by another and returns the remainder. For instance, the value of the call (remainder 37 7) is 2, since 7 goes into 37 five times with 2 left over.)

The marketing division of BBS is concerned that there will not be enough valid numbers under this scheme to accommodate the likely demand. Because of the outmoded design of existing Blovmark card readers, the card numbers are limited to seven digits -- that is, every card number must be in the range from 1000000 to 9999999. The marketers estimate that approximately 180,000 customers will want NeodymiumCards. The question is, are there 180,000 or more distinct integers in the range from 1000000 to 9999999 that are evenly divisible by 13 but not by 2, 3, 5, 7, or 11?

Write and test a Scheme procedure valid-numbers-in-range that tests every integer in a given range and returning a tally of the integers that were found to be valid. The range of integers to be tested should be specified by two parameters, start and finish; your procedure should test every integer that is greater than or equal to start and less than or equal to finish.

After you have confirmed by testing that your valid-numbers-in-range procedure works correctly in a few small cases, answer the marketers' question by determining the number of valid integers in the range from 1000000 to 9999999.

This exercise will be due at 9 a.m. on Monday, February 9.


This document is available on the World Wide Web as

http://www.cs.grinnell.edu/~stone/courses/scheme/exercises/3.xhtml

Validated as XHTML 1.1 by the World Wide Web Consortium Cascading Style Sheet validated by the World Wide Web Consortium

created February 4, 2004
last revised February 23, 2004

John David Stone (stone@cs.grinnell.edu)