CONTENTS Introduction 6 Thinking Logically 8 Try It Out 10 Welcome to the Coder Crew 16 CHAPTER 1 THE MYSTERIOUS CAVE 18 Algorithms 22 Optimization 26 Cryptology 32 Directions 42 Loops 46 The Challenge The Mysterious Cave 50 CHAPTER 2 deep sea SURPRISES 52 Constraints 56 Debugging 62 Binary Code 70 Binary Search 74 The Challenge deep sea Surprises 80
CHAPTER 3 SAVE THE SATELLITE 82 Trial and Error 86 Users and Events 88 Pixels 96 Decomposition 102 The Challenge Save the Satellite 108 CHAPTER 4 TRICKY TEPUI 110 Optimization 114 Making Shapes 120 Conditionals 126 The Challenge Tricky Tepui 136 Afterword 138 Solutions 140 Go Further 148 Code On 152 Glossary 154 Index 156 Credits 159 Copyright and Acknowledgments 160 I’m a hair ball hacker
INTRODUCTION CODING AND COMPUTER SCIENCE The title of this book is Code This but there are actually two things we’re going to learn One is the art of figuring out how to do things in general That’s called computer science The other is the art of explaining how to do something in particular particular That is called programming or coding We call them both arts because they require the same creativity you use when drawing dancing singing or telling stories Why are they two different different arts Because in order to explain something clearly enough for a computer computer to understand you first have to be able to think about it clearly to yourself The computer is like a mirror for your mind If your thoughts don’t make sense the reflection won’t make sense either And like other kinds of art computer science and computer programming use different tools If you’re in a painting class you use brushes and easels If you’re in band or orchestra orchestra you use a musical instrument It’s the same with different kinds of computer arts In computer computer science puzzles your tools include logic and math In computer programming you write specific directions called code Computer science and coding are like puzzle pieces they’re different from each other but they fit together to solve a problem 6 CODE THIS
PRACTICAL APPLICATIONS What can we do with computer science Almost anything The world increasingly relies on computers to send and receive information through the internet to use mobile phones to watch television and to play games Even this book you’re holding right now was written on a computer The doctor is in the computer Computer scientists write programs that help doctors learn about diseases and how to cure them Special programs can even help doctors to do surgery Sometimes the best way to learn about Earth is to study space Computer programmers write code that helps satellites look deep into space to grab photos They also control the machines that scramble over faraway surfaces like on Mars or fly close to the atmosphere of other planets in our solar system Computer science keeps more than just comput ers running Many cars have motors and other features that rely on computer programs Do you like to rock out or are you more of the classical type Hip-hop salsa or jazz if you’re hearing hearing music you’re hearing it courtesy of a computer It takes special code to make your favorite favorite song sound perfectly perfectly in tune Computers are hard at work even when we are relaxing People called software engineers engineers program computers to make your favorite movies and video games come to life INTRODUCTION 7