Tutorial 024 - Logarithm Game
This game was inpired by a boy called George, whom I taught way back
in the 70s. George had the amazing ability to be able to instantly tell you
the logarithm of any number to any required accuracy; or the sine of an angle
for that matter. His fellows were just starting to acquire hand calculators
and were amazed to find that his oracular predictions in this department
were remarkably accurate! Similarly there are people who can tell you the
date of Easter in any given year by calculating the result unconsciously
and instantly, without having any understanding of the necessary algorithm.
Maybe we can all train ourselves to do similar tasks. Give it a try.
Background
The (common) logarithm of a number is the power to which you need to
raise ten to give you the number. Thus
1 = 10^0
log(1) = 0.000 5 = 10^0.699
log(5) = 0.699
10 = 10^1 log(10)
= 1.000 50 = 10^1.699
log(50) = 1.699
100 = 10^2 log(100) = 2.000
500 = 10^2.699
log(500) = 2.699
1000 = 10^3 log(1000) = 3.000
5000 = 10^3.699 log(5000) =
3.699
The mathematical connection between a number and its log is sufficently
obscure as to make a conscious calculation unlikely.
I think you will find as you play the game that, after a short period
of training, your hunches will get progressively better. Let me know your
results - no cheating mind! You can see the scoring scheme in the program
listing.
REM: Logarithm
Game
REM: Test your unconscious mathematical
nous
REM: Richard Weston, 5th may 2003
MODE8
i=0:sc=0:av=0
REPEAT
i=i+1
ON
COLOUR1
PRINTTAB(5,1)"L O G A R I
T H M G A M E"
COLOUR3
PRINTTAB(5,3)"Guess the number
associated with each logarithm : "''
COLOUR15
PRINT'TAB(5);"Logarithm"TAB(27);"Number"'
a=RND(4)-1
b=RND(1)
b$=MID$(STR$(b),2,4)
log$=STR$(a)+b$
num=10^(VAL(log$))
PRINTTAB(5)log$
INPUTTAB(27,VPOS-1)guess
PRINT'TAB(4)"Answer is 10^(";log$;")
= ";num
pce=ABS(INT(100*((num-guess)/num)+0.5))
PRINT'TAB(8)"percentage error
= ";pce;"%"
PROCscore
sc=sc+usc
avsc=0.01*INT((100*sc/i +0.5))
PRINT'TAB(2)"You score ";usc
TAB(20)"average score = ";sc;"/";i;" = ";avsc
COLOUR6
PRINTTAB(5,18)"Press SPACE
for another":OFF
G=GET
CLS
UNTIL FALSE
END
:
DEF PROCscore
IF pce<2 THEN usc=5:ENDPROC
IF pce<6 THEN usc=4:ENDPROC
IF pce<11 THEN usc=2:ENDPROC
IF pce<21 THEN usc=1:ENDPROC
IF pce>20 THEN usc=0
ENDPROC
Annotated Listing
REM: Logarithm
Game
REM: Test your unconscious mathematical
nous
REM: Richard Weston, 5th may 2003
MODE8
i=0:sc=0:av=0 ***game number, score total,
average score ***
REPEAT
i=i+1 *** game number ***
ON *** flashing cursor on
***
COLOUR1
PRINTTAB(5,1)"L O G A R I
T H M G A M E"
COLOUR3
PRINTTAB(5,3)"Guess the number
associated with each logarithm : "''
COLOUR15
PRINT'TAB(5);"Logarithm"TAB(27);"Number"'
a=RND(4)-1 *** sets the "characteristic"
or integer part of the logarithm in the range 0 to 3 giving numbers from
0 to 9999.99999 ****
b=RND(1) *** sets the "mantissa"
or fractional part of the logarithm ***
b$=MID$(STR$(b),2,4) ***
strips oof the zero eg 0.3546 becomes .3546 ***
log$=STR$(a)+b$ *** joins
the characteristic and mantissa as a string ***
num=10^(VAL(log$)) *** calculates
the number corresponding to the logarithm, which you guess ***
PRINTTAB(5)log$
INPUTTAB(27,VPOS-1)guess
*** Input your guess; the VPOS bit keeps it on the same line as the logarithm
was printed in the previous line ***
PRINT'TAB(4)"Answer is 10^(";log$;")
= ";num
pce=ABS(INT(100*((num-guess)/num)+0.5))
*** percentage error; ABS keeps it positive ; 100*INT( ....+0.5) rounds
it to the nearest percentage point) ***
PRINT'TAB(8)"percentage error
= ";pce;"%"
PROCscore *** computes the
score according to the accuracy of the guess ***
sc=sc+usc *** update total
score ***
avsc=0.01*INT((100*sc/i +0.5))
*** calculates the average score and rounds it ***
PRINT'TAB(2)"You score ";usc
TAB(20)"average score = ";sc;"/";i;" = ";avsc
COLOUR6
PRINTTAB(5,18)"Press SPACE
for another":OFF *** flashing cursor would distract
G=GET *** wait for any key
press ***
CLS *** clear screen for
the next round ***
UNTIL FALSE
END
:
DEF PROCscore
IF pce<2 THEN usc=5:ENDPROC ***
percentage error less than 2% ; usc stands for "you score" (for this round)
IF pce<6 THEN usc=4:ENDPROC *** etc
***
IF pce<11 THEN usc=2:ENDPROC
IF pce<21 THEN usc=1:ENDPROC
IF pce>20 THEN usc=0
ENDPROC
Next
Tutorial
Richard Weston's Homepage