home *** CD-ROM | disk | FTP | other *** search
-
-
- "!COCONUT.MSE, 5/25/86, Lee R. Bradley"
-
- 3 B : ~ To speed Pause up under Pascal interpreter
- 1 I : 0 A : 0 R : ~ Initialize loop, abort and display counter variables.
- 0 Y : ~ Assume program trace not desired.
-
- "!!What's your name, my friend? " #N,1; ~ Get the user's name
- "!!Welcome, " #N,2; '!!' ~ Greet him/her.
-
- "!!Want to trace this program's code itself? " #A,1; [
-
- ~ Teach the user how to use the Mouse trace, if they want a trace.
-
- "!!Hit <SPACE BAR> or <RETURN> repeatedly. Press any other key to stop
- the trace. When the marker is under a ?' instruction (read character)
- hit the <SPACE BAR> one more time (so it recognizes the ') and enter a
- character. When the marker is under a ? instruction (read number)
- enter a number. A bit confusing, I know. And when you see the code,
- it gets worse... Everything is stack-oriented.
-
- Ok. Enough instructions. It's all yours, "#N,2; ".!!"
-
- { 1 Y : ] ~ Turn on trace and remember trace is desired (see Pause macro).
-
- ~ Machine configuration code follows
-
- ~ Question #1
-
- K. 'k = [ ~ In the (unlikely) event a KayPro user is re-running this
- "!!Want a scrolling display this time? " #A,1; [ 'm K : ]]
-
- ~ Question #2
-
- K. 'l = [ ~ In the (very unlikely) event a KayPro user is re-re-running this
- "!!Want a true clear screen this time? " #A,1; [ 'k K : ]]
-
- K. 'm = [ 'l K : ] ~ Fix up K's value. Needed to do this to prevent Question
- ~ #2 above from being re-asked. Kludgy, I know.
- ~ Question #0
-
- 'l K. > 'l K. < +
- 'k K. > 'k K. < + * [ ~ If first run
- "!!Running a KayPro, by any chance? " #A,4; [ 'k K : ]]
-
- "!!Want some background? " #A,2; [ ~ Ask Y/N. Pause and clear if Y.
-
- "!Hold on a bit, while I find my notes ..." #P,1000;
- "!Thanks for waiting" '!!' " " #P,1000; #Z;
-
- "! Coconuts and Missionaries
-
- Five missionaries came upon a pile of coconuts one evening on
- their way home from work. !!In fact, missionary #4's name was "
- #N,2;" too. !What a coincidence" '!!' " "
-
- #P,1000;" Anyway, on with the story... " #P,1000;
-
- "!!They decided to split up the pile the next morning and turned in
- for the night. " #P,1000; "
-
- At 1 in the morning, one of the missionaries got up, went out and
- took a look at the pile of coconuts. He split it into 5 equal
- piles, chucked the single extra coconut which was left over to a
- monkey he saw in a tree close by and put his fifth in the trunk
- of his car. He figured the others would never miss what he took.
- One by one, the other four missionaries got up, split the pile
- left by his predecessor into 5 equal piles, took his fifth and
- chucked the single coconut left over to the monkey.!!"
-
- ~ Give the fellow a reasonable amount of time to read the
- ~ story, then query if [s]he needs more time. Give different
- ~ feedback on 1st and 2nd query. Backspace over prompts, with
- ~ sufficient pauses in between.
-
- 1 V : 0 T : 2000 U :
- (
- T. U. + T : ~ Give 'em more time each time
- #P,T.;
- V. 1 = [ "Need more time to read this? " ]
- V. 2 = [ "Still need more time? " ]
- #A,3; ^
- V. 2 = [ " No problem. " ]
- V. 1 = [ 2 V : " Take your time." ]
- #P,600; 53 W : ( W. ^ " " 8 8 !'!' W. 1 - W : )
- )
-
- #Z;
- "In the morning, the remaining pile was split up into exactly five
- equal piles. The monkey didn't get anything (he was stuffed,
- anyway). " #P,1000; "
-
- How many coconuts were there in the beginning for all this to be
- possible?
-
- Hint: We know it has to be a number ending in either a 1 or a 6,
- because only such numbers have the property that if you subtract
- 1 from them, they can be divided exactly by 5, a requirement of
- our story. " #P,2000;"
-
- Let's face it, unless you're a genius, no way are you going to
- guess this thing without a computer. So, when asked, enter a 1 or
- some number that ends in 1 (like 1001). The code which follows
- will try your number, then add 5 to it, try again, and continue
- to add 5 until it comes up with the answer. On my 5 MHz KayPro it
- takes 41 seconds, if it starts with 1, and there's no trace.
- (It used to take 22 seconds, but I've added so many bells and
- whistles to this thing, it now takes a little longer ... ) "
- #P,3000;
- ]
-
- 0 D : ~ Assume progress trace not desired.
- 1000 Q : ~ Just to pause a bit before calculation starts.
-
-
- "!!Want me to trace my progress? " #A,1; [ ~ Ask Y/N
- 1 D :
- "!!Enter a number between 1 and 1000 to control my trace display
- speed, and then press <RETURN>. A 1 will give you a very fast
- trace, a 1000 a very slow trace. Try 50 for starters. " ? P :
- ]
-
- "!!Enter your first guess and then press <RETURN>. Your guess
- should end in a 1 (or 6) or we might be here for a while.
- Press good ol' CTRL-C during the calculation to abort it.
- Your guess please? "? C : "!!Thanks" '!!'
-
- "!!Hmmm.... Let's see, 5 missionaries, monkey gets 1
- after removing 1 and dividing by five... Hmmmm...!!"
-
- #P,Q.; ~ Pause a bit, so user can see you're thinkin' about it.
-
- ~ Main (outer) loop
-
- (
-
- I. ^ ~ While there's still interest...
- #C,C; ~ Compute coconut count.
- A. 0 = [ ~ In the likely event we have not aborted, ask if still interested.
- "!Want to know the next answer? " #A,3; [ ~ Ask Y/N
- "!" 1 I : ~ Reset interest variable back to "interested".
- "!This may take a while.
- !Why don't you grab a" C. 4000 > [ "nother" ] " burger while I work
- on this? !!"
- 0 R :
- #P,Q.; ~ and pause again so user can see message.
- ]]
-
- )
-
- ~ Sign off
-
- "!!If you enjoyed this, " #N,2; ", and want to learn more about
- programming in Mouse (which is what this is written in), send a note
- to me. Who knows, Mouse may become famous yet" '!'!'! !'!'!'
-
- "!!Lee R. Bradley
- Mouse House Software
- 24 East Cedar Street
- Newington, CT 06111
- "
-
- ~ Macros follow
-
- $A ~ Ask Y/N, return 1 if "Y" or "y" entered, 0 otherwise
- ~ Complete answer based on value passed.
-
- ?' w : w. 'y - w. 'Y - * 0 = v : 8 !' v. [
- 1% 1 = [ "Yup." ] 1% 2 = [ "You bet." ] 1% 3 = [ "Uh huh." ]
- 1% 4 = [ "Sure am. Dynamite machine" '!!' ] 1 @ ]
-
- w. 13 = [ 10 !' ] ~ If just carriage return entered, emit line feed.
-
- 1% 1 = [ "Nope." ] 1% 2 = [ "Nah." ] 1% 3 = [ "Uh uh." ]
- 1% 4 = [ "KayPro ? Never heard of it." ] 0 @
-
- $C ~ Do the calculation
-
- D. 0 = [ "!Calculating " ] ~ Say sumthin', just to tell 'em yur there
-
- ~ Main (inner) loop.
-
- (
-
- I. A. 0 = * ^ ~ While answer not found and problem not aborted ...
- 1%. 5 + 1% : ~ Bump guess
- 1%. 32765 > ~ Check to make sure guess still in single precision range
-
- [ "!!Sorry, but I can only do single precision integer arithmetic
- and I'm about to blow my accumulator... Try using a Cray 1. "
- 1 0 I : A : ~ Abort if not.
- ]
-
- A. 0 = [ ~ Only do this if not aborted
- 1%. w : ~ Load work variable with guess
-
- ~ If tracing, show count and success depth. Print new line for each count.
- ~ If we get to missionary #4, feed user his name
- ~ If we get to missionary #5, but fail, ring bell, etc.
- ~ Pause macro will take care of screen clearing based on lines printed.
-
- D. [ R. 1 + R : #P,P.; "!" w. ! ] ~ If tracing, pause and, when
- ~ appropriate, clear screen.
-
- #F,w; [ D. [ 'I 64 - !' w. ! ] ~ Test each missionary and
- #F,w; [ D. [ 'I 64 - !' w. ! ] ~ and show progress
- #F,w; [ D. [ 'I 64 - !' w. ! ] ~ if user asked for a trace.
-
- D. 0 = [ "." ] ~ If not tracing, continue to emit dots to show that
- ~ you're working on it.
-
- #F,w; [ D. [ 'I 64 - !' #N,2; ", you left " w. ! '!!' ]
- #F,w; [ D. [ 'I 64 - !' w. ! ]
-
- w. 5 \ [
- D. [ 7 !' #P,Q.; 7 !' #P,Q.; " Close" '!!' #P,Q.; ]]
- w. 5 \ 0 = [
- 0 I : ] ~ If final count is exactly divisible by 5,
- ~ set I to 0 to stop the loop.
- ]]]]]
- ]
-
- )
-
- A. 0 = [ ~ Announce result, provided you got here without aborting.
- "!!The original pile had " 1%. ! " juicy coconuts in it."
- ]
- @
-
- $F ~ If passed variable's value less 1 is divisible by 5, update
- ~ the variable to hold 4/5 of 1 less than its current value and
- ~ return a 1, else return a 0. This is the real workhorse of this
- ~ program.
-
- 1%. 1 - w : w. 5 \ [ 0 @ ]
- w. 5 / 4 * 1% : 1 @
-
- $N ~ Read (if a 1 passed) / display (if a 2 passed) user's name
-
- 0 w : ~ Initialize subscript into name array
- 26 3 * a : ~ Hard code origin of array. This is plenty deep.
-
- 1% 1 = [ ?' z : ~ If reading name
-
- ( z. a. w . + : ~ Store letter in array
- w. 1 + w : ~ Bump index
- ?' z : ~ Get another letter
- z. 13 < z. 13 > + ^ ) ~ Loop, if not carriage return
-
- 0 a. w. + : ~ Mark end with a null
- @ ]
-
- 1% 2 = [ ~ If displaying name
-
- ( a. w. + . v : v. ^ ~ While null not detected
- v. !' w. 1 + w : ) ~ Print letter, bump index
-
- @ ]
-
- $P ~ Pause a bit. Value passed controls how long the pause lasts.
- ~ Do clear screen when appropriate
-
- R. 22 = [ ~ If line count is just right
- x. 'c < x. 'c > + [ ~ If they haven't asked for a continuous display
-
- "!!Press <RETURN> to continue, <SPACE BAR> for continuous display. "
-
- ?' w : w. 32 = [ 'c x : ] ~ Check for <SPACE BAR> and record if detected
- ] #Z; 1 R : ] ~ Clear the screen, reset line count
-
- } ~ Make sure trace is off. Would take too long to trace this.
-
- 1% B. / w : ( w. ^ w. 1 - w : ) ~ Pause, in any case.
-
- Y. [ 0 Y : "!Restart or continue tracing? " #A,1; [
- 1 Y : { ]] ~ Turn trace back on, if it was on, and still desired.
- @
-
- $Z ~ Clear screen. Treat KayPro users that want it differently.
-
- 'k K. = [ 'Z 64 - !' @ ] ~ KayPro clear screen
-
- 24 w : ~ Scrolling clear screen via 24 line feeds
-
- ( w. ^ 'J 64 - !' w. 1 - w : ) @
-
- ~ Ok, I'm done.
- yPro clear screen
-
- 24 w : ~ Scro