SPOT Processor Programming Exercises

Back to SPOT Home Page

Note: These exercises are not in any particular order.

  Concept(s) Difficulty (1-5) Exercise
1 beginning write, jumps,mod 1 Put an random positive integer into C1 and another random one into C2. Determine whether the number in C2 divides the number in C1 evenly and print the result in the following format:

3 in C2 does not divide 7 in C1 evenly.

4 in C2 divides 8 in C1 evenly.
2 looping 1.5 Put a number into C1 and a larger one into C2.  Based on the values in C1 and C2, print out all of the integers in ascending order, starting at the one in C1 and ending just before reaching C2, separated by commas.

WRITE 3,c1
WRITE 7,c2
# the appropriate instructions...

output:
3,4,5,6

3 reading datafiles, using jump-if-eof 1 For each line in the "first" datafile, print out the lastname, firstname.  Result should look like:

Brooks, Peter
Smith, John

4 reading datafiles, arithmetic 1.5 Print out the average age and average grade of the people in the datafile "second".  Remember to skip the first line because it contains only the column headers.  Output should look like (where xx and yy are filled in):

Average age is xx.
Average grade is yy.

5 looping 2 Put a number between 3 and 20 into C1.  Print out that many numbers in the Fibonacci sequence.  For instance, if you put 8 into C1, then the output should be:

1 1 2 3 5 8 13 21

6 gosub/return 3 Create an area of code starting with a label "3k-plus-1" that does the following: first, get the value in C10, then a) print out the value, then b) if the number is even, divide it by 2 and go to step a); otherwise, multiply the number by 3 and add 1, then go to step a).  Do this until the number is equal to 1 and print a newline ("\n") and then RETURN.

You can call this entire procedure with the instruction: GOSUB 3k-plus-1.  Call this subroutine with the starting values from 2 to 10, printing out the starting value each time.  Your output should look like:

2: 2 1
3: 3 10 5 16 8 4 2 1
4: 4 2 1

etc.
10: 10 5 16 8 4 2 1

7 indexed read/write
writing a Collatz (or "3k+1") sequence in reverse
3.5 The sequences in the exercise above (#6) can be called Collatz sequences.  For instance, we see that the sequence associated with the starting number 3 is: 3,10,5,16,8,4,2,1.  We'll call the starting number the "seed".  Put a seed into C1.  Print out the sequence generated from that seed backwards.  For instance, if the seed is 3 then the result would be:
1,2,4,8,16,5,10,3
Make sure that there's no comma at the end.
8 indexed read/write,etc 4 Print out the mean, mode and median of the lottery numbers in the datafile "lottery".
9 indexed read/write, etc. 4.5 The Sieve of Eratosthenes -- a way of finding prime numbers.  Assume that you have written down the numbers 2 through 100 on a sheet of paper.
Step 1: circle the 2 and then cross out every multiple of 2 on the sheet.
Step 2: circle the next number above the 2 that hasn't been crossed out (the 3) and then cross out every multiple of that.
Step 3: circle the next number (above the 3) that hasn't been crossed out (the 5) and then cross out every multiple of that.
Stop when there are no more numbers to cross out or circle.
The circled numbers will be the primes between 2 and 100.

Implement the Sieve of Eratosthenes.  Write an arbitrary number into C1 between 50 and 200.  Using the Sieve, print out all of the primes between 2 and the value of C1.  Use subroutines wherever you can (it will make your job easier).

Creative Commons License
This work is licensed under a Creative Commons License.
All material related to the SPOT processor may be copied freely, however the author must be attributed.