0% found this document useful (1 vote)
30 views

Real World Python A Hacker s Guide to Solving Problems with Code 1st Edition Lee Vaughan - Download the ebook today and own the complete content

The document promotes an extensive collection of ebooks available for download at textbookfull.com, including titles like 'Real World Python' by Lee Vaughan and 'Statistics With R' by Jenine K Harris. It highlights the convenience of accessing various formats such as PDF, ePub, and MOBI for reading on any device. The document also provides links to specific books and encourages users to explore the collection for instant downloads.

Uploaded by

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

Real World Python A Hacker s Guide to Solving Problems with Code 1st Edition Lee Vaughan - Download the ebook today and own the complete content

The document promotes an extensive collection of ebooks available for download at textbookfull.com, including titles like 'Real World Python' by Lee Vaughan and 'Statistics With R' by Jenine K Harris. It highlights the convenience of accessing various formats such as PDF, ePub, and MOBI for reading on any device. The document also provides links to specific books and encourages users to explore the collection for instant downloads.

Uploaded by

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

Explore the full ebook collection and download it now at textbookfull.

com

Real World Python A Hacker s Guide to Solving


Problems with Code 1st Edition Lee Vaughan

https://textbookfull.com/product/real-world-python-a-hacker-
s-guide-to-solving-problems-with-code-1st-edition-lee-
vaughan/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Statistics With R Solving Problems Using Real World Data


1st Edition Jenine K Harris

https://textbookfull.com/product/statistics-with-r-solving-problems-
using-real-world-data-1st-edition-jenine-k-harris/

textbookfull.com

Optimization in the Real World Toward Solving Real World


Optimization Problems 1st Edition Katsuki Fujisawa

https://textbookfull.com/product/optimization-in-the-real-world-
toward-solving-real-world-optimization-problems-1st-edition-katsuki-
fujisawa/
textbookfull.com

Impractical Python Projects Playful Programming Activities


to Make You Smarter 1st Edition Lee Vaughan

https://textbookfull.com/product/impractical-python-projects-playful-
programming-activities-to-make-you-smarter-1st-edition-lee-vaughan/

textbookfull.com

Impractical Python Projects Playful Programming Activities


to Make You Smarter 1st Edition Lee Vaughan

https://textbookfull.com/product/impractical-python-projects-playful-
programming-activities-to-make-you-smarter-1st-edition-lee-vaughan-2/

textbookfull.com
Quantum Computing Solutions: Solving Real-World Problems
Using Quantum Computing and Algorithms 1st Edition Bhagvan
Kommadi
https://textbookfull.com/product/quantum-computing-solutions-solving-
real-world-problems-using-quantum-computing-and-algorithms-1st-
edition-bhagvan-kommadi/
textbookfull.com

Begin to Code with Python Rob Miles

https://textbookfull.com/product/begin-to-code-with-python-rob-miles/

textbookfull.com

Math Adventures with Python An Illustrated Guide to


Exploring Math with Code 1st Edition Peter Farrell

https://textbookfull.com/product/math-adventures-with-python-an-
illustrated-guide-to-exploring-math-with-code-1st-edition-peter-
farrell/
textbookfull.com

Applied Computational Thinking with Python Algorithm


design for complex real world problems 2nd Edition Sofía
De Jesús | Dayrene Martinez
https://textbookfull.com/product/applied-computational-thinking-with-
python-algorithm-design-for-complex-real-world-problems-2nd-edition-
sofia-de-jesus-dayrene-martinez/
textbookfull.com

Learn Python Programming A beginner s guide to learning


the fundamentals of Python language to write efficient
high quality code Romano
https://textbookfull.com/product/learn-python-programming-a-beginner-
s-guide-to-learning-the-fundamentals-of-python-language-to-write-
efficient-high-quality-code-romano/
textbookfull.com
RE AL WORLD
PY THON
A H A C K E R ’ S G U I D E TO
S O L V I N G P R O B L E M S W ITH CODE

LEE VAUGHAN
REAL-WORLD PYTHON
REAL-WORLD
PYTHON
A Hacker’s Guide to
Solving Problems with Code

by Lee Vaughan

San Francisco
REAL-WORLD PYTHON. Copyright © 2021 by Lee Vaughan.

All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.

ISBN-13: 978-1-7185-0062-4 (print)


ISBN-13: 978-1-7185-0063-1 (ebook)

Publisher: William Pollock


Executive Editor: Barbara Yien
Production Editor: Kassie Andreadis
Developmental Editor: Frances Saux
Project Editor: Dapinder Dosanjh
Cover Illustrator: Rob Gale
Interior Design: Octopod Studios
Technical Reviewers: Chris Kren and Eric Mortenson
Copyeditor: Kim Wimpsett
Compositor: Shawn Morningstar
Proofreader: Paula L. Fleming
Indexer: Beth Nauman-Montana

The following images are reproduced with permission: Figure 3-3 from istockphoto.com; Figure 5-1 courtesy
of Lowell Observatory Archives; Figures 5-2, 6-2, 7-6, 7-7, 8-18, and 11-2 courtesy of Wikimedia Commons;
Figures 7-2, 7-9, 7-17, 8-20, and 11-1 courtesy of NASA; Figure 8-1 photo by Evan Clark; Figure 8-4 photo by
author; Figure 9-5 from pixelsquid.com; Figure 11-9 photo by Hannah Vaughan

For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1-415-863-9900; info@nostarch.com
www.nostarch.com

Library of Congress Cataloging-in-Publication Data


Names: Vaughan, Lee, author.
Title: Real-world python: a hacker’s guide to solving problems with code / Lee Vaughan.
Description: San Francisco, CA : No Starch Press, Inc., [2020] | Includes
index.
Identifiers: LCCN 2020022671 (print) | LCCN 2020022672 (ebook) | ISBN
9781718500624 (paperback) | ISBN 1718500629 (paperback) | ISBN
9781718500631 (ebook)
Subjects: LCSH: Python (Computer program language)
Classification: LCC QA76.73.P98 V383 2020 (print) | LCC QA76.73.P98
(ebook) | DDC 005.1/33--dc23
LC record available at https://lccn.loc.gov/2020022671
LC ebook record available at https://lccn.loc.gov/2020022672

No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other prod-
uct and company names mentioned herein may be the trademarks of their respective owners. Rather than use
a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial
fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The information in this book is distributed on an “As Is” basis, without warranty. While every precaution
has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in it.
For my uncle, Kenneth P. Vaughan.
He brightened every room he entered.
About the Author
Lee Vaughan is a programmer, pop culture enthusiast, educator, and author
of Impractical Python Projects (No Starch Press, 2018). As an executive-level
scientist at ExxonMobil, he constructed and reviewed computer models,
developed and tested software, and trained geoscientists and engineers.
He wrote both Impractical Python Projects and Real-World Python to help
self-learners hone their Python skills and have fun doing it!

About the Technical Reviewers


Chris Kren graduated from the University of South Alabama with an M.S. in
Information Systems. He currently works in the field of cybersecurity and
often uses Python for reporting, data analysis, and automation.
Eric Mortenson has a PhD in mathematics from the University of Wisconsin
at Madison. He has held research and teaching positions at The Pennsylvania
State University, The University of Queensland, and the Max Planck Institute
for Mathematics. He is an associate professor in mathematics at St. Petersburg
State University.
BRIEF CONTENTS

Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix

Chapter 1: Saving Shipwrecked Sailors with Bayes’ Rule . . . . . . . . . . . . . . . . . . . . . . . . 1

Chapter 2: Attributing Authorship with Stylometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

Chapter 3: Summarizing Speeches with Natural Language Processing . . . . . . . . . . . . . 51

Chapter 4: Sending Super-Secret Messages with a Book Cipher . . . . . . . . . . . . . . . . . . 77

Chapter 5: Finding Pluto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

Chapter 6: Winning the Moon Race with Apollo 8 . . . . . . . . . . . . . . . . . . . . . . . . . . 123

Chapter 7: Selecting Martian Landing Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151

Chapter 8: Detecting Distant Exoplanets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177

Chapter 9: Identifying Friend or Foe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203

Chapter 10: Restricting Access with Face Recognition . . . . . . . . . . . . . . . . . . . . . . . . 225

Chapter 11: Creating an Interactive Zombie Escape Map . . . . . . . . . . . . . . . . . . . . . 245

Chapter 12: Are We Living in a Computer Simulation? . . . . . . . . . . . . . . . . . . . . . . . 269

Appendix: Practice Project Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
CONTE NT S IN DE TA IL

ACKNOWLEDGMENTS xvii

INTRODUCTION xix
Who Should Read This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Why Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
What’s in This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Python Version, Platform, and IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Running Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
Using a Virtual Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Onward! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv

1
SAVING SHIPWRECKED SAILORS WITH BAYES’ RULE 1
Bayes’ Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Project #1: Search and Rescue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Installing the Python Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Bayes Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Playing the Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Challenge Project: Smarter Searches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Challenge Project: Finding the Best Strategy with MCS . . . . . . . . . . . . . . . . . . . . . . . . 25
Challenge Project: Calculating the Probability of Detection . . . . . . . . . . . . . . . . . . . . . . 25

2
ATTRIBUTING AUTHORSHIP WITH STYLOMETRY 27
Project #2: The Hound, The War, and The Lost World . . . . . . . . . . . . . . . . . . . . . . . . . 28
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Installing NLTK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Corpora . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Stylometry Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Practice Project: Hunting the Hound with Dispersion . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Practice Project: Punctuation Heatmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Challenge Project: Fixing Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3
SUMMARIZING SPEECHES WITH NATURAL
LANGUAGE PROCESSING 51
Project #3: I Have a Dream . . . to Summarize Speeches! . . . . . . . . . . . . . . . . . . . . . . 52
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Web Scraping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
The “I Have a Dream” Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Project #4: Summarizing Speeches with gensim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Installing gensim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
The Make Your Bed Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Project #5: Summarizing Text with Word Clouds . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
The Word Cloud and PIL Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
The Word Cloud Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Fine-Tuning the Word Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Challenge Project: Game Night . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Challenge Project: Summarizing Summaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Challenge Project: Summarizing a Novel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Challenge Project: It’s Not Just What You Say,
It’s How You Say It! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

4
SENDING SUPER-SECRET MESSAGES WITH A BOOK CIPHER 77
The One-Time Pad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
The Rebecca Cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Project #6: The Digital Key to Rebecca . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The Encryption Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Sending Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Practice Project: Charting the Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Practice Project: Sending Secrets the WWII Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

5
FINDING PLUTO 95
Project #7: Replicating a Blink Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
The Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
The Blink Comparator Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Using the Blink Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Project #8: Detecting Astronomical Transients with Image Differencing . . . . . . . . . . . . 112
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
The Transient Detector Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Using the Transient Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Practice Project: Plotting the Orbital Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

xii   Contents in Detail
Practice Project: What’s the Difference? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Challenge Project: Counting Stars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

6
WINNING THE MOON RACE WITH APOLLO 8 123
Understanding the Apollo 8 Mission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
The Free Return Trajectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
The Three-Body Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Project #9: To the Moon with Apollo 8! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Using the turtle Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
The Apollo 8 Free Return Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Running the Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Practice Project: Simulating a Search Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Practice Project: Start Me Up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Practice Project: Shut Me Down! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Challenge Project: True-Scale Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Challenge Project: The Real Apollo 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149

7
SELECTING MARTIAN LANDING SITES 151
How to Land on Mars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
The MOLA Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Project #10: Selecting Martian Landing Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
The Site Selector Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Practice Project: Confirming That Drawings Become Part of an Image . . . . . . . . . . . . . 172
Practice Project: Extracting an Elevation Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Practice Project: Plotting in 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Practice Project: Mixing Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Challenge Project: Making It Three in a Row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Challenge Project: Wrapping Rectangles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175

8
DETECTING DISTANT EXOPLANETS 177
Transit Photometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Project #11: Simulating an Exoplanet Transit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
The Transit Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Experimenting with Transit Photometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Project #12: Imaging Exoplanets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
The Pixelator Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189

Contents in Detail   xiii
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Practice Project: Detecting Alien Megastructures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Practice Project: Detecting Asteroid Transits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Practice Project: Incorporating Limb Darkening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Practice Project: Detecting Starspots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Practice Project: Detecting an Alien Armada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Practice Project: Detecting a Planet with a Moon . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Practice Project: Measuring the Length of an Exoplanet’s Day . . . . . . . . . . . . . . . . . . . 201
Challenge Project: Generating a Dynamic Light Curve . . . . . . . . . . . . . . . . . . . . . . . . 202

9
IDENTIFYING FRIEND OR FOE 203
Detecting Faces in Photographs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Project #13: Programming a Robot Sentry Gun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Detecting Faces from a Video Stream . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Practice Project: Blurring Faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Challenge Project: Detecting Cat Faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223

10
RESTRICTING ACCESS WITH FACE RECOGNITION 225
Recognizing Faces with Local Binary Pattern Histograms . . . . . . . . . . . . . . . . . . . . . . 226
The Face Recognition Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Extracting Local Binary Pattern Histograms . . . . . . . . . . . . . . . . . . . . . . . . . 228
Project #14: Restricting Access to the Alien Artifact . . . . . . . . . . . . . . . . . . . . . . . . . . 231
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Supporting Modules and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
The Video Capture Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
The Face Trainer Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
The Face Predictor Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Challenge Project: Adding a Password and Video Capture . . . . . . . . . . . . . . . . . . . . 242
Challenge Project: Look-Alikes and Twins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Challenge Project: Time Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243

11
CREATING AN INTERACTIVE ZOMBIE ESCAPE MAP 245
Project #15: Visualizing Population Density with a Choropleth Map . . . . . . . . . . . . . . 246
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
The Python Data Analysis Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
The bokeh and holoviews Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Installing pandas, bokeh, and holoviews . . . . . . . . . . . . . . . . . . . . . . . . . . . 250

xiv   Contents in Detail
Accessing the County, State, Unemployment, and Population Data . . . . . . . . . 250
Hacking holoviews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
The Choropleth Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Planning the Escape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Challenge Project: Mapping US Population Change . . . . . . . . . . . . . . . . . . . . . . . . . 266

12
ARE WE LIVING IN A COMPUTER SIMULATION? 269
Project #16: Life, the Universe, and Yertle’s Pond . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
The Pond Simulation Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Implications of the Pond Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Measuring the Cost of Crossing the Lattice . . . . . . . . . . . . . . . . . . . . . . . . . 275
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Moving On . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Challenge Project: Finding a Safe Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Challenge Project: Here Comes the Sun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Challenge Project: Seeing Through a Dog’s Eyes . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: Customized Word Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: Simplifying a Celebration Slideshow . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: What a Tangled Web We Weave . . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: Go Tell It on the Mountain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

APPENDIX
PRACTICE PROJECT SOLUTIONS 283
Chapter 2: Attributing Authorship with Stylometry . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Hunting the Hound with Dispersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Punctuation Heatmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Chapter 4: Sending Super-Secret Messages with a Book Cipher . . . . . . . . . . . . . . . . . 285
Charting the Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Sending Secrets the WWII Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Chapter 5: Finding Pluto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Plotting the Orbital Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
What’s the Difference? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Chapter 6: Winning the Moon Race with Apollo 8 . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Simulating a Search Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Start Me Up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Shut Me Down! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Chapter 7: Selecting Martian Landing Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Confirming That Drawings Become Part of an Image . . . . . . . . . . . . . . . . . . 298
Extracting an Elevation Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Plotting in 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Mixing Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Chapter 8: Detecting Distant Exoplanets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Detecting Alien Megastructures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Detecting Asteroid Transits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305

Contents in Detail   xv
Incorporating Limb Darkening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Detecting an Alien Armada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Detecting a Planet with a Moon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Measuring the Length of an Exoplanet’s Day . . . . . . . . . . . . . . . . . . . . . . . . 311
Chapter 9: Identifying Friend or Foe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Blurring Faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Chapter 10: Restricting Access with Face Recognition . . . . . . . . . . . . . . . . . . . . . . . . 312
Challenge Project: Adding a Password and Video Capture . . . . . . . . . . . . . . 312

INDEX 315

xvi   Contents in Detail
ACKNOWLEDGMENTS

Despite operating during a global pandemic, the team at No Starch Press


delivered another excellent effort at book making. They are professionals
without peer, and this book would not exist without them. They have my
deepest gratitude and respect.
Thanks also to Chris Kren and Eric Evenchick for their code reviews,
Joseph B. Paul and Sarah and Lora Vaughan for their cosplay enthusiasm,
and Hannah Vaughan for supplying useful photographs.
Special thanks to Eric T. Mortenson for his meticulous technical reviews
and many helpful suggestions and additions. Eric proposed the chapter on
Bayes’ Rule and supplied numerous practice and challenge projects including
applying Monte Carlo simulation to Bayes, summarizing a novel by chapter,
modeling interactions between the moon and Apollo 8, viewing Mars in 3D,
calculating the light curve for an exoplanet with an orbiting moon, and more.
This book is immensely better for his efforts.
Finally, thanks to all the contributors to stackoverflow.com. One of the
best things about Python is its extensive and inclusive user community. No
matter what question you may have, someone can answer it; no matter what
strange thing you want to do, someone has probably done it before, and you
can find them on Stack Overflow.
INTRODUCTION

If you’ve learned the basics of coding in


Python, you’re ready to write complete
programs that take on real-world tasks.
In Real-World Python, you’ll write programs to
win the moon race with Apollo 8, help Clyde Tombaugh
discover Pluto, select landing sites for a Mars rover,
locate exoplanets, send super-secret messages to your
friends, battle monstrous mutants, save shipwrecked
sailors, escape the walking dead, and more, all using the
Python programming language. In the process, you’ll
apply powerful computer vision, natural language pro-
cessing, and scientific modules, such as OpenCV, NLTK,
NumPy, pandas, and matplotlib, as well as a host of other
packages designed to make your computing life easier.
Who Should Read This Book?
You can think of this as a sophomore Python book. It isn’t a tutorial on
programming basics but rather a way for you to continue training using a
project-based approach. This way, you won’t have to waste your money or
shelf space rehashing concepts you’ve already learned. I’ll still explain every
step of the projects, and you’ll receive detailed instructions about using the
libraries and modules, including how to install them.
These projects will appeal to anyone who wants to use programming
to conduct experiments, test theories, simulate nature, or just have fun. As
you work through them, you’ll increase your knowledge of Python libraries
and modules and learn handy shortcuts, useful functions, and helpful tech-
niques. Rather than focus on isolated modular code snippets, these projects
teach you how to build complete, working programs involving real-world
applications, datasets, and issues.

Why Python?
Python is a high-level, interpretive, general-purpose programming language.
It’s free, highly interactive, and portable across all major platforms and micro-
controllers such as the Raspberry Pi. Python supports both functional and
object-oriented programming and can interact with code written in many
other programming languages, such as C++.
Because Python is accessible to beginners and useful to experts, it has
penetrated schools, universities, large corporations, financial institutions,
and most, if not all, fields of science. As a result, it’s now the most popular
language for machine learning, data science, and artificial intelligence
applications.

What’s in This Book?


The following is an overview of the chapters in this book. You don’t have
to work through them sequentially, but I’ll explain new modules and tech-
niques more thoroughly when they’re first introduced.
Chapter 1: Saving Shipwrecked Sailors with Bayes’ Rule Use Bayesian
probability to efficiently direct Coast Guard search and rescue efforts
off Cape Python. Gain experience with OpenCV, NumPy, and the itertools
module.
Chapter 2: Attributing Authorship with Stylometry Use natural language
processing to determine whether Sir Arthur Conan Doyle or H. G. Wells
wrote the novel The Lost World. Gain experience with NLTK, matplotlib,
and stylometric techniques such as stop words, parts of speech, lexical
richness, and Jaccard similarity.
Chapter 3: Summarizing Speeches with Natural Language Processing
Scrape famous speeches off the internet and automatically produce
a summary of the salient points. Then turn the text of a novel into a

xx   Introduction 
cool display for advertising or promotional material. Gain experience
with BeautifulSoup, Requests, regex, NLTK, Collections, wordcloud, and
matplotlib.
Chapter 4: Sending Super-Secret Messages with a Book Cipher Share
unbreakable ciphers with your friends by digitally reproducing the one-
time pad approach used in Ken Follet’s best-selling spy novel, The Key to
Rebecca. Gain experience with the Collections module.
Chapter 5: Finding Pluto Reproduce the blink comparator device
used by Clyde Tombaugh to discover Pluto in 1930. Then use modern
computer vision techniques to automatically find and track subtle tran-
sients, such as comets and asteroids, moving against a starfield. Gain
experience with OpenCV and NumPy.
Chapter 6: Winning the Moon Race with Apollo 8 Take the gamble
and help America win the moon race with Apollo 8. Plot and execute
the clever free return flight path that convinced NASA to go to the moon
a year early and effectively killed the Soviet space program. Gain expe-
rience using the turtle module.
Chapter 7: Selecting Martian Landing Sites Scope out potential land-
ing sites for a Mars lander based on realistic mission objectives. Display
the candidate sites on a Mars map, along with a summary of site statis-
tics. Gain experience with OpenCV, the Python Imaging Library, NumPy,
and tkinter.
Chapter 8: Detecting Distant Exoplanets Simulate an exoplanet’s
passing before its sun, plot the resulting changes in relative brightness,
and estimate the diameter of the planet. Finish by simulating the direct
observation of an exoplanet by the new James Webb Space Telescope,
including estimating the length of the planet’s day. Use OpenCV, NumPy,
and matplotlib.
Chapter 9: Identifying Friend or Foe Program a robot sentry gun
to visually distinguish between Space Force Marines and evil mutants.
Gain experience with OpenCV, NumPy, playsound, pyttsxw, and datetime.
Chapter 10: Restricting Access with Face Recognition Restrict access
to a secure lab using face recognition. Use OpenCV, NumPy, playsound,
pyttsxw, and datetime.
Chapter 11: Creating an Interactive Zombie Escape Map Build a pop-
ulation density map to help the survivors in the TV show The Walking Dead
escape Atlanta for the safety of the American West. Gain experience
with pandas, bokeh, holoviews, and webbrowser.
Chapter 12: Are We Living in a Computer Simulation? Identify a way
for simulated beings—perhaps us—to find evidence that they’re living
in a computer simulation. Use turtle, statistics, and perf_counter.
Each chapter ends with at least one practice or challenge project. You
can find solutions to the practice projects in the appendix or online. These
aren’t the only solutions, or necessarily the best ones; you may come up with
better ones on your own.

Introduction   xxi
When it comes to the challenge projects, however, you’re on your own.
It’s sink or swim, which is a great way to learn! My hope is that this book
motivates you to create new projects, so think of the challenge projects as
seeds for the fertile ground of your own imagination.
You can download all of the book’s code, including solutions to the
practice projects, from the book’s website at https://nostarch.com/real-world
-python/. You’ll also find the errata sheet there, along with any other updates.
It’s almost impossible to write a book like this without some initial errors.
If you see a problem, please pass it on to the publisher at errata@nostarch.com.
We’ll add any necessary corrections to the errata and include the fix in future
printings of the book, and you will gain eternal glory.

Python Version, Platform, and IDE


I built all the projects in this book with Python v3.7.2 in a Microsoft
Windows 10 environment. If you’re using a different operating system,
no problem: I suggest compatible modules for other platforms, where
appropriate.
The code examples in this book are from either the Python IDLE text
editor or the interactive shell. IDLE stands for integrated development and
learning environment. It’s an integrated development environment (IDE) with an
L added so that the acronym references Eric Idle of Monty Python fame. The
interactive shell, also called the interpreter, is a window that lets you immedi-
ately execute commands and test code without needing to create a file.
IDLE has numerous drawbacks, such as the lack of a line-number column,
but it’s free and bundled with Python, so everyone has access to it. You’re
welcome to use whichever IDE you want. Popular choices include Visual
Studio Code, Atom, Geany (pronounced “genie”), PyCharm, and Sublime
Text. These work with a wide range of operating systems, including Linux,
macOS, and Windows. Another IDE, PyScripter, works only with Windows.
For an extensive listing of available Python editors and compatible platforms,
visit https://wiki.python.org/moin/PythonEditors/.

Installing Python
You can choose to install Python directly on your machine or through a
distribution. To install directly, find the installation instructions for your
operating system at https://www.python.org/downloads/. Linux and macOS
machines usually come with Python preinstalled, but you may want to upgrade
this installation. With each new Python release, some features are added and
some are deprecated, so I recommend upgrading if your version predates
Python v3.6.
The download button on the Python site (Figure 1) may install 32-bit
Python by default.

xxii   Introduction 
Figure 1: Downloads page for Python.org, with the “easy button” for the Windows platform

If you want the 64-bit version, scroll down to the listing of specific
releases (Figure 2) and click the link with the same version number.

Figure 2: Listing of specific releases from the Python.org downloads page

Clicking the specific release will take you to the screen shown in
Figure 3. From here, click the 64-bit executable installer, which will launch
an installation wizard. Follow the wizard directions and take the default
suggestions.

Figure 3: File listing for Python 3.8.2 version on Python.org

Introduction   xxiii
Some of the projects in this book call for nonstandard packages that
you’ll need to install individually. This isn’t difficult, but you can make
things easier by installing a Python distribution that efficiently loads and
manages hundreds of Python packages. Think of this as one-stop shopping.
The package managers in these distributions will automatically find and
download the latest version of a package, including all of its dependencies.
Anaconda is a popular free distribution of Python provided by
Continuum Analytics. You can download it from https://www.anaconda.com/.
Another is Enthought Canopy, though only the basic version is free. You
can find it at https://www.enthought.com/product/canopy/. Whether you install
Python and its packages individually or through a distribution, you should
encounter no problems working through the projects in the book.

Running Python
After installation, Python should show up in your operating system’s list of
applications. When you launch it, the shell window should appear (shown
in the background of Figure 4). You can use this interactive environment
to run and test code snippets. But to write larger programs, you’ll use a text
editor, which lets you save your code, as shown in Figure 4 (foreground).

Figure 4: The native Python shell window (background) and text editor (foreground)

To create a new file in the IDLE text editor, click File4New File.
To open an existing file, click File4 Open or File4Recent Files. From
here, you can run your code by clicking Run4Run Module or by pressing
F5 after clicking in the editor window. Note that your environment may
look different from Figure 4 if you chose to use a package manager like
Anaconda or an IDE like PyCharm.

xxiv   Introduction 
You can also start a Python program by typing the program name in
PowerShell or Terminal. You’ll need to be in the directory where your Python
program is located. For example, if you didn’t launch the Windows PowerShell
from the proper directory, you’ll need to change the directory path using
the cd command (Figure 5).

Figure 5: Changing directories and running a Python program in the Windows PowerShell

To learn more, see https://pythonbasics.org/execute-python-scripts/.

Using a Virtual Environment


Finally, you may want to install the dependencies for each chapter in a sepa-
rate virtual environment. In Python, a virtual environment is a self-contained
directory tree that includes a Python installation and a number of addi-
tional packages. They’re useful when you have multiple versions of Python
installed, as some packages may work with one version but break with others.
Additionally, it’s possible to have projects that need different versions of the
same package. Keeping these installations separate prevents compatibility
issues.
The projects in this book don’t require the use of virtual environments,
and if you follow my instructions, you’ll install the required packages system-
wide. However, if you do need to isolate the packages from your operating
system, consider installing a different virtual environment for each chapter
of the book (see https://docs.python.org/3.8/library/venv.html#module-venv and
https://docs.python.org/3/tutorial/venv.html).

Onward!
Many of the projects in this book rely on statistical and scientific concepts
that are hundreds of years old but impractical to apply by hand. But with
the introduction of the personal computer in 1975, our ability to store, pro-
cess, and share information has increased by many orders of magnitude.
In the 200,000-year history of modern humans, only those of us living
in the last 45 years have had the privilege of using this magical device and
realizing dreams long out of reach. To quote Shakespeare, “We few. We
happy few.”
Let’s make the most of the opportunity. In the pages that follow, you’ll
easily accomplish tasks that frustrated past geniuses. You’ll scratch the surface
of some of the amazing feats we’ve recently achieved. And you might even
start to imagine discoveries yet to come.

Introduction   xxv
1
SAVING SHIPWRECKED SAILORS
W I T H B AY E S’ R U L E

Sometime around 1740, an English


Presbyterian minister named Thomas Bayes
decided to mathematically prove the existence
of God. His ingenious solution, now known as
Bayes’ rule, would become one of the most successful
statistical concepts of all time. But for 200 years it
languished, largely ignored, because its tedious math-
ematics were impractical to do by hand. It took the
invention of the modern computer for Bayes’ rule to
reach its full potential. Now, thanks to our fast pro-
cessors, it forms a key component of data science and
machine learning.
Another Random Document on
Scribd Without Any Related Topics
"Had to spend a night there, sir," was, the reply. "Forced landing.
They gave me a cubicle that was more like a condemned cell.
Concrete walls and floor dripping with moisture; not even a mat on
the floor; a bedstead without a mattress and only two blankets. No
other furniture. In the morning I had the worst breakfast I ever had
on this side of the North Sea. Filthy margarine, rancid bacon and
weak tea; and they took jolly good care to make me plank down half
a dollar on the nail for my breakfast. Ugh! Makes me shudder to
think of it."

"Sheerness," remarked the captain, returning to the attack. "You


must know Smithers, then? A big, fat chap, with a mole just under
his eye. He's been quartermaster there since '16."

Von Preussen acknowledged that he knew the quartermaster. He


could not very well have denied it in the face of his inquisitor's
remarks.

"And Tomlinson?" continued the latter. "Suppose he's still there, but
I haven't heard from him recently. A short, very dark-featured old
bean, with a very dry sense of humour. Plays 'pack and brag' every
available five minutes, and uses most atrocious language when he's
put out and when he isn't."

"Tomlinson was sent to Dunkirk last month," declared von Preussen


mendaciously; then, eager to change what was a most distasteful
and embarrassing topic, he inquired:

"Is there a decent theatre at Auldhaig?"

"Not bad," replied Captain Cumberleigh—for that was the name of


von Preussen's heckler. "'Maid of the Mountains' is on to-night. Seen
it? Then, by Jove, you must, you priceless old thing!" he exclaimed
effusively. "No, we won't take a refusal. We've booked a box, and
you simply must come. After your fruitless journey to inspect those
X-lighters, you owe yourself some relaxation. And I say, Jefferson,"
he continued, addressing a lieutenant across the table, "we'll take
Fennelburt out fishing this afternoon, just to kill time. Fine sport just
off the harbour."

"I ought to be on my way back," protested von Preussen, as he


weighed up the possible advantages and disadvantages of remaining
at Auldhaig Air Station.

"Rot, you conscientious old blighter!" said Cumberleigh


boisterously. "In any case, you wouldn't get further than Edinburgh
to-night. We'll fix you up with a cabin, and you'll be all O.K., old
bean!"

CHAPTER IX
HOW THE LIGHTERS FARED

"Hope the brutes won't konk," thought Sub-lieutenant Jock


McIntosh, R.N.V.R., as he dispassionately surveyed the unlovely
outlines of X-lighters 5 and 6.

After being second-in-command of a crack M.L., McIntosh felt no


violent enthusiasm over his job—to take the two cumbersome craft
to a strange port eighty odd miles along the coast. At a maximum
speed of five knots, it meant a sixteen hours' run; but McIntosh,
knowing the vagaries of the X-lighters' motors, refrained from being
sanguine on the matter.

It was one of the jobs that fall to all branches of the Navy. With a
strange crew, and not having navigated a lighter before, McIntosh
was taking on "some stunt." He had charts and navigating
instruments, but he would have felt easier in his mind had he
possessed "local knowledge" of this part of the coast. On an M.L.,
where he was under a competent officer, navigation was fairly simple
as far as the Sub was concerned; but now the whole responsibility of
getting his charges safely into port rested on his shoulders.

It was the morning of von Preussen's visit to Auldhaig. The fog had
dispersed. In its wake had sprung up a fresh southerly breeze, which
in turn gave indications of decreasing in velocity before noon.

Stopping to give his final instructions to the coxwain of No. 6, and


impressing upon him to follow at a cable's length in her consort's
wake, McIntosh boarded the lighter which for the nonce was to be
the leading craft. Already the twin heavy oil engines were "warming
up," making the decks quiver, and filling the air with oil-laden smoke.

Making his way aft to the rough wooden hut that served as a
wheel-house, the Sub gave the signal to the engine-room staff to
"stand by."

"Rummiest packets that ever sailed under the White Ensign," he


soliloquised, as his eye caught sight of the dingy bunting floating
from the yard-arm of the lighters' stumpy masts. "Ah, well; it's all in
a day's work."

He gave the telegraph lever another jerk.

"Cast off!" he shouted.

Sluggishly the deeply-laden barge gathered way. She had a


freeboard of barely ten inches—a fact that portended wet decks
before long.

Having satisfied himself that No. 6 was following, McIntosh devoted


his attention to shaping a course out of harbour, undergoing a dozen
mental thrills as his unwieldy packet scraped past buoys and showed
a decided tendency to commit suicide across the steel stems of a
couple of anchored cruisers.
Once clear of the harbour, the Sub called to a seaman.

"Take her," he ordered, handing over the wheel. "Keep her as she
is: south a half west."

"South a half west it is, sir," replied the man in the time-honoured
formula of the sea.

Free to devote his attention to other things, McIntosh secured the


storm-flap of his oilskin coat and, leaving the shelter of the wheel-
house, looked towards the following boat.

No. 6 was coming along well. The "bone in her teeth" glistened
white as she pushed her snub nose through the waves. Both craft
were "taking it green" as the water flowed over the tarpaulined
hatches and surged along the broad waterways.

"We'll carry our tide for another hour," he said to himself. "Then it'll
be a slow job. One thing, we can't have every blessed thing in life,
but I hope to goodness nothing goes wrong."

He glanced ahead. In an incredibly short space of time, the bold


outlines of Dunkennet Head had vanished. Dead to windward haze,
possibly fog, was bearing down. It was something that McIntosh had
not bargained for. The glass had shown indications of fine weather,
but unfortunately it was not capable of indicating the approach of
mist.

"Hazy ahead," he remarked to the petty officer.

"Yes, sir," was the reply. "Will you be altering course a point or so,
sir? There's a nasty set of the tide inshore about these parts."

"Yes," decided the Sub, and gave the necessary instructions to the
helmsman.
"Get a nun-buoy ready to veer astern," he continued, "and signal to
No. 6 to keep the thing dose under her bows. If she doesn't, we'll be
losing each other."

While the men were making these preparations the hideous


clamour of No. 6's foghorn attracted their attention. The lighters had
increased their distance to nearly a quarter of a mile, and No. 6 was
still dropping astern.

"Ask 'em what's wrong," ordered McIntosh.

A signalman, steadying himself with feet planted widely apart on


the plunging deck, semaphored the message. From No. 6 two red
and yellow hand-flags replied. McIntosh, unable to follow the swift
movements of the flags, was obliged to await the signalman's
report:

"Says, sir, she's overheated her bearings. She'll have to stop or her
engines'll seize up."

It was exactly what the Sub was anticipating, and now trouble had
come he met it promptly and resolutely.

"Tell them to stand by and receive a hawser," he ordered, at the


same time ringing down for "Slow." "Look alive, there, with that six-
inch rope."

While the men were engaged in bringing one end of the hawser to
the after "towing-bitts," McIntosh took the helm and began to run to
starboard in order to close with the disabled lighter. He was working
against time, for already the mist was upon them—the outflung
tentacles of a bank of fog. With a range of visibility of three or four
hundred yards, matters were somewhat complicated, but the
manoeuvre of establishing communication with the helpless craft
would be rendered fourfold difficult, should the baffling fog envelop
the two boats.
"All ready with the heaving-line?" shouted the Sub.

"All ready, sir."

Slowly, even for the low-speed lighter, McIntosh, made for the
disabled vessel, which was now lying broadside on to the fairly
confused sea. The Sub was cautious. Strange to the boat, he knew
that there was a vast difference between the manoeuvring
capabilities of an M.L. and a lighter, and with that fact in mind he
displayed an excess of caution.

Almost before he realised the danger, disaster came. Answering too


slowly to her helm, No. 5 crashed heavily against the bluff steel
bows of No. 6. Amidst the hiss of inrushing water, the two engineers
scrambled through the smoke-laden atmosphere of the motor-room
and gained the deck with the tidings that the sea was pouring in like
a mill-race. And to add to the peril the fog was then enveloping the
colliding craft.

There seemed no doubt about it: No. 5 was sinking. Had she been
struck anywhere but right aft, her heavy rubbing-strake would have
saved her. As it was she had been hit in a vital spot—her engine-
room.

As luck would have it, both lighters drifted together, their metal-
bound sides grinding and bumping in the agitated waves. Since No.
5 was evidently sinking, the only refuge for her crew was the deck of
disabled No. 6.

"Jump for it!" shouted McIntosh. "Every man for himself."

Waiting till the last, the Sub snatched up his confidential papers,
thrust them into the pocket of his oilskins, and, as the two lighters
rolled heavily together, he made a flying leap for the deck of No. 6.

He was not a moment too soon. At the next roll there was a gap of
five or six yards between the two vessels. Separated by a freak eddy
of the tidal stream, they increased their distance more and more,
until the holed lighter, with her stern level with the water, was lost to
sight in the fog.

CHAPTER X
THE SALVAGE SYNDICATE

"What's your little game, Cumberleigh?" demanded the major.


"Hanged if I can see what you are driving at."

Lunch was over at Auldhaig Air Station. Most of the officers had
drifted in twos and threes into the ante-room to seize the
opportunity of enjoying a smoke before falling in on parade. The
second-in-command and Captain Cumberleigh found themselves
alone.

"I may be mistaken, sir," replied Cumberleigh, "but I'm not at all
sure about that fellow Fennelburt."

"What d'ye mean, old thing? asked the major.

"It's a rotten business to explain," replied the captain. "I hope I


don't do the fellow an injustice, but I believe he's a spy."

Major Sparrowhawk raised his eyebrows in a manner that indicated


incredulous objection.

"Goodness gracious, Cumberleigh!" he exclaimed. "What are you


driving at? The idea's preposterous. There are limits to the
imagination, and I think you're exceeding them."
"I have reasons, sir,"

"Well, what are they?"

"You remember I asked him about Smithers and Tomlinson? I know


for a fact that they were both at Sheerness a week ago."

"Yes, and Captain Fennelburt said he knew them."

"He did—but I deliberately gave him a totally wrong description of


them. Smithers is fat, but he's short—about five six, I should think—
and he certainly hasn't a mole under his eye. Tomlinson is fair, not
dark, and I've never known him to touch a card either in the mess or
out of it."

"There are some very queer cusses in the Service, I'll admit,"
remarked Major Sparrowhawk thoughtfully. "Getting a commission in
war time isn't the same as in normal times. The chap may be pulling
your leg, Cumberleigh. But why did you pal up to him and promise
to take him to the theatre and all that?"

"Just to gain time, sir," answered Captain Cumberleigh. "I thought


I'd ask your permission to telegraph to Sheerness Air Station. The
inquiry could be worded discreetly, and if the reply's satisfactory
there's no harm done. If it isn't, then we can take action."

"But what aroused your suspicions in the first instance?" asked the
second-in-command.

Cumberleigh shrugged his shoulders.

"Just a little mannerism of his, sir," he replied. "I've never before


tumbled across it on this side of the Rhine. Spent part of my far
distant youth at Heidelburg, and one notices certain things. So I've
practically put the fellow under arrest, only he doesn't know it.
Young Jefferson'll take him fishing this afternoon, and in the
meanwhile the wires can be getting busy."
"Bet you a double whisky you're wrong, Cumberleigh," offered
Major Sparrowhawk.

"Done, sir," was the prompt reply.

Meanwhile Lieutenant Jefferson, assisted by a couple of air-


mechanics, was getting his boat ready for the fishing expedition.
One of the advantages of being in the Service in war time is that the
uniformed owner of a private boat has a "pull" over his civilian
confrère. The one can make use of his craft almost without restraint
the other is hedged in by a formidable and galling array of
restrictions that are none the less necessary for the well-being of the
State.

The Pip-squeak, Jefferson's boat, was about fifteen feet in length


and provided with a standing lug-sail and centre-board. Formerly she
belonged to an Auldhaig waterman, who on being mobilised for the
R.N.R. sold her for £3. Her new owner, who contrived to escape the
irregular meshes of the Recruiting Officer's net, had palmed the Pip-
squeak off on Jefferson for six times the amount he had paid, or,
roughly, the same sum that the boat had cost to build twenty years
ago.

The Pip-squeak was no chicken, nor did she lay claim to beauty.
Bluff-bowed, and with an almost entire lack of sheer, she had one
compensating quality: she was as stiff as a house.

At the edge of the jetty gathered most of the crew—Cumberleigh,


Jefferson, a "second loot" named Pyecroft, and von Preussen.

"An' what are we waitin' for?" demanded Pyecroft, clapping his


hands and stamping his feet. "When I go sailing I like to get on with
it. What are we waitin' for?"

"Bait," replied Jefferson laconically.


"A sine quâ non for a fishing expedition," added the major, who,
though not one of the party, had strolled down to the jetty ostensibly
to see the start but in reality to observe "Captain Fennelburt" more
closely. The seeds of suspicion are apt to shoot rapidly.

"Here's Blenkinson with the bait," announced Cumberleigh, as


another khaki-clad individual, a first lieutenant, appeared carrying a
rusty tin in one hand and a mud-covered spade in the other.

"Here are your precious rag-worms, Jeff," he remarked bitterly.


"Next time you get me on that job I'll borrow your rubber boots. The
mud's stiff with broken glass, and I've cut mine through—look."

To prove his words, Blenkinson adroitly balanced himself on one


foot and kicked off a rubber boot. As the foot-gear fell upon the
wooden staging of the jetty a quart of black sea-water poured out.

Jefferson sniffed judiciously at the tin.

"Fresh enough," he observed, "but, old son, pity you didn't devote
your energies to the worms instead of wasting your time pulling bits
of glass out of your boots. These won't last any time."

"No more will my boots, you slave-driving blighter," rejoined the


worm-digger. "I'll swear I shifted a ton of mud without finding a
single worm."

"Don't stop there arguing all the blessed afternoon!" exclaimed


Cumberleigh. "If we can't fish we can sail. 'Once aboard the lugger,'
my hearties."

The party embarked awkwardly after the fashion of men wearing


breeches, puttees or leggings, and heavy boots. With the exception
of Jefferson and von Preussen, they were raw amateurs in the art of
sailing save on board a coastal airship. On those occasions they
shone. In the present instance they did not.
The spy was on his best behaviour. Although he kept his eyes and
ears open, he purposely avoided asking any questions relating to
naval or military affairs at Auldhaig. Once, when Cumberleigh tried
to "draw" him by pointing out the scene of the disaster to the
Pompey, von Preussen adroitly changed the subject by a reference
to the forthcoming performance of "The Maid of the Mountains."

For an hour or more the Pip-squeak made steady progress under a


stiffish breeze. She was by no means a flyer, but on the other hand
she sailed well with the wind broad on the beam. Beyond a few
slaps of spray she proved herself a dry boat, so that the crew, with
the exception of Jefferson, who was at the helm, were able to sit on
the bottom boards and smoke to their heart's content.

"Get a move on, you lazy hogs!" exclaimed Jefferson. "We're close
on the right spot. Down with the canvas! Blenkinson, stand by to let
go the anchor."

With a splash the anchor was lowered to obtain a grip in ten


fathoms of water. Riding head to wind and tide, the boat brought up,
pitching sharply in the short crested waves.

As long as the supply of bait lasted, sport was good. So engrossed


were the sportsmen that they failed to notice that the wind was
rising, and with the turn of the tide the waves were growing
decidedly vicious.

"Hadn't we better be getting a move on?" suddenly inquired


Cumberleigh, as he realised that the motion was causing an
uncomfortable sensation in the pit of his stomach. "Remember, some
of us are going to the theatre to-night."

"What's the hurry, old bean?" inquired the enthusiastic boat-sailer,


Jefferson. "If it comes to that, you can see the 'Mountains' from
here, although there's no 'Maid'—not even a mermaid. But, I say,
what's that?"
He pointed seawards. At about a mile distant was a long, low-lying
black hull, apparently drifting broadside on to the waves.

"Boche submarine, perhaps," ventured the facetious Pyecroft.


"She's coming to give us a tow back to Auldhaig. Did anyone
remember to bring a Lewis gun in his trouser pocket?"

With the others, von Preussen looked in the direction of the


mysterious craft. He had no pressing desire to renew acquaintance
with one of His Imperial Majesty's unterseebooten, although the
consequences would be far less awkward for him than it would be
for his present companions. But a brief glance assured him on that
point. The craft, whatever it might be, was certainly not a U-boat.
No amount of camouflage could alter that.

"She's a derelict," exclaimed Jefferson. "Get up the anchor, you


fellows. We'll run alongside and have a look at her."

Quickly the anchor was broken out and the sail hoisted.
Cumberleigh, who had been silently keeping the derelict under
observation, suddenly turned and thumped von Preussen on the
shoulder.

"Fennelburt," he vociferated, "Providence has played into your


hands! You came here to inspect X-barges. Lo and behold, one of
them obligingly drifts down to greet you!"

"You're right, Cumberleigh," said Pyecroft. "It's one of those that


left Auldhaig this morning. I saw them go out. That red-haired Scot
chap—McIntosh, you know him—was in charge."

"Hanged if he is now, at any rate," added Jefferson. "An' the old


thing is well down by the stern. I believe she's sinking."

It took ten minutes for the Pip-squeak to close with X-lighter No. 5.
Running up into the wind on the lee side, Jefferson got way off the
boat.
"How about it, you fellows?" he inquired. "Think it's safe to run
alongside?"

"Might have a shot at it, old thing," replied Cumberleigh. "She


hasn't altered her trim during the last five or ten minutes. I say, do
we get salvage on a job like this, or is there some rotten regulation
debarring underpaid officers from making a bit? What do you make
of her, Fennelburt? You are a marine expert."

Von Preussen, who had been maintaining a discreet silence,


ventured an opinion that it might be safe to board her provided the
sailing-boat were kept alongside.

"Good enough," replied Cumberleigh. "You, Blenkinson and I will


comprise the boarding-party; the others stand by in the boat. En
avant, mes braves! Over the top you go, and the best of luck."

Fending off the Pip-squeak lest her planks should be stove in


against the massive rubbing-strake of the lighter, the three men
contrived to effect a safe transhipment. A brief examination revealed
the fact that the derelict had been in collision and that she had been
badly holed right aft. The engine-room was flooded, and only the
iron bulkhead between it and the hold had kept the craft from
foundering.

"Now what's to be done?" inquired Blenkinson. "We can't tow her


in. That's a moral cert."

"No, but we can send for a tug," said Cumberleigh. "Jefferson can
sail back to Auldhaig in about an hour even if he doesn't fall in with
a tug or even an M.L. on the way."

"What about 'The Maid of the Mountains'?" asked Blenkinson.

"We'll cut the appointment," replied the captain, with a laugh.


"Excuse—the exigencies of the Service."
"But," protested von Preussen, "the lighter might founder. We
should be in an awkward predicament if she did, the boat having left
us. I would suggest that we all go back in the Pip-squeak and report
the matter."

"I agree," added Blenkinson. "After all's said and done, we don't
stand a chance of getting anything out of the deal. And what
matters if the old tub does sink? Her value is but a mere fleabite out
of six millions a day."

But Captain Cumberleigh was made of sterner stuff. Once having


set his hand to this maritime plough, he was loth to turn back.

"We'll stick it," he decided resolutely. "Jefferson will cruise around


in case of an accident. If we find we are drifting on shore we can let
go that anchor. I don't see there's much to get the wind up about."

"Cheers for the R.A.F. Salvage Syndicate," exclaimed Blenkinson,


fired by his companion's enthusiasm, but von Preussen merely
shrugged his shoulders. He hadn't risked the perils of the North Sea
in order to protect the property of His Majesty the King of England.

CHAPTER XI
VON PREUGFELD'S RESOLVE

"Donnerwetter! I am utterly sick of this business, Kaspar," whispered


Seaman Furst. "It is the life of a dog, or worse. If this war is not
over by the beginning of the winter there will be trouble amongst
the unterseebooten crews."
"S'sh, not so loud," cautioned his companion, as the grumbler
raised his voice towards the end of his tirade. "I agree with you,
Hans. This game does not pay. We were told that we should save
the Fatherland and bring England to her knees by our submarines.
But have we? Just look! Here we are hungry, wet and unhappy, yet
in England there is, they say, plenty. Just before we left Cuxhaven
my wife had a letter from her brother who is a prisoner in England.
He wrote and said that even our men who are held in captivity
receive three good meals a day."

"That is what I do not understand," remarked Hans Furst. "If we


are winning, as our officers tell us we are, how comes it that we
cannot get eatable food? Of course, at the beginning of the war we
were lucky. All we had to do was to run alongside an English
merchantman, take what we wanted in the way of food and tobacco,
and then sink her; but now——"

"But now," continued Kaspar Krauss, taking up the parable, "every


strafed English ship has a gun, and one never knows but that a
coasting vessel is not a death-trap for us. You remember that
fishing-smack off Flamborough?"

Furst shuddered.

"Will I ever forget it?" he answered. "'Tis marvellous that we live to


tell the tale. What would I not give for a life ashore with a tankard of
Munich beer, a loaf of good bread and cheese? And tobacco—what is
tobacco? I have almost forgotten."

"There was some in that Dutch vessel we burnt a week ago," said
Krauss.

Furst clenched his fists.

"And where did it go?" he demanded. "That schweinhund our


kapitan put it under lock and key. He and the pig-faced von
Loringhoven smoke every night when we rise to recharge batteries,
but never a cigar or a pipeful comes our way."

"We'll be back again on Friday if all goes well," said the other.
"Then we can enjoy ourselves."

"Enjoy ourselves!" echoed Furst contemptuously. "How? I've got a


bundle of notes in my belt, but precious little use are they. In the
good old days a mark was a mark, but now——"

"Yes, I know," snarled Krauss. "Just before the war I came back
from America on the George Washington with eight hundred and
fifty marks to my name. I was going to buy a small business in
Bremen and settle down to a life ashore. I should have done well.
Then came the war. The rascally swindlers told us that if we lent our
money to the State it would be repaid with twenty-five per cent.
when peace was proclaimed. Just imagine! I handed over my eight
hundred marks in silver, fool that I was! Even supposing the
government does pay me back a thousand marks, it will be in rotten
paper money, and I know that five thousand now will not buy the
place I had offered to me for eight hundred and fifty four years
ago."

"There will be trouble," agreed Furst. "Do you know that there is a
movement amongst the men of the U-boats' crews to hoist the Red
Flag?"

"Have I not heard of it!" exclaimed Kaspar grimly. "And when the
time comes here is one who will jump at the opportunity. Now, at
——"

The clang of a gong interrupted the discourse. The men jumped up


smartly. The cast-iron discipline of the German Navy was as yet too
powerful a force to be flouted by embryo revolutionists.

"Empty two and four tanks," came a guttural order through a voice
tube. "And be quick about it, you numskulls!"
U 247 was preparing to rise to the surface in order to verify her
position. For several hours she had rested on the bottom, scared by
the presence of a swarm of destroyers and M.L.'s which had hurried
to avenge the bombardment of Aberspey.

The material damage to the little town had been slight—almost


negligible—for the majority of the shells had fallen in open spaces.
Two people had been slightly injured by flying fragments. Actual
destruction of military property was nil. Financially the bombardment
was a failure. The cost of the ammunition far exceeded that of the
damage; but morally an insult had been offered to the island shores
of Britain, and the destroyer flotillas were quick to avenge the
affront.

Ober-leutnant Hans von Preugfeld, kapitan of U 247, had acted


with great discretion after his brave bombardment of Aberspey.
"Legging it," submerged for several miles, he allowed the submarine
to lie on the bottom for a considerable period. Then, hearing no
suspicious sounds, he had the motors restarted and, the while
submerged, shifted his position a good five miles. At length,
assuming that it was safe to blow ballast-tanks and come to the
surface, he gave the necessary orders.

Directly a patch of white light showed upon the object-bowl of the


periscope, signifying that the tip of the latter had "broken surface,"
von Preugfeld made a cautious survey. Through nearly three
hundred degrees the periscope revolved. Then, abruptly, the kapitan
checked the rotary movement of the training-wheel.

"Come here, Eitel!" he exclaimed peremptorily.

Von Preugfeld stood aside to allow the unter-leutnant to view the


object that had attracted his superior's attention.

"Come now," said the ober-leutnant irritably. "What do you make of


it?"
"It is a vessel of some kind, Herr Kapitan," replied Eitel von
Loringhoven.

"Of course it is," snapped von Preugfeld. "Any fool could see that.
What I want to know is: what sort of craft is it? Stand aside if you
cannot do better than that."

"It is a long, low-lying craft painted black," resumed Loringhoven,


retaining his place at the periscope in order to ingratiate himself in
the eyes of his commanding officer. "There are men standing aft.
Amidships I can see a small sail—it may be that there is a sailing
boat alongside."

"That's better," remarked von Preugfeld, literally pushing the unter-


leutnant aside. "Port helm fifteen degrees," he ordered. "A touch
ahead with both motors."

The U-boat shuddered under the beats of the twin screws, then
forging slowly ahead approached the puzzling object.

"Stop!"

A bell clanged somewhere in the confined recesses of the modern


pirate craft. At a curt nod from the kapitan the quartermaster pulled
over a lever which had the effect of actuating the twin horizontal
rudders. Once more the periscope reared its sinister head above the
waves.

"Ach! I see men in uniform," exclaimed von Preugfeld. "We must


be cautious. Men in khaki," he continued, scratching his closely
cropped head in perplexity. "I cannot understand it. Look again,
Eitel: can you see if she carries any guns or torpedo-tubes?"

"None, as far as I can see, Herr Kapitan," replied von Loringhoven


after a careful scrutiny. "To me it looks as if she is sinking. Her stern
is well down. Yes, there is a sailing-boat alongside or close to her.
The boat is moving ahead."
"We will submerge and come up again on the other side," declared
von Preugfeld. "We may then solve the mystery. Down to ten
metres," he ordered.

Bubbling with latent insubordination, Furst and Krauss at their


posts at the auxiliary ballast-tank valves obeyed promptly. In spite of
all their revolutionary tendencies and expressions of general "fed-
uppedness," they realised that their lives depended upon the prompt
execution of their hated superior's orders. Knowing nothing of what
was going on without, they submitted to discipline as the only
remedy for their present predicament. After a period of ten minutes'
total submergence the periscope shoved its squat snout above the
surface—like a reluctant puppy about to receive a hiding. When a
periscope is in danger of getting a blinding blow in the shape of a
six-pounder shell, or the hull to which it belongs is liable to be
pulverised by a trio of torpedoes, the need for extreme caution
becomes apparent.

"They have not observed us," muttered von Preugfeld with fervent
gratitude to the providence that looks after Hun submarines.
"There's 'X 5' painted on her bows. Know what that means, Eitel?"

Von Loringhoven confessed that he did not. In spite of a careful


perusal of all works dealing with numbers and nomenclature of
British shipping—and Berlin was kept fairly up-to-date in such
matters—the mystic symbol "X 5" was to him an unknown quantity.
Incidentally it recalled days when he was studying mathematics at
the Kiel Naval College.

The ober-leutnant steadied the periscope and touched a switch.


Immediately, by the introduction of a special lens, the "field" covered
by the eye-piece of the periscope was reduced, but the object
actually seen was considerably magnified. It was like looking through
a telescope.
"They are men of the English Air Force," he observed. "I believe—
here, Eitel, look—the man walking for'ard. What do you make of
him?"

"Donnerwetter!" ejaculated von Loringhoven. "Surely it is our friend


von Preussen?"

"Yes," replied the ober-leutnant. "Von Preussen playing the part of


a Jonah to an English whale. I wonder what he does there?"

"It would be well to clear out and leave him alone, Herr Kapitan,"
suggested von Loringhoven. "It could only be that von Preussen is
engaged in highly important confidential work that brings him afloat
again. Himmel! He is a clever fellow."

The ober-leutnant tugged at his moustache thoughtfully. Eager to


have a finger in any pie without the risk of burning himself, he was
loth to take his subordinate's advice. Here, apparently, was an
unarmed craft, crewless, with the exception of a few officers. To him
it suggested that highly confidential experiments were being carried
on—so important that no one beneath the rank of officer was
permitted to be present. Perhaps they were staff officers of high
rank?

Eagerly von Preugfeld kept each man under observation. The


trench-coats gave no indication of their wearers' rank, but —
disappointing fact—none of the officers wore gilt leaves round the
peaks of their caps. The sailing-boat alongside was also a puzzle.
Why should the experimenters make use of an insignificant sailing-
boat when there were steam pinnaces and motor launches available?

"Stand by!" he ordered. "Guns' crews prepare to take your stations.


Blow main and auxiliary tanks."

Bells clanged, valves hissed and pumps grated, men hurried to and
fro in execution of loud-voiced orders.
Von Preugfeld turned to his unter-leutnant.

"Bring her up," he ordered. "I am going to take those fellows


prisoners."
CHAPTER XII
PRISONERS OF WAR

"What in the name of goodness is that?" exclaimed Captain


Cumberleigh.

He knew perfectly well. The sight of a slender pole inclined slightly


from the perpendicular and throwing out a double feather of spray
as it cleft the water told him that it was the periscope of a
submarine.

His exclamation attracted the attention of his companions. Even as


they looked appeared the tip of the second periscope, followed
almost immediately by the bows and conning-tower of the
submarine. Then like a gigantic whale the long, bulging hull slithered
above the surface, the water pouring from its deck in cascades of
swirling foam.

"One of our submarines, by Jove!" exclaimed Pyecroft. "Wonder


what she's doing here?"

"A Hun!" corrected Cumberleigh. "We're properly in the soup, you


fellows."

He gave a hurried glance in the only direction from which they


could expect aid—skywards. Not an aircraft of any description was in
sight. The gorgeous prospect of seeing a seaplane swoop down
upon an incautious Fritz was out of the question.

"Jefferson!" he shouted. "Run for it, man. Don't wait for us."
The owner of the Pip-squeak took in the situation at a glance. True,
the U-boat was between him and the shore, but there was a stiff
leading wind. While the Hun was concentrating his attention upon
the X-lighter the sailing-boat had a fair chance of getting away, but
Jefferson was a "white man."

"No fear, old bird!" he shouted. "We're all in this stunt. I am coming
on board."

With that he ran the sailing-boat alongside the barge, and, without
waiting to lower the sail, leapt on deck and secured the painter.

Meanwhile the hatches of the U-boat had been thrown open and
her two guns manned and trained point-blank upon the helpless
lighter.

"'Fraid this isn't the time for a death-or-glory stunt," remarked


Cumberleigh. "Fritz is evidently 'one up.'"

Of the five, "Captain Fennelburt" was the least perturbed. The spy
was distinctly annoyed at the unexpected turn of events. It looked
as if his carefully prepared campaign was to be nipped in the bud.
Consequently he was liable to heavy financial loss in addition to a
waste of valuable time, for his employers in Berlin paid only for
definite results. "No work, no pay," was the motto of the German
Secret Service, and before von Preussen could be landed in Great
Britain again weeks might elapse. As a secondary consideration,
there was the doubt of how he would be received by his
compatriots. For very good reasons he wished to conceal his identity
from his companions on the lighter. In spite of strenuous
precautions, British prisoners of war sometimes contrived to effect
their escape, and it would be a very serious matter for von Preussen
if it became known through the medium of a former captive in
Germany that the soi-disant Captain Fennelburt was a Secret Service
agent of the German Intelligence Department.
"Gentlemen!" observed Pyecroft facetiously. "The R.A.F. Salvage
Syndicate is dissolved."

With her guns still trained upon the lighter, U 247 approached
slowly and with evident hesitation. At the back of von Preugfeld's
mind lurked the haunting suspicion that X 5 was a snare. The very
temptingness of the bait increased his suspicions. Perhaps a British
submarine was lying in wait to blow him and his U-boat to atoms; or
somewhere in the clouds a coastal airship was floating motionless,
awaiting an opportunity to swoop down and let loose an aerial
torpedo before the Germans had time to close hatches and
submerge.

On the other hand, there was von Preussen, clad in a British R.A.F.
uniform and standing seemingly unconcerned upon the lighter's
deck. Surely, if there were a trap, the Hun would contrive to make a
mute signal to his compatriots.

Von Preussen gave none. He was content to let events take their
course.

Presently U 247 reversed engines and brought up within half a


cable's length of the barge. Clambering upon the raised platform
abaft the conning-tower, the kapitan raised a megaphone to his lips.

His delivery of English was execrable, but he was unaware of the


fact. He rather prided himself on the knowledge that he could speak
the language, having learnt it from a third-rate German professor in
a minor university in the Fatherland.

"You vos surrender make!" he shouted. "It all of an instant up is


mit you. Get into der leedle boat and put you yourselves on board
dis scheep. If you drouble giff, den we shoot."

"Right-o, old bean!" hailed Cumberleigh in reply.


Von Preugfeld was puzzled by the reply. Mentally he resolved at the
first opportunity to consult Volume II (Ba-Cu) of a British
Encyclopaedia that he had on board.

"Look you pointed about it!" he exclaimed angrily. "I you give half a
minute to quit der boat."

"Come on, boys!" said Cumberleigh. "The old josser's getting


jumpy."

"Is that an order or a request, Cumberleigh?" asked Pyecroft. "If


it's an order, well and good; if not, I'm not having any."

"Please yourself, old man," replied the captain. "And the very best
of luck."

The four stepped into the Pip-squeak. Her sail was hurriedly
stowed, and under oars the boat approached the submarine.

"Der vos five!" exclaimed Ober-leutnant von Preugfeld, as the


prisoners came over the side. "Vere is der odder?"

A look of blank ignorance appeared on each man's face. Even the


spy failed to betray any sign that would reveal the secret. The
kapitan turned to a petty officer.

"Place these men below," he ordered.

"These three in No. 3 store-room; this one will go aft. You, there,"
he added, addressing another seaman. "Take an axe and knock out
the garboards of that boat."

Cumberleigh, Blenkinson and Jefferson found themselves escorted


below in double quick time. When fear hangs on the heels of a U-
boat's crew the promptness to execute an order borders on panic.
Literally hustled along a narrow alley-way bristling with dozens, nay,
scores, of valve-wheels, they were bundled into a dark, moisture-
laden recess that at one time contained a quantity of consumable
stores. The door was slammed and locked, and the three R.A.F.
officers found themselves prisoners of war under highly
objectionable circumstances—trapped in a U-boat.

Giving another glance skywards and all around the horizon, von
Preugfeld walked aft to the hatchway through which von Preussen
had disappeared. "I'll see you in the ward-room in less than five
minutes, von Preussen," he said. "Apparently this affair requires an
explanation. But what has become of the fourth Englishman?"

"Still on board," replied the spy. "He's trying to evade capture."

"There is an alternative," remarked the ober-leutnant grimly. "He's


welcome to it."

Making his way back to the outside of the conning-tower, von


Preugfeld noted that his order concerning the sailing-boat had been
carried out. Levelling his binocular, he scanned the shelving deck of
the X-lighter. There was no sign of life on board X 5.

Ringing for half speed, von Preugfeld increased the distance


between the U-boat and her prize to three hundred yards.

"Give her a round amidships!" he ordered.

The U-boat rolled sluggishly to starboard under the recoil of the


gun. Almost simultaneously with the report of the weapon came the
crash of exploding shell. Amidst a welter of foam and yellow smoke
X 5 disappeared beneath the waves, leaving the water dotted with
floating debris in the shape of buoyant articles released from her
hold by the shattering of her hatches.

For a full half-minute the ober-leutnant kept the flotsam under


observation; then, satisfied that his work of destruction had been
accomplished in its entirety, and that to remain on the surface much
longer after the roar of the explosion was hazardous, he turned to
von Loringhoven.

"Down to twenty-five metres," he ordered. "Course due west at


eight knots for ten minutes. Then let her sound."

Leaving the unter-leutnant to carry out his instructions, von


Preugfeld made his way to the cabin where the returned spy awaited
him.

"I hardly expected to see you so soon, Karl," he began. "I hope I
haven't disturbed your elaborate plans."

"You have," replied the spy, with marked emphasis.

"Himmel! How is that? Were you taken into the confidence of these
English officers, and were your investigations a secret project that
was being experimented upon to the disadvantage of the
Fatherland?"

"You have put me to considerable inconvenience," replied von


Preussen. "My kit is at an hotel at Auldhaig."

"No compromising documents, I hope?" asked the kapitan


anxiously.

"No; but a man cannot get about in comfort without his travelling
belongings," remarked the spy. "You will have to land me again, but
my venture in the Auldhaig district is a failure. It means that I must
make my way south and try my luck in Dover and Portsmouth. And I
was getting on so nicely with those fellows at the air station," he
added, little knowing to what purpose the hospitality had been
extended.

"And what was the experiment?" asked von Preugfeld.


"Experiment? There was no experiment," declared the spy. "Those
fools of Englishmen took a liking to me and insisted on my going
with them on a fishing expedition. We fell in with an almost water-
logged barge, and while we were exploring you appeared. Now
comes the question, where and when do you intend to set me
ashore?"

Von Preugfeld's feelings were far from those of composure. On the


one hand, he had sunk an English vessel of sorts. It was true that
she looked like sinking before, but that was a side issue. He had
made a capture of three English officers and had killed a fourth.
Unfortunately, they were of no great rank as he had hoped—merely
junior officers. On the other hand, he would have to delay his return
journey in order to set von Preussen ashore. Stores, fuel and
provisions were already running short, and the delay would mean
considerable inconvenience, possibly danger. His afternoon's work,
like that of the bombardment of Aberspey, was not worth the candle.

"I have already carried out instructions with reference to yourself,"


he remarked stiffly.

"And almost immediately you have undone all the work required of
you in the matter," added the spy.

The ober-leutnant shrugged his shoulders. He was obstinate, pig-


headed and arrogant, but in argument he was no match for the
trained finesse of the Secret Service agent.

"As a favour——" he began.

"No—as a right," corrected von Preussen firmly.

"Donnerwetter! You insist too much," grumbled von Preugfeld. "I


suppose there is nothing to be done but to fall in with your whim."

"With official instructions," interpolated the spy.


"Have your own way then," snapped the ober-leutnant. "To land
you must necessarily entail night-work. I propose, then, to set you
ashore at the same place as before. We are, in fact, within a couple
of miles of it, and you will observe that we have shut off the motors,
and U 247 is even now resting on the bed of the German Ocean. I
would suggest that you should walk to Nedderburn and catch the
mail train south that stops at the junction shortly after three in the
morning."

"And more than likely stumble across some of the officers and men
from Auldhaig Air Station," objected the spy. "No, my friend, I prefer
to lay my own plans; then, if anything does go wrong, I have only
myself to blame. And since Captain George Fennelburt is either a
prisoner of war or 'missing—presumed drowned,' I must needs beg,
borrow or steal another name. Henceforth, until further notice, I am
Captain Broadstone, also of the Royal Air Force. Will you oblige me
by lending me a pen? There are certain forms which I must now fill
in to bear out my new character."

CHAPTER XIII
A STRUGGLE FOR LIFE

With Captain Cumberleigh's valedictory words ringing in his ears,


Pyecroft began his preparations to avoid capture. While his
comrades were hurriedly lowering the Pipsqueak's sail, the "second
loot," hidden from the pirate craft by the flapping canvas, slipped
over the side as noiselessly and silently as an eel.

The shock of the icy-cold water almost took his breath away.
"By gosh!" he muttered. "It is a bit of a stinger. But cheer up, old
son, you may get it pretty hot in a very short time."

With that he dived under the lighter's hull. Literally groping his way
down the weed and barnacle-covered bottom, he scraped under the
keel and up again on the other side until darkness gave place to a
glint of pale green water that in turn gave place to the salt-laden air.
He had now placed the hull of No. 5 between him and the U-boat.
So far so good, but the late member of the R.A.F. Salvage Syndicate
had to consider another pressing problem.

Even supposing, as he fondly hoped, that the Huns had not noticed
him, it was logical to assume that they would not sheer off before
sending the lighter to Davy Jones's locker. How? By ramming?
Hardly. A U-boat would not hesitate to crash into a ship's boat
deeply laden with the survivors of a torpedoed merchantman, but
she would think twice before trying conclusions with the lighter's
massive rubbing-strake. By placing bombs on board? That meant
making use of a boat and consequently delay. Gunfire? Yes; that
looked like the answer to the question.

Now for the subsidiary problem. Assuming that the Huns would
turn a quick-firer upon the lighter, where would they aim? At the
engine-room? Hardly, as the stern was already awash. Amidships,
into the heavily-laden hold, the work of destruction would be most
easily accomplished.

"So here's for her bows," decided Pyecroft, having reviewed the
situation. "If my theories are all wrong, then it's a case of 'going
west.'" He swam with slow, easy strokes towards the bows. There
was no immediate hurry, since the boat with his companions had not
yet reached the pirate submarine. He knew that he had to conserve
his strength and his energies for the ordeal that promised to be
forthcoming.
To his great delight, he found a rope trailing overboard. A tug
reassured him that it was made fast to the towing bollards. By
hanging on to it Pyecroft could support himself with ease, while the
bluff, overhanging bows would effectually screen him should any of
the Huns board the abandoned craft.

For a long-drawn ten minutes—it seemed like ten hours—Pyecroft


waited. Already the numbing cold was taking effect. His upstretched
arm seemed to have lost all sensation of feeling. It was merely the
grip of the tightly closed fingers, contracted by the cold, that
supported him.

Then with appalling suddenness came the crash of the exploding


shell. Jerked almost clear of the water, Pyecroft had a vision of the
forepart of the massive hull rearing high in the air. Flying debris
hurtled over him, pungent smoke filled the air. Then, with a rush of
eddying water, the X-lighter slithered beneath the waves.

Under cover of the smoke Pyecroft struck out. Fragments hurled


high in the air were now falling all around him, while buoyant
objects, taken down by the vortex, were rising to the surface with
terrific force. A plank, the jagged edge of which would have almost
cut the swimmer in two, shot upwards from beneath the waves.
Missing him by inches, it described a parabola, rising to a height of
twenty feet or more before it fell back with a resounding smack.

With his senses deadened by the stupendous roar, the pungent


smoke and the coldness of the water, Pyecroft kept himself afloat
automatically until he came in contact with a huge wicker basket
that was floating upside down with about a third of its bulk exposed.

As he grasped it, the basket turned completely over, the rim


striking the swimmer a smart rap on the face. The sting of the blow
had the effect of partly restoring his mental faculties. Gaining a
firmer grip of the basket, he took stock of his surroundings.
The surface of the water was coated with a deposit of oil, for part
of the cargo of X 5 had consisted of turps, linseed, and lubricating oil
in casks. One effect of the explosion of the shell had been to liberate
the contents of the casks; another, the oil acted as an antidote to
the coldness of the water.

Before the haze of smoke had completely disappeared Pyecroft


drew the basket over his head. Within there was enough space to
keep his head clear of the water, and at the same time there
remained considerable buoyancy on the part of the stout wicker-
work.

Presently the outlines of the U-boat that had been responsible for
Pyecroft's predicament became visible. She was slowly forging
ahead. Her deck was deserted. She was preparing to submerge.

"She's gone," he soliloquised. "That's a blessing. I wouldn't swop


places with Cumberleigh for a tenner."

He dodged outside his place of concealment and glanced around. A


hundred yards away was the water-logged Pip-squeak. Even with
her garboard smashed the staunchly built boat kept afloat.

"Wonder if I can do it?" thought the swimmer.

Fumbling with benumbed fingers to draw a knife from his pocket,


he proceeded to cut the laces of his leggings.

"There's thirty-one and six gone," he muttered ruefully. "An' they


aren't paid for yet."

His boots were likewise ruthlessly sacrificed. Then, quitting his hold
of the basket, he struck out towards the derelict boat. A few strokes
convinced him that the overhand method of swimming has its
disadvantages when hampered with sodden clothing. The breast
stroke, he found, required comparatively little effort, yet by the time
he covered that hundred yards he felt that he had reached the limit
of his prowess in the swimming line.

Grasping the gunwale, Pyecroft attempted to clamber into the boat,


with the result that the water-logged boat dipped completely under
his weight.

At the second attempt he slithered over the transom and, still


submerged, lightly grasped one of the thwarts. Here was a
precarious shelter. Provided he made no attempt to draw himself
clear of the water, there was just sufficient buoyancy to keep him
afloat.

His next task—there was little time before he would be overcome


by the cold—was to unship the mast and lash it to the thwarts.
Thrice the boat dipped before the effort met with success. The stout
spar, secured to the thwarts by the main-sheets and halliards, added
considerably to the liveliness of the boat.

An oar, amongst other flotsam, drifted alongside. This Pyecroft


secured, and by its aid added another oar, although of different
length, to his life-saving appliances. A circular life-buoy and a couple
of empty petrol tins were also taken possession of; these he lashed
under thwarts, with the result that the boat's gunwales showed four
inches above the surface amidships.

Groping on the bottom boards, the young officer discovered a pair


of gun-metal rowlocks that had apparently escaped the eye of the
destructive Hun. Thus equipped, he began to row for the distant
shore.

It was hard work. At the best the water-logged craft made a bare
mile an hour, but the effect of the heavy toil was to bring warmth to
the man's chilled body and limbs. Setting his jaw tightly, he held on,
glancing from time to time over his shoulder in the direction of the
cliffs, now growing dim in the dusk of approaching night.
"How much further?" he asked himself at the end of two hours.
"Hanged if they seem any nearer. Wind and tide are with me, too."

Compared with flying through the air at a hundred and fifty miles
an hour, his present rate of progression was indeed painfully slow,
yet with the dogged determination of an Englishman, "never to say
die till you're dead," he tugged at the heavy oars until his blistered
hands grew raw and his muscles ached as if his back would break.

With night the wind dropped and the sea assumed a placid, oily
aspect. The land was now invisible, for not a light could be seen
from seaward. Fortunate it was that the young airman had been
compelled to undergo a course of astronomy. He hated it at the
time; now he was glad, for by keeping the North Star broad on his
starboard beam, he knew that he was heading towards the shores of
Scotland.

His task was stupendous. The drag of the boat, which contained
more than a ton of the North Sea, was terrific. He was wearing
badly. Cold, hunger and fatigue were telling. Almost mechanically he
swotted at the heavy oars.

He had lost all count of time, when he heard a faint rumble. It was
the surf lashing the beach. Encouraged, yet realising that other
dangers lurked on that surf-beaten shore, he rallied his remaining
energies, counting each stroke as he bent to the oars.

At the one thousand and eightieth stroke he desisted. Around him


the water was phosphorescent and white with the backlash of the
waves. His task was accomplished. Human endurance had attained
its limit. He was powerless to control his water-logged craft in the
breakers. All he could do was to sit tight and trust in Providence.

For another five minutes the sorely-tried Pip-squeak was tossed


and buffeted in the broken water, until a tremendous jar announced
that in the trough of the waves she had touched hard shingle.
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