Introduction to Programming 
with 
Mathematica

By
Richard J. Gaylord 
(gaylord@ux1.cso.uiuc.edu)

Samuel N. Kamin 
(kamin@cs.uiuc.edu)

Paul R. Wellin 
(wellin@sonoma.edu)

Copyright © 1993 by TELOS/Springer-Verlag

Chapter 1 – Preliminaries

(Mathematica code)

Functions defined in this Notebook...(page No. in book)

bowlingScore...2

Initialization (evaluate to turn off spell messages)

Off[General::spell]

Off[General::spell1]

Section 1.1  Introduction

bowlingScore[pins_] := Module[{score},
   score[{x_, y_, z_}] := x + y + z;
   score[{10, y_, z_, r___}] := 10+y+z+score[{y, z, r}];
   score[{x_, y_, z_, r___}] := x+y+z+score[{z, r}] /; 
		x + y == 10;
   score[{x_, y_, r___}] := x+y+score[{r}] /; x+y < 10;
   score[If[pins[[-2]] + pins[[-1]] >= 10, pins, Append[pins, 0]]]]

(* Example of perfect game *)
bowlingScore[Table[10,{12}]]

Section 1.4  Predicates and Boolean Operations

TableForm[Outer[And, {{True, False}, {True, False}}],
	TableHeadings->{{T, F}, {T, F}}]

Section 1.5  Evaluation of Expressions

timings = Table[Timing[FactorInteger[(100j)!]][[1]], 
	{j, 1, 15}];

ListPlot[timings/Second, PlotStyle->PointSize[.02]];