If I were teaching this I would first build some terms of the series
manually.

Put on the board (or in a J session displayed on a screen in front of the
class):
  1 1
Ask the class what is the sum of the last two numbers. Hopefully, someone
says "2". Then write "2" after the numbers on the board.
  1 1 2
Ask again what the sum of the last two digits is. Answer: "3"
  1 1 2 3

Repeat a couple of more times getting something like the following and give
it a name:
  y=:1 1 2 3 5 8
This demonstrates what the series is and how to build it.
Now ask the class how to get the last two digits of y. (This is assuming
you have already introduced some J expressions like {. and +/ to the class
earlier.) In J that would be:
  _2{.y
5 8
Now ask how to add the digits in J:
  +/5 8

Then put it together:
  +/_2{.y
13

Then concatenate it to the list built so far:
  y,+/_2{.y
1 1 2 3 5 8 13

Now define a verb to do this, maybe called "f". Simply wrap what you have
above giving:
  f =: 3 : 'y,+/_2{.y'
If you are doing this on a computer it would be easy to simply add the
characters around the expression already used.

Then go back to the beginning:
  f 1 1
1 1 2

Then add an "f":
  f f 1 1
1 1 2 3

And repeat for a while to something like:
  f f f f f 1 1
1 1 2 3 5 8 13

  power=:2 : 'v^:m y' NB. To repeat verb v m times
A conjunction "power", which you don't have to explain how it works to the
class, simply have it already defined.

Now use it with f:
  f 1 1
1 1 2
  1 power f 1 1
1 1 2
  2 power f 1 1
1 1 2 3
  5 power f 1 1
1 1 2 3 5 8 13
  12 power f 1 1
1 1 2 3 5 8 13 21 34 55 89 144 233 377

It might be fun to ask them what the 100th fibonacci number is.
  {:98 power f 1 1x
354224848179261915075
Then explain that since you started with 2 terms already you only needed to
do it 98 more times.


Okay, so this is not how to program in the tradition of C or whatever, but
it is J-like and should be easy for students to see what's happening. A way
for them to approach solving problems themselves by testing as they go.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to