HICCUP

From Wikiid
Revision as of 08:49, 5 August 2015 by SteveBaker (Talk | contribs) (Work to do before Starting SPARK)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Hiccup - Introducing Computer Programming to Little Kids

by Steve Baker.

Introduction for the Teacher

This work is designed to teach very young children something that most adults never learn. How a computer works and how to program it. We do this without the need to use a real computer.

This is achieved by having a group of children act out the various parts of an imaginary computer called SPARK (Small Programs And Real Kids). SPARK is made from odds and ends that you might find in a classroom like matchboxes, 3x5 file cards and a half dozen children. A calculator might be a useful accessory - but purists may want to omit it if the class has some children with sufficiently good arithmetic skills.

The activity will require simple reading skills, some basic math and a lot of enthusiasm.

The SPARK computer can run real computer programs written in a special programming language called 'HICCUP' which is quite like several real computer languages. SPARK computers run HICCUP programs - VERY SLOWLY. I present a couple of suitable programs in this book - but you can write more of your own. If your kids get into writing HICCUP then you can use a real computer to run them at a decent speed (THAT IMPLIES FORMALIZING HICCUP ENOUGH TO ENABLE ME TO WRITE A SIMPLE PARSER/INTERPRETER). Sizeable HICCUP programs can do real work and be useful (but not when run on SPARK because the kids get bored and make lots of mistakes).

The basic SPARK computer is very simple - but you can easily extend it with more kids - and add peripherals like a printer, colour graphics - and even a Robot.

Why Teach Programming? (An Aside)

Computers are amazing machines - whilst they may not have made as much difference to people as some other machines (The car, the plow, the flint knife), they are undoubtedly the most astounding.

What is surprising is that although a computer is really a fairly simple device, hardly anyone (outside of computer professionals) has the faintest idea of how a computer actually works. People are taught some incredibly low level stuff (Binary arithmetic) and some incredibly high level stuff (How to Surf the Web, How to Word-Process) - but hardly anyone understands the all important part in between.

Computer programming is a very important thing to teach children. It is hard to teach a kid the equations of motion - not because those equations are particularly hard - but because they appear to have absolutely no relevance to real life. When did YOU last need to use those equations in your day-to-day life? Have you EVER needed those equations in day-to-day life?

Think about this though - if you are trying to write a video game (something kids DO identify with) - and you want your character to jump over an obstacle in a realistic manner - you need to know the equations of motion! The idea of building virtual worlds in the computer is appealing - but forces kids to confront the mathematics of the real world. The computer can't do anything unless you tell it how - there is no way to bypass it. You HAVE to use math.

Well, HICCUP isn't going to do all of that - but it's a good start. It will certainly get everyone's enthusiasm going - and could lead into a formal programming course using a computer programming language like LOGO or BASIC.

Work to do before Starting SPARK

First, you need to get the kids thinking about what a computer is.

Here are some questions to ask - and what I think the answers are:

Are computers smart?
Well, there are computers that can fly a plane or drive a car - there are computers that can play chess better than any human being alive today. On the other hand, they sometimes make incredibly stupid mistakes like sending you a bill for no dollars and no cents and demanding that you pay it immediately OR ELSE!
Do computers make mistakes?
They do - but very rarely. Computers are by far the most reliable machines that have ever been built. An average car would be unlikely to go for more than 100,000 miles without something on it breaking. At 50mph, that is 120,000 minutes. If the engine runs at 5,000rpm, it does about 600 million operations before it breaks. A computer has to do 600 million operations every SECOND without making a single mistake for years at a time. You often hear stories about computers making mistakes - but the mistake is almost always in the programs that people write for the computer to tell it what to do.
Are computers good at numbers?
Well, how about this - computers don't know all the numbers 0 through 9. They only really understand 0 and 1. This makes counting a bit difficult - try it. ONE, TWO - Oh, no, it can't do TWO can it? - only zeros and ones, what's the next number it could do then? 3,4,5,6,7,8,9 - no. The next number it can do is TEN! OK, let's try again. ONE, TEN!, ELEVEN, ...uh... ONE-HUNDRED!, ONE-HUNDRED-ONE, ONE-HUNDRED-TEN, ONE-HUNDRED-ELEVEN, ...oh-oh...ONE-THOUSAND!?! Try counting some objects in 'binary numbers'. It would be hard to work with computers if they counted like that all the time - so one of the first things we write programs for is to teach them to use ALL the numbers when they talk to us. Once we do that, we can talk to the computer using all the numbers - and it'll change them into zeros and ones so it can understand us. It will even change the zeros and ones back into ordinary numbers so that we can understand what the computer is telling us.
Can computers do anything else apart from just numbers?
No - not really. If the computer wants to use letters or make pictures or sounds, it has to use numbers for all those things. It could do letters by making '1' be 'A', '2' be 'B, '3' be 'C' and so on up to '26' for 'Z'. Real computers use '65' for 'A', '66' for 'B' and so on - that's to leave enough spare numbers for all the other funny squiggles that computers need like '#' and '@'. This is called 'ASCII' (American Standard Code for Information Interchange). You can try writing your name using numbers. (Interesting side-topic about secret codes here too. Write a message, turn it into numbers, add something to all the numbers and then turn it back into letters again. For a computer, all letters are "codes" that it has to decode) Pictures can also be turned into numbers. Colour your picture on squared paper, then turn each square (A picture element or 'pixel') into a number using '1' for Red, '2' for Green, etc. You can turn the numbers back into a picture again by using a box of crayons with the right numbers written on each crayon. Draw a simple picture on a 10x10 grid, code it into a long list of 100 numbers and see if anyone can decode it. What happens if you miss out one

of the numbers near the beginning?

What can a computer DO?
Not Much: All it can do is follow a set of rules called a 'program'. Computers don't do ANYTHING without a program.
How fast is a computer?
When we run HICCUP programs on SPARK, most children never manage more than one instruction every ten seconds - a 2GHz PC such as you might have in your home or classroom is about 20,000,000,000 times faster than SPARK. That sounds pretty fast - but there are still things that humans can do faster than a computer. Recognising the face of someone you know would be a good example. Computers have been designed that can do that, but they take several seconds to do it - something that the human brain can do in a tiny fraction of a second.
How many computers does your family own?
One? Maybe two? Well, I bet there is at least one computer in your family car, another in the microwave, another in your TV and probably another one in the remote control, at least one in your DVD player, maybe one in your Air Conditioning controller, every pocket calculator or digital watch has a computer inside. Video games and cellphones are computers too. Even the big box you call "a computer" probably has three or four smaller computers inside it. Most families own a dozen or more computers without even knowing it. Think how hard it would be to go through a whole day without using a computer of some kind.

Building SPARK

SPARK is made from a number of separate parts - each one manned by either one or two kids. In order for HICCUP programs to 'run' correctly, the kids mustn't make even one mistake! Fortunately, the HICCUP language makes it quite hard for a mistake to happen - but it might be better to have two kids running each part so they can check up on each other.

The Parts

Each part is manned by a child who has to follow simple instructions given to them by one of the other children. It might be nice if each child wore a paper hat with the name of their part written on it.

Between 'runs' of a HICCUP program, it's a good idea to change the jobs of each of the children so they all get a turn at each of the jobs.

The User

This isn't strictly a part of SPARK - but someone has to actually use the SPARK computer to type in data and to respond to output from the screen. It might seem logical for the teacher to be the user - but that's probably not a good idea - we need someone 'in the know' to try to catch mistakes that the kids may make as the program is running.

The Memory

SPARK's memory consists of a number of small boxes (matchboxes would be ideal), each clearly labelled with a letter of the alphabet starting at 'A'. Most SPARK programs will need only four or five matchboxes, but some programs might need more. The 'memory' probably ought to have around 16 matchboxes just to get across the general idea. Adding more matchboxes is a 'Memory Upgrade' - real PC's with 16 Megabytes of memory have (in effect) 16 million matchboxes. SPARK is a VERY low tech computer.

The child who is 'MEMORY' should have a pencil and a pile of small paper squares (large enough to write a number on - but small enough to put into a matchbox - PostIt notes will do quite well).

Each box can only contain one number. If MEMORY is asked to put a number into a box that already has one, then throw the older number away first.

The Math Processor

The SPARK's math processor (called an 'Arithmetic/Logic unit' or ALU in a real computer) is just a person who does simple arithmetic when told to do so by one of the other parts of SPARK. It might be worth having a calculator at hand in case the arithmetic gets difficult. Some HICCUP programs need you to do division - and if so, then any fractional part (or 'remainder')of the result should be ignored. This is actually the case in real computers much of the time. 7 / 3 = 2 ! When computers need the fractional part of the result, they have to use techniques similar to the ones people use when doing long-division.

The child who is 'MATH' also needs a supply of paper squares just like we gave to 'MEMORY'.

The Screen

This should either be a cardboard box with a screen-shaped hole in the front that the child can wear on his/her head - or a simple cutout panel that you can prop up with some books.

The person who sits here either reads out (or writes on flash-cards) the output from SPARK so that the USER can 'read' what's on the screen.

SCREEN is told to read out (or write down and flash) everything that anyone shows to him or her.

The Keyboard

The person who is the keyboard should have a number of 'keys' that the USER can push. They should also have a pencil and some more paper squares.

Most HICCUP programs only need a few keys to make them work. A key marked 'YES' and another marked 'NO' is important for most HICCUP programs. The program below needs '<', '>' and '=' keys. )It's quite amusing to use post-it notes with the key characters on them and to stick them onto the keyboard persons forehead, nose, fingers, etc. The USER's typing gets fairly amusing.)

Whenever the USER pushes a key, the KEYBOARD person should write the key down on a paper slip and give it to INSTRUCTOR.

The Instruction Decoder

This is the most important job of all. Each instruction in the HICCUP program is written out on a 3x5 file card with a hole punched in one corner. To avoid getting the all-important instructions getting lost or muddled up, they are best stored on a key-ring.

The INSTRUCTOR is told to read each card in turn - and to do whatever it says.

In a real computer, these instructions are held in the memory - (one file card per matchbox) - but that gets a little confusing so HICCUP programs are stored on a keyring. Real computers also convert each kind of instruction into a different 'code' number - so that programs are themselves just long lists of numbers. Some older programmers remember when you had to type the numbers into the computer - that's why they sometimes talk about 'code' and 'coding' instead of 'program' and 'programming'.

A Sample HICCUP Program

Each instruction is written on a 3x5 file card. Don't get them muddled up!

This is a computer program to play the 'HiLo' game. The rules of 'HiLo' are that one person thinks of a number (bigger than 0 and smaller than 30 in this game), and the other person has to guess that number by asking just five questions.

Most children find it very hard to guess the number with so few questions, so they will be quite suprised to find they can do it right every time when they participate in SPARK. The program can guess numbers from 1 to anything you like - in as few questions as mathematically possible - just change the maximum number written on the very first file card. Beware though that every time you double the maximum number, you add around three to five minutes to the amount of time the children will take to find the answer.

When playing with people, you can let someone guess a number between 1 and a million and try to guess it with just 20 questions.

So, start at the first card...GO!

  1. Tell MEMORY to write '30' on a paper slip and put it into box 'B'.
  2. Tell MEMORY to write '1' on a paper slip and put it into box 'C'.
  3. Show this to SCREEN: "Think of a number bigger than 0 and smaller than"
  4. Tell MEMORY to show the slip in box 'B' to SCREEN
  5. HELLO! (Go on to the next card)
  6. Tell MEMORY to look inside box B, copy the number onto a slip of paper and pass it to MATH.
  7. Tell MEMORY to look inside box C, copy the number onto a slip of paper and pass it to MATH.
  8. Tell MATH to add together the two numbers, write the answer down on a new paper slip.
  9. Tell MATH to divide the new number by two (ignore any remainder).
  10. Tell MATH to write the answer on another slip of paper and pass it to MEMORY.
  11. Tell MEMORY to put the slip into box 'A'.
  12. TYPING! (Go on to the next card)
  13. Show SCREEN this: "Is your number bigger, smaller or the same as "
  14. Tell MEMORY to show the slip in box 'A' to SCREEN
  15. Show SCREEN this: "Please type > for Bigger, < for Smaller or = for same."
  16. Wait for KEYBOARD to pass you a slip of paper.
  17. If it says '<' then skip on to the card marked "SMALLER!" - if not, carry on from here.
  18. If it says '>' then skip on to the card marked "BIGGER!" - if not, carry on from here.
  19. If it says '=' then skip on to the card marked "EQUAL!" - if not, carry on from here.
  20. Go back to the card marked "TYPING!".
  21. BIGGER! (Go on to the next card)
  22. Tell MEMORY to copy the number from box A onto a new slip and to put it into box C (throw away whatever was in box C already).
  23. Go back to the card marked "HELLO!".
  24. SMALLER! (Go on to the next card)
  25. Tell MEMORY to copy the number from box A onto a new slip and to put it into box B (throw away whatever was in box B already).
  26. Go back to the card marked "HELLO!" and go on from there.
  27. EQUAL! (Go on to the next card)
  28. Show SCREEN this: "The number you were thinking of was"
  29. Tell MEMORY to show the slip in 'A' to SCREEN.
  30. Well done. Everybody Stop!

So, what should happen is that the USER thinks of a number - and by asking a number of questions (at most 5 if nobody makes a mistake), the 'computer' should be able to correctly guess the number.

This is interesting. The answer comes out right - but the 'computer' (ie the kids) have no idea how they did it! That's how come a computer can play world class chess - and yet still be a chunk of brainless silicon and copper. All the 'skill' was in the computer program - which in the case of our HICCUP program is just a bunch of inanimate 3x5 file cards.

It takes about 15 HICCUP instruction cards to figure out which question to ask and it could take as many as five questions to solve the problem. It needs a total of around 80 cards to be read to get the problem solved (40 minutes at 30 seconds per card - I DON'T KNOW HOW FAST KIDS WILL BE ABLE TO WORK THESE CARDS - MAYBE FASTER THAN 30 SECONDS WITH PRACTICE). The PC in your classroom could do that in well under a millionth of a second.

How long is a millionth of a second? Well, if you stood at one end of the school holding a flashlight, and turned the flashlight on at the same instant the computer started to run the program, the light from the flashlight would not have reached the other end of the school by the time the computer had finished working on the problem.

I estimate that it could take a half hour to run this HICCUP program on a typical SPARK computer. If you want to cut it shorter than that then CHEAT! Pick an initial number that the program will guess more quickly. Alternatively, you could cut some time by reducing the initial value in box 'B' to 16 - although that's a lot less effective as a demo and probably only saves about 5 minutes. Here is a table of numbers and the number of guesses the program should need to get to that number (assuming 'B' is 30 as above):

Your NumberNumber of Guesses
1
5
2
4
3
5
4
3
5
5
6
4
7
5
8
2
9
4
10
5
11
3
12
5
13
4
14
5
15
1
16
4
17
5
18
3
19
5
20
4
21
5
22
2
23
5
24
4
25
5
26
3
27
5
28
4
29
5

Written in a more conventional programming language (like 'C'), the HiLo game program looks like this:


#include <stdio.h>

void main ()
{
  int A ;
  int B = 30 ;
  int C =  1 ;

  printf ( "Think of a number bigger than 0 and smaller than %d\n", B ) ;

  while ( 1 )
  {
    A = ( B + C ) / 2 ;

    printf ( "Is your number bigger, smaller or the same as %d\n", A ) ;
    printf ( "Please type > for Bigger, < for Smaller or = for same." ) ;

    switch ( getch () )
    {
      case '>' : C = A ; break ;
      case '<' : B = A ; break ;
      case '=' : printf ( "The number you were thinking of was %d\n", A ) ;
		 exit ( 0 ) ;
    }
  }
}

Making Change

What is the smallest number of coins it takes to make change for some amount of money? Write down the number of cents you want to make change for - and put that in MEMORY box 'A' before you start the program running. This program doesn't use the keyboard.

Although the program is twice as long as HiLo, it runs fairly quickly for small amounts of change.

  1. Show this to SCREEN: "The smallest number of coins for"
  2. Tell MEMORY to show the slip in box 'A' to SCREEN
  3. Show this to SCREEN: "cents is:"
  4. Tell MEMORY to write '0' on a paper slip and put it into box 'C'.
  5. QUARTERS! (Go on to the next card)
  6. Tell MEMORY to look inside box A, copy the number onto a slip of paper and pass it to MATH.
  7. Ask MATH if that number is smaller than 25.
  8. If it is then skip on to the card marked "DONE_QUARTERS!" - if not, carry on from here.
  9. Tell MATH to subtract 25 from the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  10. Tell MEMORY to put the slip into box 'A'.
  11. Tell MEMORY to look inside box C, copy the number onto a slip of paper and pass it to MATH.
  12. Tell MATH to add one to the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  13. Tell MEMORY to put the slip into box 'C'.
  14. Go back to the card marked "QUARTERS"
  15. DONE_QUARTERS! (Go on to the next card)
  16. Tell MEMORY to show the slip in box 'C' to SCREEN
  17. Show this to SCREEN: "Quarters and"
  18. Tell MEMORY to write '0' on a paper slip and put it into box 'C'.
  19. DIMES! (Go onto the next card)
  20. Tell MEMORY to look inside box A, copy the number onto a slip of paper and pass it to MATH.
  21. Ask MATH if that number is smaller than 10.
  22. If it is then skip on to the card marked "DONE_DIMES!" - if not, carry on from here.
  23. Tell MATH to subtract 10 from the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  24. Tell MEMORY to put the slip into box 'A'.
  25. Tell MEMORY to look inside box C, copy the number onto a slip of paper and pass it to MATH.
  26. Tell MATH to add one to the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  27. Tell MEMORY to put the slip into box 'C'.
  28. Go back to the card marked "DIMES!"
  29. DONE_DIMES! (Go on to the next card)
  30. Tell MEMORY to show the slip in box 'C' to SCREEN
  31. Show this to SCREEN: "Dimes and"
  32. Tell MEMORY to write '0' on a paper slip and put it into box 'C'.
  33. NICKELS! (Go onto the next card)
  34. Tell MEMORY to look inside box A, copy the number onto a slip of paper and pass it to MATH.
  35. Ask MATH if that number is smaller than 5.
  36. If it is then skip on to the card marked "DONE_NICKELS!" - if not, carry on from here.
  37. Tell MATH to subtract 5 from the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  38. Tell MEMORY to put the slip into box 'A'.
  39. Tell MEMORY to look inside box C, copy the number onto a slip of paper and pass it to MATH.
  40. Tell MATH to add one to the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  41. Tell MEMORY to put the slip into box 'C'.
  42. Go back to the card marked "PENNIES!"
  43. DONE_NICKELS! (Go on to the next card)
  44. Tell MEMORY to show the slip in box 'C' to SCREEN
  45. Show this to SCREEN: "Nickels and"
  46. Tell MEMORY to write '0' on a paper slip and put it into box 'C'.
  47. PENNIES! (Go onto the next card)
  48. Tell MEMORY to look inside box A, copy the number onto a slip of paper and pass it to MATH.
  49. Ask MATH if that number is smaller than 1.
  50. If it is then skip on to the card marked "DONE_PENNIES!" - if not, carry on from here.
  51. Tell MATH to subtract 1 from the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  52. Tell MEMORY to put the slip into box 'A'.
  53. Tell MEMORY to look inside box C, copy the number onto a slip of paper and pass it to MATH.
  54. Tell MATH to add one to the number, to write the answer down on a new slip of paper and pass it to MEMORY.
  55. Tell MEMORY to put the slip into box 'C'.
  56. Go back to the card marked "PENNIES!"
  57. DONE_PENNIES! (Go on to the next card)
  58. Tell MEMORY to show the slip in box 'C' to SCREEN
  59. Show this to SCREEN: "Pennies."
  60. Well done. Everybody Stop!

Here is that one again in 'C':


#include <stdio.h>

int main ()
{
  int A = 122 ;
  int C ;

  printf ( "The smallest number of coins for %d cents is:\n", A ) ;
  C = 0 ; while ( A >= 25 ) { A -= 25 ; C ++ ; }
  print ( "%d Quarters and ", C ) ;
  C = 0 ; while ( A >= 10 ) { A -= 10 ; C ++ ; }
  print ( "%d Dimes and ", C ) ;
  C = 0 ; while ( A >=  5 ) { A -= 25 ; C ++ ; }
  print ( "%d Nickels and ", C ) ;
  C = 0 ; while ( A >=  1 ) { A -= 1 ; C ++ ; }
  print ( "%d Pennies.", C ) ;
}

You can add another child to the team - the ROBOT. This robot has a SPARK computer in it's head that tell it what to do. Add new instructions on file cards to say things like "Tell ROBOT to turn left by 90 degrees", "Tell ROBOT to take 5 steps forward"...and so on. This 'Robot' is now controllable just like the 'Turtle' in LOGO. Kids who have written HICCUP programs to drive the robot will be well placed to slip into LOGO programming.

Once the children have the idea of how the HICCUP setup works, they can probably work in pairs, one playing the robot and the other one running the program. When children write LOGO programs, they have to learn how to 'Play Turtle' in order to imagine what their program will do when they are in the process of writing it - and also in order to see what goes wrong when their programs have bugs in them.

A DEEP Conclusion

The in 1997, the computer 'DEEP BLUE' beat Kasparov - who was the best chess player in the whole world at the time. (Arguably, he remains the best chess player who ever lived). If we rewrote DEEP BLUE's program in HICCUP (which would be quite easy to do) then SPARK could beat Kasparov. But hold on. SPARK is just a handful of school children following some simple rules. The kids might not even know the rules of chess.

Could six kids who don't play chess really beat Kasparov?

The answer is a conditional YES!

Our kids could play world class chess and beat the best chess player in the world if they had enough time and a lot of matchboxes. The number of matchboxes needed would cover several acres of land - and it's doubtful that the kids would manage to read enough HICCUP instructions to work out their first move before they graduated from college - but that's not really the point - in theory, they could do it. So, we must conclude that the thing that beat Kasparov wasn't the super-powerful IBM computer, it was the SOFTWARE that ran on the computer.

Aside: Deep Blue can probably run though 10,000,000,000 instructions in

a second, and probably took 10 seconds working out what move it should play. If SPARK could run one instruction per second, it would take those kids 10,000 years (working 8 hours a day) to make that first move. If they made one single mistake in all that time then Deep-SPARK's first move might turn out to be "Eat At Joes" instead of "b2-b4".

How did the skills to play chess so well get into the computer? It was in the PROGRAM. How did the skills get into the Program then? Well, some person wrote the program that DEEP BLUE uses. We could explain what happened if that person had all the skills needed to beat Kasparov and just passed them on to the computer.

Well, that can't be so - if he was that good at chess, he would be able to beat Kasparov and we know he can't do that or HE would be the world champion.