The Best of Creative Computing Volume 1 (published 1976)

Page 191 << PREVIOUS >> NEXT Jump to page:
Go to contents Go to thumbnails

Beginning with BASIC (extending a simple program to solve complex problems)

graphic of page


This hands-on guide is for somewhat more proficient students, and is designed to
illustrate some ways of adapting a simple program to more complex uses. It
presents the program as a resource, a given tool to be used for solving a
problem. As an added benefit, students are helped to review and extend their
knowledge of some important mathematical concepts.

A Problem to Solve and a Program to Help:


Find out if 1517 is a prime number. If it is not prime, find at least two


Instead of looking for a table of prime numbers (unfair!) or doing a whole mess
of division problems to look for divisors, and maybe not finding any, use this
simple program:

10 LET A=1517
40 GOTO 20
This program tells the computer to:

[image]Remember the number 1517 (Line 10)
[image]Ask for a number - it will type ? and wait (Line 20)
[image]Divide 1517 by that number (Line 30)
[image]And go back for another divisor (Line 40)
You still have to give the computer numbers to try as divisors, but at least it,
not you, will be doing the work.


Remember the Sieve of Eratosthenes? Even if you don't, do you have to divide
1517 by all the multiples of 2, or just by 2? Now, since there are no other even
primes, why not divide 1517 by only odd numbers after you try 2? Why not leave
out multiples of 3, 5, 7 etc.?


Here are some prime numbers to try as divisors: 2 3 5 7 11 13 17 19 23 29 31 37
41 43...


Change the above program to print:

a) Your name
b) Each division problem as well as its answer
c) Using lines such as LET B=3 and LET B=B+2, all the divisions of 1517 by odd
numbers until you stop the computer with a CTRL/C

The above exercises are merely suggestions for making the computer's
self-sufficiency pay off and helping the student maintain his own private
dialogue with the machine.

A Puzzle For Fun

A warden had eight prisoners in separate cells, arranged in the manner shown

He decided to rearrange the prisoners so their numbers would be in consecutive
order, reading counter-clockwise around the circle, with the center cell left

The warden started by moving a prisoner into the empty cell, then moving the
other prisoners one at a time, always into the cell vacated by the previous
occupant. All but No. 5, who was never moved from his cell.

Prisoners can only be moved to a cell adjacent to their own, i.e., only 7 or 3
could move to the empty cell.

Can you figure out how the warden did it in 17 moves?

[image]36522 5 1 2 7 4 3 6 8

Page 191 << PREVIOUS >> NEXT Jump to page:
Go to contents Go to thumbnails