0% found this document useful (0 votes)
0 views

Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming 2nd Edition Jessen Havill download

Ebook download

Uploaded by

marasprideqq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming 2nd Edition Jessen Havill download

Ebook download

Uploaded by

marasprideqq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 57

Discovering Computer Science: Interdisciplinary

Problems, Principles, and Python Programming 2nd


Edition Jessen Havill pdf download

https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-2nd-
edition-jessen-havill/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Discovering Computer Science Interdisciplinary Problems


Principles and Python Programming 2nd Edition Jessen
Havill

https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-2nd-
edition-jessen-havill-2/

Discovering Computer Science Interdisciplinary Problems


Principles and Python Programming 1st Edition Jessen
Havill

https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-1st-
edition-jessen-havill/

Discovering Computer Science Interdisciplinary Problems


Principles and Python Programming First Edition Jessen
Havill

https://textbookfull.com/product/discovering-computer-science-
interdisciplinary-problems-principles-and-python-programming-
first-edition-jessen-havill/

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/
Python Programming An Introduction to Computer Science
John M. Zelle

https://textbookfull.com/product/python-programming-an-
introduction-to-computer-science-john-m-zelle/

Python Programming An Introduction to Computer Science


3rd Edition John M. Zelle

https://textbookfull.com/product/python-programming-an-
introduction-to-computer-science-3rd-edition-john-m-zelle/

Data Science from Scratch First Principles with Python


2nd Edition Joel Grus

https://textbookfull.com/product/data-science-from-scratch-first-
principles-with-python-2nd-edition-joel-grus/

Data Science from Scratch First Principles with Python


2nd Edition Grus Joel

https://textbookfull.com/product/data-science-from-scratch-first-
principles-with-python-2nd-edition-grus-joel/

Practical Programming An Introduction to Computer


Science Using Python 3 6 3rd Edition Paul Gries

https://textbookfull.com/product/practical-programming-an-
introduction-to-computer-science-using-python-3-6-3rd-edition-
paul-gries/
Discovering Computer Science
Chapman & Hall/CRC
Textbooks in Computing

Series Editors
John Impagliazzo
Andrew McGettrick
Pascal Hitzler, Markus Krötzsch, and Sebastian Rudolph, Foundations of Semantic Web Technologies
Henrik Bœrbak Christensen, Flexible, Reliable Software: Using Patterns and Agile Development
John S. Conery, Explorations in Computing: An Introduction to Computer Science
Lisa C. Kaczmarczyk, Computers and Society: Computing for Good
Mark Johnson, A Concise Introduction to Programming in Python
Paul Anderson, Web 2.0 and Beyond: Principles and Technologies
Henry Walker, The Tao of Computing, Second Edition
Ted Herman, A Functional Start to Computing with Python
Mark Johnson, A Concise Introduction to Data Structures Using Java
David D. Riley and Kenny A. Hunt, Computational Thinking for the Modern Problem Solver
Bill Manaris and Andrew R. Brown, Making Music with Computers: Creative Programming in Python
John S. Conery, Explorations in Computing: An Introduction to Computer Science and Python Programming
Jessen Havill, Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming
Efrem G. Mallach, Information Systems: What Every Business Student Needs to Know Iztok Fajfar, Start Programming
Using HTML, CSS, and JavaScript
Mark C. Lewis and Lisa L. Lacher, Introduction to Programming and Problem-Solving Using Scala, Second Edition
Aharon Yadin, Computer Systems Architecture
Mark C. Lewis and Lisa L. Lacher, Object-Orientation, Abstraction, and Data Structures Using Scala, Second Edition
Henry M. Walker, Teaching Computing: A Practitioner’s Perspective
Efrem G. Mallach, Information Systems:What Every Business Student Needs to Know, Second Edition
Jessen Havill, Discovering Computer Science: Interdisciplinary Problems, Principles, and Python Programming, Second
Edition
For more information about this series please visit:
https://www.crcpress.com/Chapman--HallCRC-Textbooks-in-Computing/book-series/CANDHTEXCOMSER?
page=2&order=pubdate&size=12&view=list&status=published,forthcoming
Discovering Computer Science
Interdisciplinary Problems, Principles, and Python
Programming

Second Edition

Jessen Havill
Second edition published 2021
by CRC Press
2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
and by CRC Press
6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742
© 2021 Jessen Havill
The right of Jessen Havill to be identified as author of this work has been asserted by him in accordance with sections 77
and 78 of the Copyright, Designs and Patents Act 1988.
All rights reserved. No part of this book may be reprinted or reproduced or utilised in any form or by any electronic,
mechanical, or other means, now known or hereafter invented, including photocopying and recording, or in any information
storage or retrieval system, without permission in writing from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com or contact the
Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. For works that are not
available on CCC please contact mpkbookspermissions@tandf.co.uk
Trademark notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library

Library of Congress Cataloging-in-Publication Data


Names: Havill, Jessen, author.
Title: Discovering computer science: interdisciplinary problems, principles, and Python programming / Jessen
Havill.
Description: Second edition. ∣ Boca Raton: CRC Press, 2021. ∣ Series: Chapman & Hall/CRC press textbooks
in computing ∣ Includes bibliographical references and index.
Identifiers: LCCN 2020030144 ∣ ISBN 9780367472498 (paperback) ∣ ISBN 9780367613358 (hardback) ∣
ISBN 9781003037149 (ebook)
Subjects: LCSH: Computer science--Textbooks. ∣ Python (Computer program language)--Textbooks.
Classification: LCC QA76 H3735 2021 ∣ DDC 005.13/3--dc23
LC record available at https://lccn.loc.gov/2020030144

ISBN: 9780367613358 (hbk)


ISBN: 9780367472498 (pbk)
ISBN: 9781003037149 (ebk)
Typeset in Computer Modern font
by Cenveo Publisher Services
Contents

Preface

Acknowledgments

About the author

CHAPTER 1 ■ How to Solve It

1.1 UNDERSTAND THE PROBLEM


A first problem: computing reading level
Functional abstraction

1.2 DESIGN AN ALGORITHM


Take it from the top
Pseudocode
Implement from the bottom

1.3 WRITE A PROGRAM


Welcome to the circus
What’s in a name?
Interactive computing
Looking ahead

1.4 LOOK BACK


Testing
Algorithm efficiency

1.5 SUMMARY AND FURTHER DISCOVERY

CHAPTER 2 ■ Visualizing Abstraction


2.1 DATA ABSTRACTION
Turtle graphics

2.2 DRAWING FLOWERS AND PLOTTING EARTHQUAKES


Iteration
Tangent 2.1 Defining colors
Data visualization

2.3 FUNCTIONAL ABSTRACTION


Function parameters

2.4 PROGRAMMING IN STYLE


Program structure
Documentation
Tangent 2.2 Global variables
Self-documenting code

2.5 A RETURN TO FUNCTIONS


The math module
Writing functions with return values
Return vs. print

2.6 SCOPE AND NAMESPACES


Local namespaces
The global namespace

2.7 SUMMARY AND FURTHER DISCOVERY

CHAPTER 3 ■ Inside a Computer

3.1 COMPUTERS ARE DUMB


Tangent 3.1 High performance computing
Machine language
Tangent 3.2 Byte code

3.2 EVERYTHING IS BITS


Bits are switches
Bits can represent anything
Tangent 3.3 Hexadecimal notation
Computing with bits

3.3 COMPUTER ARITHMETIC


Limited precision
Tangent 3.4 Floating point notation
Error propagation
Division
Complex numbers

*3.4 BINARYARITHMETIC
More limited precision
Negative integers
Designing an adder
Implementing an adder

3.5 THE UNIVERSAL MACHINE

3.6 SUMMARY AND FURTHER DISCOVERY

CHAPTER 4 ■ Growth and Decay

4.1 ACCUMULATORS
Managing a fishing pond
Measuring network value
Organizing a concert

4.2 DATA VISUALIZATION

4.3 CONDITIONAL ITERATION


When will the fish disappear?
When will your nest egg double?

*4.4 CONTINUOUS MODELS


Difference equations
Radiocarbon dating
Tradeoffs between accuracy and time
Simulating an epidemic

*4.5 NUMERICAL ANALYSIS


The harmonic series
Approximating π
Approximating square roots

4.6 SUMMING UP
Tangent 4.1 Triangular numbers

4.7 FURTHER DISCOVERY

*4.8 PROJECTS
4.1 Parasitic relationships
4.2 Financial calculators
4.3 Market penetration
4.4 Wolves and moose

CHAPTER 5 ■ Forks in the Road

5.1 RANDOM WALKS


Tangent 5.1 Interval notation
One small step
Monte Carlo simulation

*5.2 PSEUDORANDOM NUMBER GENERATORS


Implementation
Testing randomness

*5.3 SIMULATING PROBABILITY DISTRIBUTIONS


The central limit theorem

5.4 BACK TO BOOLEANS


Predicate functions
Short circuit evaluation
DeMorgan’s laws
Thinking inside the box
Many happy returns

5.5 DEFENSIVE PROGRAMMING


Checking parameters
Assertions
Unit testing
Tangent 5.2 Unit testing frameworks
Testing floats
Catching exceptions

5.6 GUESS MYNUMBER


Ending the game nicely
Friendly hints
A proper win/lose message

5.7 SUMMARY AND FURTHER DISCOVERY

*5.8 PROJECTS
5.1 The magic of polling
5.2 Escape!

CHAPTER 6 ■ Text, Documents, and DNA

6.1 FIRST STEPS


Normalization
Tangent 6.1 Natural language processing
Tokenization
Creating your own module
Testing your module

6.2 TEXT DOCUMENTS


Reading from text files
Writing to text files
Reading from the web

6.3 ENCODING STRINGS


Computing checksums
Unicode
Tangent 6.2 Compressing text files
Indexing and slicing

6.4 A CONCORDANCE
Finding a word
A concordance entry
A complete concordance

6.5 WORD FREQUENCY TRENDS


Finding the frequency of a word
Getting the frequencies in slices
Plotting the frequencies

6.6 COMPARING TEXTS


Dot plots

*6.7 TIME COMPLEXITY


Best case vs. worst case
Asymptotic time complexity

*6.8 COMPUTATIONAL GENOMICS


A genomics primer
Basic DNA analysis
Transforming sequences
Comparing sequences
Reading sequence files

6.9 SUMMARY AND FURTHER DISCOVERY


*6.10 PROJECTS
6.1 Polarized politics
6.2 Finding genes

CHAPTER 7 ■ Data Analysis

7.1 SUMMARY STATISTICS


Mean and variance
Minimum and maximum

7.2 WRANGLING DATA


Smoothing data
A more efficient algorithm
Modifying lists in place
List operators and methods
*List comprehensions
Tangent 7.1 NumPy arrays

7.3 TALLYING FREQUENCIES


Word frequencies
Dictionaries
Tangent 7.2 Hash tables
Finding the most frequent word
Bigram frequencies
Tangent 7.3 Sentiment analysis

7.4 READING TABULAR DATA


Earthquakes

*7.5 DESIGNING EFFICIENT ALGORITHMS


Removing duplicates
A first algorithm
A more elegant algorithm
A more efficient algorithm
*7.6 LINEAR REGRESSION

*7.7 DATA CLUSTERING


Defining similarity
A simple example
Implementing k-means clustering
Locating bicycle safety programs

7.8 SUMMARY AND FURTHER DISCOVERY


Tangent 7.4 Privacy in the age of big data

*7.9 PROJECTS
7.1 Climate change
7.2 Does education influence unemployment?
7.3 Maximizing profit
7.4 Admissions
7.5 Preparing for a 100-year flood
7.6 Voting methods
7.7 Heuristics for traveling salespeople

CHAPTER 8 ■ Flatland

8.1 TABULAR DATA


Reading a table of temperatures
Tangent 8.1 Pandas

8.2 THE GAME OF LIFE


Creating a grid
Initial configurations
Surveying the neighborhood
Performing one pass
Tangent 8.2 NumPy arrays in two dimensions
Updating the grid
8.3 DIGITAL IMAGES
Colors
Tangent 8.3 Additive vs. subtractive color models
Image filters
Tangent 8.4 Image storage and compression
Transforming images

8.4 SUMMARY AND FURTHER DISCOVERY

*8.5 PROJECTS
8.1 Modeling segregation
8.2 Modeling ferromagnetism
8.3 Growing dendrites
8.4 Simulating an epidemic

CHAPTER 9 ■ Self-similarity and Recursion

9.1 FRACTALS
Trees
Snowflakes

9.2 RECURSION AND ITERATION


Solving a problem recursively
Palindromes
Guessing passwords

9.3 THE MYTHICAL TOWER OF HANOI


*Is the end of the world nigh?

9.4 RECURSIVE LINEAR SEARCH


*Efficiency of recursive linear search

9.5 DIVIDE AND CONQUER


Buy low, sell high
Navigating a maze
*9.6 LINDENMAYER SYSTEMS
Formal grammars
L-systems
Implementing L-systems

9.7 SUMMARY AND FURTHER DISCOVERY

*9.8 PROJECTS
9.1 Lindenmayer’s beautiful plants
9.2 Gerrymandering
9.3 Percolation

CHAPTER 10 ■ Organizing Data

10.1 BINARY SEARCH


Tangent 10.1 Databases
Efficiency of iterative binary search
A spelling checker
Recursive binary search
*Efficiency of recursive binary search

10.2 SELECTION SORT


Implementing selection sort
Efficiency of selection sort
Querying data

10.3 INSERTION SORT


Implementing insertion sort
Efficiency of insertion sort

10.4 EFFICIENT SORTING


Merge sort
Internal vs. external sorting
Efficiency of merge sort
*10.5 TRACTABLE AND INTRACTABLE ALGORITHMS
Hard problems

10.6 SUMMARY AND FURTHER DISCOVERY

*10.7 PROJECTS
10.1 Creating a searchable database
10.2 Binary search trees

CHAPTER 11 ■ Networks

11.1 MODELING WITH GRAPHS


Making friends

11.2 SHORTEST PATHS


Breadth-first search
Finding the actual paths

11.3 IT’S A SMALL WORLD…


Small world networks
Clustering coefficients
Scale-free networks

11.4 RANDOM GRAPHS

11.5 SUMMARYAND FURTHER DISCOVERY

*11.6 PROJECTS

11.1 Diffusion of ideas and influence

11.2 Slowing an epidemic

11.3 The Oracle of Bacon

CHAPTER 12 ■ Object-oriented Design

12.1 SIMULATING AN EPIDEMIC


Object design
Person class
Augmenting the Person class
World class
The simulation

12.2 OPERATORS AND POLYMORPHISM


Designing a Pair ADT
Pair class
Arithmetic methods
Special methods
Comparison operators
Indexing

*12.3 A FLOCKING SIMULATION


The World
Boids

*12.4 ASTACKADT
Stack class
Reversing a string
Converting numbers to other bases

*12.5 ADICTIONARYADT
Hash tables
Implementing a hash table Indexing
ADTs vs. data structures

12.6 SUMMARYAND FURTHER DISCOVERY

*12.7 PROJECTS
12.1 Tracking GPS coordinates
12.2 Economic mobility
12.3 Slime mold aggregation
12.4 Boids in space
Bibliography

APPENDIX A ■ Python Library Reference

APPENDIX B ■ Selected Exercise Solutions

Index
_______________
* Sections with *** in lieu of a page number are available on the book website.
Preface

n my view, an introductory computer science course should strive to accomplish three


I things. First, it should demonstrate to students how computing has become a powerful
mode of inquiry, and a vehicle of discovery, in a wide variety of disciplines. This orientation
is also inviting to students of the natural and social sciences, and the humanities, who
increasingly benefit from an introduction to computational thinking, beyond the limited
“black box” recipes often found in manuals and “Computing for X” books. Second, the
course should engage students in computational problem solving, and lead them to discover
the power of abstraction, efficiency, and data organization in the design of their solutions.
Third, the course should teach students how to implement their solutions as computer
programs. In learning how to program, students more deeply learn the core principles, and
experience the thrill of seeing their solutions come to life.

Unlike most introductory computer science textbooks, which are organized around
programming language constructs, I deliberately lead with interdisciplinary problems and
techniques. This orientation is more interesting to a more diverse audience, and more
accurately reflects the role of programming in problem solving and discovery. A
computational discovery does not, of course, originate in a programming language feature in
search of an application. Rather, it starts with a compelling problem which is modeled and
solved algorithmically, by leveraging abstraction and prior experience with similar problems.
Only then is the solution implemented as a program.

Like most introductory computer science textbooks, I introduce programming skills in an


incremental fashion, and include many opportunities for students to practice them. The topics
in this book are arranged to ease students into computational thinking, and encourage them to
incrementally build on prior knowledge. Each chapter focuses on a general class of problems
that is tackled by new algorithmic techniques and programming language features. My hope
is that students will leave the course, not only with strong programming skills, but with a set
of problem solving strategies and simulation techniques that they can apply in their future
work, whether or not they take another computer science course.

I use Python to introduce computer programming for two reasons. First, Python’s intuitive
syntax allows students to focus on interesting problems and powerful principles, without
unnecessary distractions. Learning how to think algorithmically is hard enough without also
having to struggle with a non-intuitive syntax. Second, the expressiveness of Python (in
particular, low-overhead lists and dictionaries) expands tremendously the range of accessible
problems in the introductory course. Teaching with Python over the last fifteen years has
been a revelation; introductory computer science has become fun again.

Changes in the second edition


In this comprehensive, cover-to-cover update, some sections were entirely rewritten while
others saw only minor revisions. Here are the highlights:

Problem solving The new first chapter, How to Solve It, sets the stage by focusing on Polya’s
elegant four-step problem solving process, adapted to a computational framework. I
introduce informal pseudocode, functional decomposition, hand-execution with informal
trace tables, and testing, practices that are now carried on throughout the book. The
introduction to Python (formally Chapter 2) is integrated into this framework. Chapter 7,
Designing Programs, from the first edition has been eliminated, with that material spread out
more naturally among Chapters 1, 5, and 6 in the second edition.

Chapter 2, Visualizing Abstraction (based on the previous Chapter 3), elaborates on the
themes in Chapter 1, and their implementations in Python, introducing turtle graphics,
functions, and loops. The new Chapter 3, Inside a Computer (based on the previous Sections
1.4 and 2.5), takes students on a brief excursion into the simple principles underlying how
computers work.

Online materials To reduce the size of the printed book, we have moved some sections and
all of the projects online. These sections are marked in the table of contents with ***. Online
materials are still indexed in the main book for convenience.

Exercises I’ve added exercises to most sections, bringing the total to about 750. Solutions to
exercises marked with an asterisk are available online for both students and self-learners.

Digital humanities The interdisciplinary problems in the first edition were focused primarily
in the natural and social sciences. In this edition, especially in Chapters 1, 6, and 7, we have
added new material on text analysis techniques commonly used in the “digital humanities.”

Object-oriented design Chapter 12 begins with a new section to introduce object-oriented


design in a more concrete way through the development of an agent-based simulation of a
viral epidemic. The following sections flesh out more details on how to implement
polymorphic operators and collection classes.

Book website
Online materials for this book are available at
https://www.discoveringCS.net.

Here you will find


• additional “optional” sections, marked with an asterisk in the main text,
• over thirty interdisciplinary programming projects,
• solutions to selected exercises,
• programs and data files referenced in the text, exercises, and projects, and
• pointers for further exploration and links to additional documentation.

To students
Active learning Learning how to solve computational problems and implement them as
computer programs requires daily practice. Like an athlete, you will get out of shape and fall
behind quickly if you skip it. There are no shortcuts. Your instructor is there to help, but he or
she cannot do the work for you.

With this in mind, it is important that you type in and try the examples throughout the text,
and then go beyond them. Be curious! There are numbered “Reflection” questions
throughout the book that ask you to stop and think about, or apply, something that you just
read. Often, the question is answered in the book immediately thereafter, so that you can
check your understanding, but peeking ahead will rob you of an important opportunity.

Further discovery There are many opportunities to delve into topics more deeply. “Tangent”
boxes scattered throughout the text briefly introduce related, but more technical or applied,
topics. For the most part, these are not strictly required to understand what comes next, but I
encourage you to read them anyway. In the “Summary and Further Discovery” section of
each chapter, you can find both a high-level summary of the chapter and additional pointers
to explore chapter topics in more depth.

Exercises and projects At the end of most sections are several programming exercises that
ask you to further apply concepts from that section. Often, the exercises assume that you
have already worked through all of the examples in that section. Solutions to the starred
exercises are available on the book website. There are also more involved projects available
on the book website that challenge you to solve a variety of interdisciplinary problems.

No prerequisites The book assumes no prior knowledge of computer science. However, it


does assume a modest comfort with high school algebra. In optional sections, trigonometry is
occasionally mentioned, as is the idea of convergence to a limit, but these are not relevant to
understanding the main topics in the book.

Have fun! Programming and problem solving should be a fun, creative activity. I hope that
this book sparks your curiosity and love of learning, and that you enjoy the journey as much
as I have enjoyed writing this book.

To instructors
This book is appropriate for a traditional CS1 course for majors, a CS0 course for non-majors
(at a slower pace and omitting more material), or a targeted introductory computing course
for students in the natural sciences, social sciences, or humanities.

The approach is gentle and holistic, introducing programming concepts in the context of
interdisciplinary problems. We start with problem-solving, featuring pseudocode and hand-
execution with trace tables, and carry these techniques forward, especially in the first half of
the book.

Problem focus Most chapters begin with an interesting problem, and new concepts and
programming techniques are introduced in the context of solving it. As new techniques are
introduced, students are frequently challenged to re-solve old problems in different ways.
They are also encouraged to reuse their previous functions as components in later programs.

Reflection questions, exercises, and projects “Reflection” questions are embedded in every
section to encourage active reading. These may also be assigned as “reading questions”
before class. The end-of-section exercises are appropriate for regular homework, and some
more complex ones may form the basis of longer-term assignments. The book website also
hosts a few dozen interdisciplinary projects that students may work on independently or in
pairs over a longer time frame. I believe that projects like these are crucial for students to
develop both problem solving skills and an appreciation for the many fascinating applications
of computer science.

Additional instructor resources All of the reflection questions and exercises are available to
instructors as Jupyter notebooks. Solutions to all exercises and projects are also available.
Please visit the publisher’s website to request access.

Python coverage This book is not intended to be a Python manual. Some features of the
language were intentionally omitted because they would have muddled the core problem
solving focus or are not commonly found in other languages that students may see in future
CS courses (e.g., simultaneous swap, chained comparisons, zip, enumerate in for loops).

Topic coverage There is more in this book than can be covered in a single semester, giving
instructors the opportunity to tailor the content to their particular situation and interests. As
illustrated in Figure 1, Chapter 1, Chapter 2, Chapter 3, Chapter 4, Chapter 5, Chapter 6,
Chapter 7 form the core of the book, and should be covered sequentially. The remaining
chapters can be covered, partially or entirely, at your discretion, although I would expect that
most instructors will cover at least parts of Chapter 8, Chapter 9, Chapter 10, and 12 if the
course covers object-oriented design. Chapter 11 introduces social network graphs and small-
world and scale-free networks as additional powerful applications of dictionaries, and may
come any time after Chapter 7. Sections marked with an asterisk are optional, in the sense
that they are not assumed for future sections in that chapter. When exercises and projects
depend on optional sections, they are also marked with an asterisk, and the dependency is
stated at the beginning of the project.
Figure 1 An overview of chapter dependencies.

Chapter outlines The following tables provide brief overviews of what is available in each
chapter. Each table’s three columns, reflecting the three parts of the book’s subtitle, provide
three lenses through which to view the chapter.

1 How to Solve It

Sample problems Principles Programming


• reading level • problems, input/output • int, float, str types
• counting syllables, • functional abstraction • arithmetic
words
• sphere volume • functional decomposition • assignment
• digital music • top-down design • variable names
• search engines • bottom-up • calling built-in
implementation functions
• GPS devices • algorithms and programs • using strings
• phone trees • pseudocode • string operators
• wind chill • names as references • print and input
• compounding interest • trace tables
• Mad Libs • constant- vs. linear-time

2 Visualizing Abstraction
Sample problems Principles Programming
• visualizing • using abstract data types • using classes and objects
earthquakes
• drawing flowers • creating functional • turtle module
• random walks abstractions • for loops (range and
lists)
• ideal gas • functional decomposition • using and writing
functions
• groundwater flow • bottom-up implementation • return vs. print
• demand functions • turtle graphics • namespaces and scope
• reading level • trace tables with loops • docstrings and
comments
• self-documenting code
• program structure

3 Inside a Computer

Principles Programming
• computer organization • int and float types
• machine language • arithmetic errors
• binary representations • true vs. floor division
• computer arithmetic
• finite precision, error propagation
• Boolean logic, truth tables, logic gates
• Turing machines, finite state machines

4 Growth and Decay

Sample problems Principles Programming


• population models • accumulators • for loops, range
• network value • list accumulators • format strings
• demand and profit • data visualization • matplotlib.pyplot
• loans and investing • conditional iteration • appending to lists
• bacterial growth • classes of growth • while loops
• radiocarbon dating • continuous models
• epidemics (SIR, SIS) • accuracy vs. time
• diffusion models • numerical approximation

5 Forks in the Road


Sample problems Principles Programming
• random walks • random number generators • random module
• Monte Carlo simulation • simulating probabilities • if/elif/else
• guessing games • flag variables • comparison operators
• polling and sampling • using distributions • Boolean operators
• DeMorgan’s laws • short circuit evaluation
• particle escape • defensive programming • predicate functions
• pre- and post-conditions • assert, isinstance
• unit testing • catching exceptions
• histograms
• while loops

6 Text, Documents, and DNA

Sample problems Principles Programming


• text analysis • functional decomposition • str class and methods
• word frequency trends • unit testing • iterating over strings, lists
• checksums • ASCII, Unicode • indexing and slicing
• concordances • linear-time algorithms • iterating over indices
• dot plots, plagiarism • time complexity • creating a module
• congressional votes • linear search • text files and the web
• genomics • string accumulators • break
• nested loops

7 Data Analysis

Sample problems Principles Programming


• word, bigram • histograms • list class
frequencies
• smoothing data • hash tables • indexing and slicing
• 100-year floods • tabular data files • list operators and
methods
• traveling salesman • efficient algorithm • reading CSV files
design
• meteorite sites • linear regression • modifying lists in place
• zebra migration • k-means clustering • list parameters
• tumor diagnosis • heuristics • tuples
• supply and demand • list comprehensions
• voting methods • dictionaries

8 Flatland
Sample problems Principles Programming
• earthquake data • 2-D data • lists of lists
• Game of Life • cellular automata • nested loops
• image filters • digital images • 2-D data in a dictionary
• racial segregation • color models
• ferromagnetism
• dendrites
• epidemics
• tumor growth

9 Self-similarity and Recursion

Sample problems Principles Programming


• fractals • self-similarity • writing recursive functions
• cracking passwords • recursion • divide and conquer
• Tower of Hanoi • linear search • backtracking
• maximizing profit • recurrence relations
• navigating a maze • divide and conquer
• Lindenmayer systems • depth-first search
• gerrymandering • grammars
• percolation

10 Organizing Data

Sample problems Principles Programming


• spell check • binary search • nested loops
• querying data sets • quadratic-time sorting • writing recursive functions
• parallel lists
• merge sort
• recurrence relations
• intractability, P=NP?

11 Networks
Sample problems Principles Programming
• social media, web graphs • graphs • dictionaries
• diffusion of ideas • adjacency list, matrix
• epidemics • breadth-first search
• Oracle of Bacon • queues
• shortest paths
• depth-first search
• small-world networks
• scale-free networks
• uniform random graphs

12 Object-oriented Design

Sample problems Principles Programming


• epidemic simulation • abstract data types • object-oriented design
• data sets • encapsulation • writing classes
• genomic sequences • polymorphism • special methods
• rational numbers • data structures • overriding operators
• flocking behavior • stacks • modules
• slime mold aggregation • hash tables
• agent-based simulation
• swarm intelligence

Software assumptions
To follow along in this book and complete the exercises, you will need to have installed
Python 3.6 or later on your computer, and have access to IDLE or another programming
environment. The book also assumes that you have installed the matplotlib.pyplot and
numpy modules. The easiest way to get this software is to install the free open source
Anaconda distribution from http://www.anaconda.com.

Errata
While I (and my students) have ferreted out many errors, readers will inevitably find more.
You can find an up-to-date list of errata on the book website. If you find an error in the text
or have another suggestion, please let me know at havill@denison.edu.
Acknowledgments

In addition to those who provided their support and expertise for the first edition, I wish to
thank Janet Davis (Whitman College), Jim Deverick (The College of William and Mary),
David Goodwin (Denison University), and Ashwin Lall (Denison University) for their
valuable feedback on drafts of the second edition.
I would also like to thank Dee Ghiloni, Mary Lucas-Miller, and Tony Silveira for their
steadfast support, Mike Brady and my Data Analytics colleagues for reminding me how
much fun it can be to learn new things, and the Book Group for reminding me to not take life
too seriously. A Bowen Fellowship awarded by Denison University gave me the time needed
to complete this project.
Finally, my family has once again provided me with seemingly infinite patience and love
during this intensive period of writing. I am an extraordinarily lucky husband and father.
About the author

Jessen Havill is a Professor of Computer Science at Denison University. He has been


teaching courses across the computer science curriculum for almost thirty years, and was
awarded the College’s highest teaching honor, the Charles A. Brickman Teaching Excellence
Award, in 2013. Although his primary expertise is in the development and analysis of online
algorithms, Dr. Havill has spent many years collaborating with colleagues across the
curriculum to develop interdisciplinary academic opportunities for students. From 2016–
2019, he became the founding Director of Denison University’s interdisciplinary Data
Analytics program. Dr. Havill earned his bachelor’s degree from Bucknell University and his
Ph.D. in computer science from The College of William and Mary.
Another Random Scribd Document
with Unrelated Content
prayer is granted you must take the fox back again and put it just
where it was before. I should like to have taken one home; but my
servants hate foxes and Inari and tofu and azuki-meshi and abura-gi
and everything related to foxes. So I left it alone.
You will not be sorry to hear that I am to have the same publishers
as Mr. Lowell,—at least according to present indications. I am not
vain enough to think I can ever write anything so beautiful as his
“Chosōn” or “Soul of the Far East,” and will certainly make a poor
showing beside his precise, fine, perfectly worded work. But I am
not going to try to do anything in his line. My work will deal wholly
with exceptional things (chiefly popular) in an untilled field of
another kind.
I gave 72 boys, as subject for composition the other day, the
question: “What would you most like in this world?” Nine of the
compositions contained in substance this answer: “To die for our
Sacred Emperor.” That is Shintō. Isn’t it grand and beautiful? and do
you wonder that I love it after that?
Most grateful regards from yours most sincerely,
Lafcadio Hearn.

TO BASIL HALL CHAMBERLAIN


Matsue, 1891.

Dear Professor Chamberlain,—I went to Kōbe by rail, and thence by


jinrikisha across Japan over mountains and through valleys of rice-
fields—a journey of four days; but the most delightful in some
respects of all my travelling experiences. The scenery had this
peculiar effect, that it repeated for me many of my tropical
impressions—received in a country of similar volcanic configuration,
—besides reviving for me all sorts of early memories of travel in
Wales and England which I had forgotten. Nothing could be more
beautiful than this mingling of the sensations of the tropics with
those of Northern summers. And the people! My expectations were
much more than realized: it is among the country-people Japanese
character should be studied, and I could not give my opinion of
them now without using what you would call enthusiastic language.
I felt quite sorry to reach this larger city, where the people are so
much less simple, charming, and kindly,—although I have every
reason to be pleased with them. And in a mountain village I saw a
dance unlike anything I ever saw before—some dance immemorially
old, and full of weird grace. I watched it until midnight, and wish I
could see it again. Nothing yet seen in Japan delighted me so much
as this Bon-odori—in no wise resembling the same performance in
the north. I found Buddhism gradually weaken toward the interior,
while Shintō emblems surrounded the fields, and things suggesting
the phallic worship of antiquity were being adored in remote groves.
Lafcadio Hearn.

TO BASIL HALL CHAMBERLAIN


Matsue, June, 1891.

Dear Mr. Chamberlain,—I am horribly ashamed to confess my


weakness; but the truth must be told! After having lived for ten
months exclusively upon Japanese fare, I was obliged to return (for
a couple of days only!!!!) to the flesh-pots of Egypt. Having become
sick, I could not recuperate upon Japanese eating—even when
reënforced with eggs. I devoured enormous quantities of beef, fowl,
and sausage, and fried solid stuffs, and absorbed terrific quantities
of beer,—having had the good luck to find one foreign cook in
Matsue. I am very much ashamed! But the fault is neither mine nor
that of the Japanese: it is the fault of my ancestors,—the ferocious,
wolfish hereditary instincts and tendencies of boreal mankind. The
sins of the father, etc.
Do you know anything about Chōzuba-no-Kami? There are images of
him. He has no eyes—only ears. He passes much of his time in
sleep. He is angry if any one enters the koka without previously
hemming,—so as to give him notice. He makes everybody sick if the
place in which he dwells is not regularly cleaned. He goes to Kizuki
and to Sada with the other gods once a year; and after a month’s
absence returns. When he returns, he passes his hand over each
member of the family as they go to the Chōzuba,—to make sure the
family is the same. But one must not be afraid of the invisible hand.
I think this kami is an extremely decent, respectable person, with
excellent views on the subjects of morality and hygiene. I could not
refuse him a lamp nor—for obvious reasons—the worship of incense.
I have not been able to travel yet far enough to find anything novel,
but hope soon to do so. Meanwhile I am planning to make, if
possible, not only a tour of Izumo, but also a very brief visit to
Tōkyō in company with Mr. Nishida. Perhaps—I may be able to see
both you and Mr. Lowell for a tiny little while—you will always have a
moment to spare.
I am always haunted by a particularly sarcastic translation Mr.
Lowell, in one of his books, made of the name of a gate,—“The Gate
of Everlasting Ceremony.” (Only an American could have dared to
make such a translation.) I have been through the Gate and into the
Court of Everlasting Ceremony; but the gate is a marvellous
swarming of carven dragons and water, and the court is full of peace
and sweetness. Most truly,
Lafcadio Hearn.

TO BASIL HALL CHAMBERLAIN


Matsue, 1891.
Dear Professor Chamberlain,—Your welcome letter has just reached
me, on the eve of a trip to Kizuki, and—unless extraordinary
circumstances prevent—Oki islands. My guest has departed. He was
so petted and made much of here, that I could not help regretting
you also would not come. I think I could make you comfortable
here,—even in regard to diet,—at any time when you could make
the trip; and, as far as the people go, they would embarrass you
with kindness. Your name here is—well, more than you would wish it
to be.
Your last delightful letter I did not fully answer in my last, being
hurried. What you said about the influence of health or sickness on
the spiritual life of a man went straight to my heart. I have found, as
you have done, that the possessor of pure horse-health never seems
to have an idea of the “half-lights.” It is impossible to see the
psychical undercurrents of human existence without that self-
separation from the purely physical part of being, which severe
sickness gives—like a revelation. One in good health, who has never
been obliged to separate his immaterial self from his material self,
always will imagine that he understands much which, even recorded
in words, cannot be understood at all without sharp experience. We
are all living two lives,—but the revelation of the first seems only to
come by accident. There is an essay worth reading, entitled
“Sickness is Health,”—dealing with the physical results of sickness
only; but there is a much larger psychological truth in the title than
the author of it, whose name I forget, ever dreamed of. All the
history of asceticism and self-suppression as a religion, appears to
me founded upon a vague, blundering, intuitive recognition of the
terrible and glorious fact, that we can reach the highest life only
through that self-separation which the experiences of illness, that is,
the knowledge of physical weakness, brings; perfect health always
involves the domination of the spiritual by the physical—at least in
the present state of human evolution.
Perhaps it will interest you to know the effect of Japanese life upon
your little friend after the experiences of a year and a half. At first,
the sense of existence here is like that of escaping from an almost
unbearable atmospheric pressure into a rarefied, highly oxygenated
medium. That feeling continues: in Japan the law of life is not as
with us,—that each one strives to expand his own individuality at the
expense of his neighbour’s. But on the other hand, how much one
loses! Never a fine inspiration, a deep emotion, a profound joy or a
profound pain—never a thrill, or, as the French say so much better
than we, a frisson. So literary work is dry, bony, hard, dead work. I
have confined myself strictly to the most emotional phases of
Japanese life,—popular religion and popular imagination, and yet I
can find nothing like what I would get at once in any Latin country, a
strong emotional thrill. Whether it is that the difference in our
ancestral history renders what we call soul-sympathy almost
impossible, or whether it is that the Japanese are psychically smaller
than we, I cannot venture to decide—I hope the former. But the
experience of all thinking persons with whom I have had a chance to
speak seems to be the same.
But how sweet the Japanese woman is!—all the possibilities of the
race for goodness seem to be con centrated in her. It shakes one’s
faith in some Occidental doctrines. If this be the result of
suppression and oppression,—then these are not altogether bad. On
the other hand, how diamond-hard the character of the American
woman becomes under the idolatry of which she is the subject. In
the eternal order of things which is the highest being,—the childish,
confiding, sweet Japanese girl,—or the superb, calculating,
penetrating Occidental Circe of our more artificial society, with her
enormous power for evil, and her limited capacity for good? Viscount
Torio’s idea haunts me more and more;—I think there are very
formidable truths in his observations about Western sociology. And
the question comes: “In order to comprehend the highest good, is it
necessary that we must first learn the largest power of evil?” For the
one may be the Shadow of the other.
I am very much disappointed with Rein. I got much more
information about my own particular line of study from your “Things
Japanese” than from Rein. Rein himself confesses, after seven or
eight years’ labour, that he has only been able to make “a
patchwork”! What, then, can a man like myself hope to do,—without
scientific knowledge, and without any hope of even acquiring the
language of the country so as to read even a newspaper? Really it
seems to me almost an impertinence on my part to try to write
anything about Japan at all, and the only fact which gives me
courage is that there exists no book especially devoted to the
subject I hope to consider.
The deity of Mionoseki is called always by the people Ebisu, or Koto-
shiro-nushi-no-Kami;—in the guide the deity is said to be Hiruko,
who, I believe, has been identified by Shintō commentators with
Hiruko, as I find in the article on the Seven Gods of Good Fortune, in
the Asiatic Transactions. But I am not sure what to say about Hiruko
being the deity of Mio Jinja, as a general statement. My friends say
that only a Shintō priest can decide, and I am going to see one.
Most truly,
Lafcadio Hearn.

TO BASIL HALL CHAMBERLAIN


Matsue, August, 1891.

Dear Professor Chamberlain,—I have just received and read your most
interesting letter on my return from Kizuki,—where I should have
liked to remain longer, but I must go to see the Bon-odori at Shimo-
ichi, where it is danced differently from anywhere else, so far as I
can learn, and in a thrillingly ghostly manner,—so that one thinks he
is looking at a Dance of Souls.
Before leaving I had a copy of Murray’s Guide sent to the Kokuzō,
who was more than pleased to see the picture of the great temple
reproduced and to hear what was said about it. Before I went away,
he gave me another singular entertainment, such as he alone could
do—for he is King of Kizuki. (By the way, the old reverence for the
Kokuzō is not dead. Folks do not believe now that whoever he looks
at immediately becomes unable to move; but as I and my
companion followed him to the great shrine, the pilgrims fell down
and worshipped him as he passed.)
This was the entertainment he gave me:—Having invited me to the
temple grounds, where seats were prepared, and a supper got ready
for us, Mr. Senke gave some order, and the immense court
immediately filled with people,—thousands. Then at a signal began a
round dance, such as I had never seen before,—the Hōnen-odori, as
anciently performed in Kizuki. It was so fascinating that I watched it
until two o’clock in the morning. At least three hundred dancers
were in the ring;—and the leader, standing on a mochi-mortar
turned upside down, with an umbrella over his head, formed the axis
of the great round, and turned slowly within it upon his pedestal. He
had a superb voice. The Kokuzō also got the beautiful miko dances
photographed to please me, and presented me with many curious
MSS., some of which I hope to show you later on. They were written
expressly for me.
Now as to the shōryō-bune. Just as the Bon-odori differs in every
part of Japan, and just as everything at Kizuki is totally different
from everything at Ise, even to the Miko-kagura, so is the custom of
sending away the Ships of the Souls different here. In many parts
the ships are launched at two or three o’clock in the morning of the
day after the Bon; or if ships are not launched, then floating lanterns
are sent out by way of guiding the dead home. But in Kizuki the
shōryō-bune are launched only by day and for those who have been
drowned at sea, and the shapes of the ships vary according to the
kind of ship in which the lost man or woman perished. And they are
launched every year for ten years after the death:—and when the
soul returns yearly to visit the home, the ship is made ready, and a
little stick of incense is lighted before launching it to take the
beloved ghost back again, and a little stock of provisions is placed in
it upon kawarake (principally dango). And the kaimyō of the dead is
written upon the sail. And these boats are launched,—not at night,
as elsewhere, but in the daytime.
I have had the shōryō-bune boxed and addressed to you, and a
priest wrote for me the kaimyō upon the sail and the date of death,
according to the usual custom. But you will not get the thing before
three weeks, as I am forwarding it by express, and you know how
slow the process is!
As for my letters, use anything you wish, and, if you desire, my
name. The only matter is this: that I am so small a personage as an
author that I am much in doubt whether the use of my name
attached to any opinion would give the opinion more weight than if
expressed impersonally. Unless it should, it might not be good for
the book. I leave the decision entirely to you.
I have been reading Mr. Lowell’s book over again; for it is one thing
to read it in Philadelphia, and quite another thing to read it after
having spent a year and a half in Japan. And the power and the
charm impress me more than ever. But I am so much horrified by its
conclusions—at least a few of them—that I try very hard to find a
flaw therein. I think the idea that the degree of the development of
individuality in a people necessarily marks its place in the great
march of mind is not true necessarily. At least it may be argued
about. For as the tendency of the age is toward class specialization
and interdependent subdivision of all branches of knowledge and all
practical application of that knowledge, the development of the
individuality of every integer of a community would seem to me to
unfit the unit to form a close part of any specialized class. In brief, I
doubt, or rather I wish to doubt, that the development of
individuality is a lofty or desirable tendency. Much of what is called
personality and individuality is intensely repellent, and makes the
principal misery of Occidental life. It means much that is connected
with pure aggressive selfishness: and its extraordinary development
in a country like America or England seems a confirmation of
Viscount Torio’s theory that Western civilization has the defect of
cultivating the individual at the expense only of the mass, and giving
unbounded opportunities to human selfishness, unrestrained by
religious sentiment, law, or emotional feeling.
THE CITY OF MATSUE

What you say about your experience with Japanese poetry is indeed
very telling and very painful to one who loves Japan. Depth, I have
long suspected, does not exist in the Japanese soul-stream. It flows
much like the rivers of the country,—over beds three quarters dry,—
very clear and charmingly beshadowed;—but made temporarily
profound only by some passional storm. But it seems to me that
some tendencies in Japanese prose give hope of some beautiful
things. There was a story some time ago in the Asahi Shimbun about
a shirabyōshi that brought tears to my eyes, as slowly and painfully
translated by a friend. There was tenderness and poetry and pathos
in it worthy of Le Fanu (I thought of the exquisite story of Le Fanu,
“A Bird of Passage,” simply as a superb bit of tender pathos) or Bret
Harte—though, of course, I don’t know what the style is. But the
Japanese poem, as I judge from your work and the “Anthologie
Japonaise,” seems to me exactly the Japanese coloured print in
words,—nothing much more. Still, how the sensation of that which
has been is flashed into heart and memory by the delicious print or
the simple little verse.
I go to-morrow or the next day to Shimo-ichi. If you get the shōryō-
bune, let me know. Any of your servants can, I think, fix the little
masts and pennons in place. A small incense vessel and kawarake
with dango, or models of dango, might be added by Dr. Tylor to the
exhibit; but I suppose these are not essential.
With sincerest regards, ever truly,
Lafcadio Hearn.

TO BASIL HALL CHAMBERLAIN


Matsue, August, 1891.

Dear Mr. Chamberlain,—Before leaving, I must trouble you with


another note or two.
For “Things Japanese,” I would like to make a suggestion about the
article “Theatre.” The refer ence to O-Kuni seems to me extremely
severe; for her story is very beautiful and touching. She was a miko
in the Great Temple of Kizuki, and fell in love with a ronin named
Nagoya Sanza, and she fled away with her lover to Kyōto. On the
way, another ronin, who fell in love with her extraordinary beauty,
was killed by Sanza. Always the face of the dead man haunted the
girl.
At Kyōto she supported her lover by dancing the Miko-kagura in the
dry bed of the river Kamogawa.
Then they went to Tōkyō (Yedo) and began to act. Sanza himself
became a famous and successful actor. The two lived together until
Sanza died.
Then she came back to Kizuki. She was learned, and a great poet in
the style called renga. After Sanza’s death she supported herself, or
at least occupied herself, in teaching this poetic art. But she shaved
off her hair and became a nun, and built the little Buddhist temple in
Kizuki called Rengaji, in which she lived, and taught her art. And the
reason she built the temple was that she might pray for the soul of
the ronin whom the sight of her beauty had ruined. The temple
stood until thirty years ago. Nothing is now left of it but a broken
statue of Jizō. Her family still live in Kizuki, and until the restoration
the chief of the family was always entitled to a share of the profits of
the Kizuki theatre, because his ancestress, the beautiful miko, had
founded the art.
So I would like to suggest that poor O-Kuni have a kind word said
for her. And I am sure we would both think very highly of her if she
were alive.
There is a little Japanese book about her history; but I do not know
the title. With best regards,
Lafcadio.

TO PAGE M. BAKER
Matsue, August, 1891.

Dear Page,—I answer your dear letter at once, as you wished me to


do. It reached me to-day, on my return from Kizuki, the Holy City of
Japan,—where I have become something of a favourite with the
high pontiff of the most ancient and sacred shrine of the land,—
which no other European was ever permitted to enter before me.
And I am travelling now,—stopping at home only on my way to other
curious and unknown places. For this part of Japan is so little known
that I was the first to furnish Murray’s Guidebook editors with some
information thereabout....
But I had unknown friends here who knew me through my “Chinese
Ghosts”—so they applied to the Government for me, and I got an
educational position under contract. The contract was renewed last
March for a year—the extreme term allowed by law. My salary is
only $100 per month; but that is equal here to more than double the
sum in America. So that I am able to keep up nearly the nicest
house in town,—outside of a few very rich men,—to have several
servants, to give dinners, and to dress my little wife tolerably nicely.
Moreover, life in Japan is something so placid and kindly and gentle
—that it is just like one of those dreams in which everybody is good-
natured about everything. The missionaries have no reason to like
me,—for one had to be discharged to secure me; and I teach the
boys to respect their own beautiful faith and the gods of their
fathers, and not to listen to proselytism. However, the missionaries
leave me alone. We have a tiff about Spencer in the Japan Mail
sometimes; but as a rule I am completely isolated from all
Europeans. It is only at long intervals one ever gets so far,—with the
exception of an austere female stationed here in the vague hope of
making a convert.
Of course I will send you a photograph of my little wife. I must tell
you I am married only in the Japanese manner as yet,—because of
the territorial law. Only by becoming a Japanese citizen, which I
think I shall do, will it be possible to settle the matter satisfactorily.
By the present law, the moment a foreigner marries a native
according to English law, she becomes an English citizen, and her
children English subjects, if she have any. Therefore she becomes
subject to territorial laws regarding foreigners,—obliged to live within
treaty limits, and virtually separated from her own people. So it
would be her ruin to marry her according to English form, until I
become a Japanese in law;—for should I die, she would have serious
reason to regret her loss of citizenship.
As for going abroad—I mean back to you all—I don’t know what to
say. Just now, of course, I could not if I would; for I am under legal
contract. Then my plans for a book on Japan are but a quarter
finished. Then, my little woman would be very unhappy, I fear, away
from her people and her gods;—for this country is so strange that it
is impossible for any who have never lived here for a long time to
understand the enormous difference between the thought and
feeling of the Japanese and our own. But, later on, perhaps I must
go back for a time to see about getting out a book. Then I will
probably appeal to you for a year’s employ or something. The Orient
is more fascinating than you may suppose: here, remember, the
people really eat lotuses: they form a common article of diet. But no
human being can tell exactly what the future has in store for him. So
I cannot for the life of me say now what I shall do....
We are many years behind you here. In Matsue there is a little
newspaper of which I must send you a copy as a curiosity. Every
week or two there is an article in it about me. For “the foreigner’s”
every act is a subject for comment. There is no such thing in Japan
as privacy. There are no secrets. Every earthly thing a man does is
known to everybody, and life is extravagantly, astoundingly frank.
The moral effect is, in my opinion, extremely good,—though the
missionaries, who lie hard about this country, say the reverse. Think
of nothing but a paper screen dividing all your life from the lives
about you,—a paper screen to poke a hole through, which is not
considered outrageous, unless the screen be decorated with
celebrated paintings. That is common life here. As for me, I have a
secluded house, with three gardens round it. But, according to
popular custom, I must never shut the door, or lock myself up except
at night. One must not be nervous here, or impatient: it is
impossible to remain either in such an atmosphere, or to be ill-
natured, or to hide anything. And just think of it!—I having to give
lectures and make speeches through an interpreter, which lectures
and speeches are duly printed in a Japanese magazine! To speak
before a Japanese audience, however, is delightful. One look at all
the placid smiling faces reassures the most shrinking soul at once.
Well, at all events, I shall write you often, and send you something
queer betimes. I must now get ready to take the little steamer by
which I start.
With best regards to all, and to you best love, I remain,
Lafcadio Hearn.

This is my legal seal.

TO BASIL HALL CHAMBERLAIN


Yabase, August, 1891.

Dear Professor Chamberlain,—I have discovered Yabase. No European


seems to have ever been here before. On arriving at Shimo-ichi to
see the Bon-odori, I found I had come three days too soon, and the
little town is very hot and uncomfortable.
Well, Yabase is an extremely quiet, pretty little town, with a much
better hotel than I have seen for quite a while,—and a superb
beach. Strange to say, there are no boats and nobody ever thinks of
going into the sea, except children. So whenever I go to swim, the
entire population crowd the beach to look on. Happily I am a very
good swimmer,—could swim for twenty-four hours without fatigue.
Thus the people have a mezurashii mono to behold. Another queer
thing about Yabase is that it is the only place I have seen in Japan
where there is no shrine of Inari. It is a strictly Buddhist town, and
Nichiren prevails. There is a yashiro on a neighbouring mountain,
however. There is no Bon-odori here, one must go to the next town
to see it, which I will do to-night. There has been much rough
weather—tremendous seas breaking along the coast. At Kizuki I
thought the hotel was going to be carried away; and all the
approaches to it, bridges, etc., were dashed to pieces. Here, the sea
is opposed by a loftier coast, but it becomes something one cannot
laugh at on a windy day.
I must tell you an incident of the revival of pure Shintō. At Kizuki,
until very recently, two of the hotels were kept by families belonging
to some Buddhist sect, as well as to the Kizuki sect of Shintō, and so
in their establishments, as in nearly every Izumo household, there
was a butsudan as well as a kamidana. But some pilgrims who came
to Kizuki, full of fiery Shintō zeal, were wroth to see a butsudan in
the inns of the Sacred City, and girded up their loins, and sought out
an hotel where no Buddha was, and went there,—and sent out word
to their fellow pilgrims. The result has been that all the hotels in
Kizuki have suppressed Buddhism, or at least its externals: they
have become pure Shintō. This incident is rather anomalous, but it is
a confirmation of what I said before, regarding the predominance of
Shintō.
From Mionoseki, I hope to send you some o fuda of interest. The
prospects of getting to Oki are growing small, however,—for the time
being.

P.S. Alas! I have not discovered Yabase! Some detestable missionary


was here before me—for one hour only, it is true, but he was here!—
And to-day, being a day of high surf, there came down to the beach
with planks, divers boys, who swam far out and came in, as the
Americans say, “a-kite-ing,” on the crests of waves—swimming
unspeakably well, after the fashion of the Polynesian islanders. So
that I feel small! I offered to teach them what I know in exchange
for instruction as to how to come “a-kite-ing” on the top of a wave.
As for the little Japanese pipe:—
I cannot think that its form and dimensions simply evidence the
Japanese fondness for “small things.” The ancient Samurai pipes, of
which I have seen many fine specimens, were very much larger than
the modern kiseru. The pipe seems to me rather the natural
evolution of a utensil in its relation to the domestic life of Japan. The
little pipe is admirably adapted to the multifarious interruptions of
Japanese occupations. Long-sustained effort, protracted and
unbroken study, are things foreign to Japanese existence. The
Western pipe is good between the teeth of a man trained to remain
on duty without remission of mental labour or relaxation of muscle
for five or six hours at a stretch. But the Japanese idea of labour is
blessed and full of interruptions as his year is full of matsuri. Thus,
the little pipe, with its three conventional whiffs, exactly suits his
wants. Its artistic evolution is also a matter worthy of study. Some of
the best metal-work has been done upon it. From the pipe of 3 sen
to the pipe of 30 yen, there is as great a range of artistic design and
finish as in the realm of kakemono. Pipes of silver are the fashion.
Without engraving, the silver must be very heavy. If the two metal
parts be elaborately engraved and inlaid, the metal may be made as
light as possible. A really fine pipe becomes an heirloom.
The introduction of European costume among the class of officials
and teachers necessarily produced a change in the smoking
paraphernalia which formed a part of the native Japanese outfit. The
tabako-ire was reshaped, so as to accommodate itself to a breast or
side pocket, and the little pipe shortened so as to be enclosed
without the tobacco pouch, much as a pencil is enclosed in a pocket-
book. Many beautifully designed things thus came into existence. A
nice small pipe of silver may now be had to order for about 3 yen,—
(designed). The netsuke has, of course, no place in this form of the
tabako-ire. I have collected over a hundred different forms of the
new pipe. This has no bamboo: the whole thing is one solid piece of
metal. The best are inlaid or engraved:—the bowl and mouthpiece
(at least) being usually of silver, worked into steel or brass.
Pipes with long stems are preferable for house use. They do not
burn the tongue so quickly as the short pipe. However, the tobacco
itself has much to do with this matter. Those jōros, geishas, and
others, who smoke the greater part of the time, use a special
tobacco which does not blister the tongue or lips.
With the pipe for an evolutionary centre, a whole intricate and
complex world of smoking-furniture has come into existence,—of
which the richest specimens are perhaps those lacquered tabako-
bon for the use of aristocratic ladies, with plated or solid silver
hibachi and haifuki. The winter hibachi for smoking purposes has, of
course, many forms;—some of the daintiest being those invented for
use in theatres, to be carried in the hand. The smoker, who finds a
handsome bronze hibachi placed before him on a winter’s day, is not
supposed to empty his pipe into it by knocking the metal head of the
pipe upon the rim: if genteel, he will always insert the leather flap of
his tobacco pouch between the pipehead and the hibachi—so as to
prevent the tapping of the pipehead from causing a dent in the
bronze. At present the most genteel tabako-bon for summer use has
a small cup of bronze, instead of the usual cup of porcelain. The
smoker empties his pipe, not into the hibachi of bronze or porcelain,
but into the bamboo haifuki which is an indispensable part of the
summer tabako-bon.
The foreigner who uses the Japanese pipe commences his
experience with that apparently simple article by burning small
round holes in everything near him—the tatami, the zabuton, and
especially his own yukata or kimono. The small pellet of ignited
tobacco contained in the kiseru becomes, after a few whiffs, a fiery
pill, loose, and ready to leap from the pipe at a breath. Wherever it
falls, it pierces holes like a red-hot shot. But the Japanese expert
smoker rarely burns anything. He draws from his pipe at the very
most three whiffs and at once empties it into the haifuki. To smoke a
Japanese pipe to the bottom, moreover, results in clogging up the
pipe. The art of cleaning it out afterwards is quite elaborate. A
common plan is to heat the pipehead in the charcoal of the hibachi,
and then blow out the refuse. But this method corrodes and spoils a
fine pipe. The cleaning of the fine pipe must be done with a twist of
tough fine paper passed up the stem and pulled out through the
head.
Besides smoking-furniture, a special code of politeness has been
evolved around the Japanese pipe.
The pipe, I regret to say, is in vulgar circles used as a domestic rod.
The wife or child who is very naughty may receive a severe blow
with the kiseru, or even many. However, it is not so bad as the
instruments of punishment in vogue elsewhere.
I am not sure if I have been able to say anything worth your while
to read about the pipe, but I think the Japanese pipe is really worth
more consideration than is usually given it.
Note. Women’s pipes have a special, delicate form—and are made
very small and dainty—also their tabako-ire.

TO BASIL HALL CHAMBERLAIN


Yura, August, 1891.

Dear Professor Chamberlain,—If you are not frightfully busy, which I


suppose nobody is at this time of the year, perhaps some of my
adventures will interest you.
I found that the Bon-odori is different, not only in every village, but
even in every commune. So I was very anxious to see all the
varieties of this curious dance that I could. I heard that at Ōtsuka,
near Yabase, there was a very remarkable kind of dance danced;
and I went, in Japanese costume, with a dozen citizens of Yabase, to
see it. It turned out to be not worth seeing at all: the people had no
more knowledge of dancing—or rather, much less, than Sioux or
Comanches.
Ōtsuka is a stony, large, primitive-looking village,—full of rude
energy and, I am sorry to say, of bad manners,—a terrible thing to
say about any Japanese town. But I have been in about 50 Japanese
villages, where I loved all the people, and always made a few of
them love me, and Ōtsuka is the first exception I found to the
general rule about the relation between foreigners and hyakushō-no-
jin. At Ōtsuka the people left their dance to pelt the foreigner with
little pellets of sand and mud,—crying out: “Bikki!—bikki!” What that
means I do not know. So both I and the whole of the Yabase people
turned back. The pelting was not very savage—it was just like the
work of naughty children: a foreign mob would have thrown stones,
which these folk were very careful not to do—in spite of the fact that
there were no police. I passed through this village twice since, and
found the attitude of its people peculiarly rough—bordering upon
hostility. Compared with the roughness of—say a Barbadoes mob—it
was a very gentle thing, but it gave me the first decidedly
unpleasant sense of being an alien that I have ever had in Japan.
I have just returned from Togo-ike,—a place described in your
Guide.
Frankly, I detest Togo-ike. But it is extremely popular with travelling
Japanese—especially the shōbai. Imagine a valley of rice-fields,
ringed in by low jagged wooded hills, with a lakelet in the middle of
it about a mile and a quarter long (at most) by half a mile broad,
and hotels built out into the water. The coldest place I have yet been
in Japan. The hotels are supplied with hot water from the volcanic
springs through bamboo pipes, but the baths do not compare with
those of the much humbler Izumo resort—Tama-tsukuri. The cold air
to me was penetrating, sickly, but this may be idiosyncrasy. To one
who has lived in the tropics the chill of rice-fields means fever and
death; and some of my old tropical fears came up. Then the hotel
has only mishido, no karakami,—so that one is never alone. One
hour of Yabase is worth a season at Togo-ike—free of expense—to
one who loves quiet and simple ways. So I shall spend a couple
more days there before going to Mionoseki.
I have given up Oki, until winter. The health and strength I get from
seawater bathing have made me delay too long. But I will get to Oki
later.
Ever yours,
Lafcadio Hearn.
TO SENTARŌ NISHIDA
Yabase, August, 1891.

Dear Mr. Nishida,—I have had a pleasant time in different little


drowsy sea-villages,—sleeping, eating, drinking sake, and bathing.
Yabase is about the most pleasant place I ever stopped at here.
But, alas!—I saw no Bon-odori at all at Shimo-ichi. I seemed to have
gone too soon;—at Yabase, there is no Bon-odori; and at Ōtsuka,
where I next travelled, on foot, to see the Bon-odori, I had an
adventure of a peculiar kind.
Ōtsuka seems to be a rough sort of place. Its folk are big hustling
noisy countrymen; and when they are full of sake inclined to be
mischievous. They stopped dancing to see the foreigner. The
foreigner took refuge from the pressure of the crowd in a house,
where he sat upon the floor, and smoked. The crowd came into the
house and round the house, and uttered curious observations and
threw sand and water at the foreigner. Therefore the people of
Yabase, who had accompanied the foreigner to Ōtsuka, arose and
made vigorous protests; and we all returned to Yabase together. At
Yabase, the police and some of the principal people more than made
up to me for the rudeness of the Ōtsuka folk,— they apologized for
the Ōtsuka folk until I was really ashamed of being so kindly looked
after; and I was entertained very generously; and the police told me
that anything in the world I wished their advice or help about, only
to send them word. (The hostility of the Ōtsuka folk was really a
very childish sort of thing, not worth making a fuss about;—a
Western crowd would have thrown stones or rotten eggs. Indeed I
am not sure whether the crowd was really hostile at all. I rather
think that they wanted to see the foreigner move,—so they tried to
make him stir about,—like a kedamono in a cage.)
To-morrow I return to Matsue, by way of Mionoseki;—I really regret
leaving Yabase: the people are the kindest, most honest,
straightforward folk imaginable. And I have made several friends;—
at the temple of Nichiren here, I got some beautiful o fuda.
Lafcadio Hearn..

TO BASIL HALL CHAMBERLAIN


Matsue, August, 1891.

Dear Professor Chamberlain,—Having reached a spot where I can write


upon something better than a matted floor, I find three most
pleasant letters from you. The whole of the questions in them I
cannot answer to-night, but will do so presently, when I obtain the
full information.
However, as to cats’ tails I can answer at once. Izumo cats—(and I
was under the impression until recently that all Japanese cats were
alike)—are generally born with long tails. But there is a belief that
any cat whose tail is not cut off in kittenhood, will become an obake
or a nekomata, and there are weird stories about cats with long tails
dancing at night, with towels tied round their heads. There are
stories about petted cats eating their mistress and then assuming
the form, features, and voice of the victim. Of course you know the
Buddhist tradition that no cat can enter paradise. The cat and the
snake alone wept not for the death of Buddha. Cats are unpopular in
Izumo, but in Hōki I saw that they seemed to exist under more
favourable conditions. The real reason for the unpopularity of the cat
is its powers of mischief in a Japanese house;—it tears the tatami,
the karakami, the shōji, scratches the woodwork, and insists upon
carrying its food into the best room to eat it upon the floor. I am a
great lover of cats, having “raised,” as the Americans say, more than
fifty;—but I could not gratify my desire to have a cat here. The
creature proved too mischievous, and wanted always to eat my
uguisu.
The oscillation of one’s thoughts concerning the Japanese—the
swaying you describe—is and has for some time been mine also.
There are times when they seem so small! And then again, although
they never seem large, there is a vastness behind them,—a past of
indefinite complexity and marvel,—an amazing power of absorbing
and assimilating,—which forces one to suspect some power in the
race so different from our own that one cannot understand that
power. And as you say, whatever doubts or vexations one has in
Japan, it is only necessary to ask one’s self:—“Well, who are the best
people to live with?” For it is a question whether the intellectual
pleasures of social life abroad are not more than dearly bought at
the cost of social pettinesses which do not seem to exist in Japan at
all.
Would you be horrified to learn that I have become passionately
fond of daikon,—not the fresh but the strong ancient pickled daikon?
But then the European Stilton cheese, or Limburger, is surely quite
as queer. I have become what they call here a jōgo,—and find that a
love of sake creates a total change in all one’s eating habits and
tastes. All the sweet things the geko likes, I cannot bear when
taking sake. By the way, what a huge world of etiquette, art, taste,
custom, has been developed by sake. An article upon sake,—its
social rules,—its vessels,—its physiological effects,—in short the
whole romance and charm of a Japanese banquet, ought to be
written by somebody. I hope to write one some day, but I am still
learning.

As to Dr. Tylor and the anthropological institute. If he should want


any paper that I could furnish, I would be glad and consider myself
honoured to please him. As for your question about the o fuda, why,
I should think it no small pleasure to be mentioned merely as one of
your workers and friends. Though the little I have been able to send
does not seem to me to deserve your kindest words, it is making me
very happy to have been able to please you at all. Whatever I can
write or send, make always any use of you please.
About “seeing Japan from a distance,”—I envy you your coming
chance. I could not finish my book on the West Indies until I saw the
magical island again through regret, as through a summer haze,—
and under circumstances which left me perfectly free to think, which
the soporific air of the tropics makes difficult. (Still the book is not
what it ought to be, for I was refused all reasonable help, and wrote
most of it upon a half-empty stomach, or with my blood full of fever.)
But to think of Japan in an English atmosphere will be a delicious
experience for you after so long an absence. I should not be
surprised should the experience result in the creation of something
which would please your own feelings as an author better than any
other work you have made. Of course it is at the time one is best
pleased that one does one’s real best in the artistic line.
By the way, since you like those Shintō prints,—and I might get you
others,—what about a possible edition of your “Kojiki” illustrated by
Japanese conceptions of this kind, colours and all? Such work can be
so cheaply done in Japan! And an index! How often I wished for an
index. I have made an imperfect one of my own. It is believed here
that Hahaki is the ancient name of the modern Hōki. I was told this
when I wanted to go to the legendary burial-place of Izanami.
As usual, I find I have been too presumptuous in writing offhand
about cats’ tails. On enquiring, I learn that there are often, born of
the same mother, Izumo kittens with short tails, and kittens with
long tails. This would show that two distinct species of cats exist
here. The long-tailed kittens are always deprived when possible of
the larger part of their caudal appendage. The short tails are spared.
If an old cat be seen with a short tail, people say,—“this cat is old,
but she has a short tail: therefore she is a good cat.” (For the obake
cat gets two tails when old, and every wicked cat has a long tail.) I
am told that at the recent bon, in Matsue, cats of the evil sort were
seen to dance upon the roofs of the houses.
What you tell me about those Shintō rituals and their suspicious
origin seems to me quite certainly true. So the kara-shishi and the
mon and the dragon-carvings and the tōrōs,—all stare me in the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like