Kids, Code, and Computer Science
! y b a B , i c c p U a h c n t e o k S b Fi iraling with Sp
. 55 . . .
.8
....
13 ....2
1.
.
.
4. . . 3 .
..
.
.3
... 1...
.
.. 2.
.5 ...
..
Clap the Night Away!
0. . .
.1
Who Won? It Depends On How You Count the Votes April 2019
$6.00 $6.00 USD
“In the Middle" Your Keyboard Has a History
beanz magazine April 2019: Volume 6 Issue 5 Issue 41 (online) & 26 (print) ISSN: 2573-3966 (online) ISSN: 2573-3958 (print) beanz Magazine© is published bi-monthly, six times a year, online at http://beanzmag.com and in print. A print + online magazine subscription includes online access to all articles, with links to let you explore topics in more detail. SUBSCRIBE: visit http://beanzmag. com/subscribe or email us for checks/ invoices. We’re also available through EBSCO, Discount Magazine, WT Cox, Magazine PTP, and many other subscription services. ONLINE MAGAZINE ACCESS: send your email address to hello@beanzmag.com and we’ll set you up. Published by Owl Hill Media, LLC 378 Eastwood Rd, Woodmere, NY 11598 Email: hello@beanzmag.com Phone: (646) 553-3390 POSTMASTER: Send address changes to Owl Hill Media, LLC, 378 Eastwood Rd, Woodmere, NY 11598. Periodicals postage paid at Woodmere, NY and other mailing offices Copyright Owl Hill Media, LLC with all rights reserved except as noted. Images are copyrighted by their creators, as noted with each story both online and in print. Publisher/Editor/Webmaster: Tim Slavin Staff Writers: Amy S. Hansen, Simon Batt, Patricia Foster, Bonnie Roskes, Clarissa Littler, Jennifer Newell, Les Pounder, Paul Seal, Erin Winnick, Tim Slavin Contributors: David Dodge, Jay Silver, Jeremy Kubica, Colleen Graves, Daniel Fenjves, Ali Hagen, Emeline Swanson, Jean-Francois Nguyen, Madeleine Slavin, Tim McGuigan Back Office Magic: Wendy Garrison Copy Editors: Eileen Seiler Art Director: Kelley Lanuto Webmistress: Patricia Foster COVER IMAGE: J BREW, FLICKR, AND PUBLIC DOMAIN, WIKIMEDIA
Publisher’s Note This magazine is serious about software programming, computer science, and technology, but in a fun way that’s surprising and quirky at times. For example, what's an article about dessert food doing in a STEAM magazine? Because it's a fun way to learn coding! In this issue, we take a second look at a concept we introduced awhile ago about how to make food with Python. Okay, digital food, not stuff you can eat, sorry. The new Deluxe Dessert Generator shows how high level changes can improve your code. We feature some interesting math concepts in this issue, starting with the Fibonacci sequence, where the sum of the two numbers that precede it: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. We play with binary numbers using a Bakuro game. It’s a mix of math, binary numbers, and Sudoku. The issue begins with a history lesson about how indie software games were distributed in the 1980s. Today it’s easy to post your game online then announce it to the world through social media. Years ago, however, people used snail mail and let people decide whether or not to pay. We also have an interview with Allie at Mythbusters Junior, as well as articles about Scratch, a clap-on clap-off light project, Glitch, Game of Life, voting algorithms, the Van Allen Belt, teapots, and much more. Dive in!
Tim Slavin Publisher beanz Magazine beanz magazine (as Kids, Code, and Computer Science magazine, our earlier title) is a winner of Parents’ Choice, Tillywig, and Academics’ Choice awards: http://beanzmag.com/awards
Our Mission beanz magazine is a bi-monthly online and print magazine about learning to code, computer science, and how we use technology in our daily lives. The magazine includes hard-to-find information, for example, a list of 40+ programming languages for education, coding schools, summer tech camps, and more. While the magazine is written to help kids ages 8 and older learn about programming and computer science, many readers and subscribers are parents, teachers, and librarians who use the articles to learn alongside their young kids, students, or library patrons. The magazine strives to provide easy to understand how-to information, with a bit of quirky fun. Subscribers support the magazine. There is no advertising to distract readers. The magazine explores these topics: Basics of programming and where to learn more, Problem solving and collaboration, Mathematical foundations of computing and computer science, Computational thinking, Recognizing and selecting computer devices, and the Community, global, and ethical impacts of technology.
April 2019 Cover Story
18
6
Cover Story
Electronics Create a ClapControlled Nightlight
2 4 9 10 12
14
History Cover Story Sharing Is Caring Programming Mix Up Something New With Glitch Concepts What Is the Internet of Things? Languages Assembly Concepts Now Look Here!
16 17 20 21 22
In the Middle Your Keyboard Has a History Cover Story
tidbitz
11 A + Bee = ? 11 A Lab, in Your Hands! 11 Not So Bad After All?
Sketch Up The Fibonacci Spiral
3D Printing Teatime History Sending Satellites Into Danger Programming Squares and Patterns Profiles Meet Allie Weber Notebook Weirdly Easy Cover Story
24 25 26
Scratch The Game of Life, in Scratch Puzzles Bakuro! Programming Deluxe Dessert Generator
27
Algorithms How to Decide?
28
Parents and Teachers Constructing STEAM with Microcomputers
contents
advanced
intermediate
beginner
scribe b u s / m ag.co m z n a e b http://
History
2
BY SIMON BATT
Sharing Is Caring
Today, a lone developer can make a game and distribute it on the internet for the public to play. This is how Markus Persson, a.k.a. Notch, managed to get his game, Minecraft, onto the market! But did you ever wonder how videogames were distributed, pre-internet? Back in the 80s and early 90s, it was hard for developers to get their games out there. There weren’t really many big game stores, and if there were, they’d only take games handled by big publishers. The internet wasn’t yet suitable for distributing games. If a small group of people (or just one person!) wanted to sell games, they’d have to get creative with their methods. One way developers did this is with shareware. Shareware has a special kind of user license that allows people to make as many copies of it as they like. Usually it's illegal to make a copy of a CD, or to download music and videogames without paying. Not with Shareware! Back then, you could put data on a floppy disk and make multiple copies to give to friends, which meant piracy was common. The motto “don’t copy that floppy” was invented by the Software Publishers Association to raise awareness of piracy. While software manufacturers and others were fighting the copying of floppy disks, independent game developers capitalized on this technology with Shareware. First, an independent developer would make a free "demo version" of a game. This would typically have fewer levels than the main game, be missing some features, and may even use older graphics than the paid version. This demo version would be loaded onto a floppy disk (or multiple disks; one floppy could only hold 1.44MB of data!) and labelled ‘shareware’. They would then be given out to gamers to try out the game. Because the demo version was under a shareware license, everyone with the disk could distribute it to their friends. Then, they too could make copies and send it to their friends. The goal for early game developers was to have one shareware floppy disk be copied and shared multiple times. Given the ‘collectability’ of shareware, gamers took to it well. You could meet up with your other gamer friends and swap copies of games, all legally! It encouraged people to try out new games, which would in turn lead to more sales. Next came CDs. They had more room for games, meaning one CD could hold tens or even hundreds of shareware games for people to enjoy. Eventually the internet became widely used, giving developers a better avenue for sharing their games. Over time, the shareware model started to fade away as developers found it easier to get their name out to the public via the internet. The next time you buy and download a videogame from the internet, imagine having to send that money in the mail to the developer themselves, then waiting for the CDs to arrive in your mailbox! That was what the gaming scene looked like 30 years ago! b JOSH MCGINN, FLICKR
LICKR
ICK, F
R KOSB
tware c sof i r a. o t s , a.k. Prehi evice d e g stora isk ppy D rents.) a Flo pa r you (Ask
3
When the heck will my video game arrive? Hold horse your s, I'll ge Sonny! tt event o you ually .
DON,
THE U
P NO
RTH M
EMOR
IES G
UY, FL
ICKR
Programming Languages
4
g n i h t e m o S h p c U t i l x i G M h t i W w Ne
BY CLARISSA LITTLER
Want to learn how to build a website or code in JavaScript? Does a web development site where you can remix projects like in Scratch sound interesting? Then read on to learn about Glitch, a site that combines Scratch-like project sharing with making small singlepurpose web pages. When you first go to https:// glitch.com you'll see something like this: A Once you sign up, you'll be able to experiment with making a simple site. To start, click on the button that says "New Project". You'll see three different choices like this: B
A
Click on the option that says hello-webpage for a really simple start! C From this page you can • click on the sunglasses near the top of the screen to see what the app looks like, or • click on the files to the left of the screen in order to modify those files. This is where, if you haven't done web programming before, you must plug in the Mozilla Developer Network, commonly just called the MDN: https://developer. mozilla.org/en-US/. This is probably the single best resource online for learning HTML,
CSS, or JavaScript. It has tutorials, reference manuals, and all sorts of guides to other cool things like SVG, WebGL, or WebAssembly. If you've done web programming, you can just jump right in to messing around with the HTML, CSS, and JavaScript. If you haven't, then read on as I give a brief introduction. The three technologies I've mentioned before are • HTML • CSS • JavaScript You may have heard of all of them and might even know that JavaScript is a programming language. Let's talk a bit more, though, about what these three components to a webpage are. HTML is the bones of a webpage. It's the basic content that says "There's a heading here, a list there, a paragraph over there". In your starter-site you'll see the file index.html. You'll see a bunch of pairs like <body> and </body> or <p> and </p>. The ones without the slash are opening tags and the ones with the slash are closing tags. What goes in between them is the actual content you want in your page. So between <p> and </p> you put the text of a paragraph. Between <div> and
5
MIKE PETRUCCI, UNSPLASH
</div> you put things you want to group together. CSS determines how your HTML looks on the screen. The default CSS in your project will look like /* CSS files add styling rules to your content */ body { font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif; margin: 2em; } h1 { font-style: italic; color: #373fff; }
B
This makes a pretty good example of what CSS looks like in general! It's a mixture of selectors, like body and h1, and then the properties that you're changing. Finally, JavaScript is the thing about which you may have heard the most. It's the programming language that makes the web work! Every browser has a JavaScript interpreter built into it that runs the JavaScript in each website. The default JavaScript in this project has only a single line: console.log('hi'). If you go to the preview of your project then you can open the JavaScript console and see that this code wrote "hi" to the console's output. You can find a comprehensive list of how to open the console in different browsers here: https://webmasters. stackexchange.com/ questions/8525/how-doi-open-the-javascriptconsole-in-differentbrowsers. With this overview complete, let's talk about the social media aspects of Glitch. You can go to the front page of Glitch and browse through categories or search for other people's projects to look at, but let's pick a particular example. Navigate to https://glitch. com/~space-invaders.
Once you're on this page you can click on the button that says show to try the game. You can also click on "view source" to look at the project itself. (This is like the "See Inside" button you might be familiar with from Scratch.) I picked this project because it's very clean and well commented. You can't actually do anything with it from here other than look at it, though! So go to the button in the upper right corner of the screen that says "Remix to Edit". Click that to copy the project for yourself and play around with the code. Iâ&#x20AC;&#x2122;d recommend trying to modify the speed of bullets to make the game go a little faster. From here, I recommend that you follow some of the recommended Glitch projects found in the online version of this article. Don't be afraid to remix everything in sight! b
C
SketchUp
6
The Fibonacci Spiral BY BONNIE ROSKES
SketchUp is a free and fun program for 3D modeling. You can use SketchUp to design just about anything, from furniture to a dream bedroom to an entire city. There is a downloadable version called SketchUp Make, which you can get at https://www.sketchup. com/download/all. But there is also a web-based version which works right in your Internet browser. This version is called my.sketchup, and to use it just go to www. my.sketchup.com. The Fibonacci spiral is the basis for a lot of patterns you’ll find in nature. Look at these photos of a hurricane cloud formation, an aloe plant, and the inside of a Chambered Nautilus shell. See how these are all similar?
In this issue, we’ll create the spiral itself. Next time we’ll use the spiral to create some interesting flower patterns. When you open SketchUp, you’ll see "Josh" standing on the ground. He isn’t needed in this model, so press E for the eraser, and click on any of Josh’s edges. To create the spiral, we want to start in Plan view (also known as top view or bird’s eye view). Click the Views icon on the right side. In the Views window, click the Top view icon. Now we’re looking straight down at the “ground.” Press R for the Rectangle tool and draw a square - be sure to click when you see the “Square” popup.
COASTAL AND HYDRAULIC LABORATORY, NASA, FLICKR
J BREW, FLICKR
JITZE COUPERUS, FLICKR
Then press C to active the Circle tool. For best results, this circle should be as smooth as possible— SketchUp circles are actually polygons. Before clicking anywhere, look in the Sides field at the lower right corner; the default number of sides for a circle is 24. To make a smoother circle, type 60, which appears in the Sides field, and press Enter. (You never have to click in this field; just type and the number will appear.)
Now create the circle by clicking Point 1 for the center, and Point 2 for a point along the circumference.
Activate the Eraser and erase the entire circle except for the quartercircle inside the square.
This little object is the building block we’ll use to create the spiral. Because it will be repeated, and because we want it to act as a single object, it should be made into a component. Press the Spacebar for the Select tool, and drag a selection window around the whole square. Right-click on any selected face and choose Make Component. Assign a name or accept the default name, and click Create. The component is highlighted as a single object, which means it’s selected - leave it selected.
This component will be copied multiple times, and each time the copy will be made with the Rotate tool (press Q). Tap the Ctrl key (PC) or the Option key (Mac) to add a plus sign to the cursor, which means a copy will be made. The Rotate tool requires three clicks. The first click defines the center of rotation - click Point 1 shown below.
while it is selected, press the S key to activate the Scale tool. You’ll see a set of eight green drag handles around the component.
Click the top right drag handle, and move it until that corner meets the top left corner of the other two components. The entire component is now twice as large as before, which you can see in the Scale field. Again, leave this component selected; this is the one that will be copied next. The second click defines the start of the rotation (zero angle) click Point 2. Then click Point 3 to complete the rotation. You’ve just made a 90-degree rotated copy. (In the Angle field, you’ll see 90 listed.)
Scale values will vary the first times, but will eventually all be ~1.62. Why this number? 1.62 is the ratio of sides of a golden rectangle; this ratio equals (1+ square root of 5) / 2. Keep going with the same steps, each time rotatecopying and scaling the newest component. When rotating, the protractor should always go to a corner of one of the original two components, on the side where the new component will go.
The scale value will eventually approach 1.62, after the 4th or 5th copy. Keep going until you have as many copies as you like— nine or ten is a good number. Use Rotate and the three points seen below to make the next copy.
Now the copied component is selected. That's good as this is the one that will be rotate-copied next. Rotate should still be the active tool, and press Ctrl / Option again to make another copy. Click Points 1, 2, and 3 to create the next copy.
The new copy is now selected, and it needs to be enlarged to join the other two components. So
Then use Scale on the new component to make it large enough to reach the previous ones. The scale value this time is 1.5.
We now have the Fibonacci spiral, made up of the quartercircles inside each component. To reduce what we have now to just those arcs (no faces), right-click on any component and choose Edit Component. The component you’re editing appears in a dotted-line box, while everything else in the model appears faded in the background. (See following page for the visual example.)
7
8
Use the Eraser to erase all four edges of the square, leaving only the arc. This change is made to each component.
Meet Mr. Fibonacci
When finished, right-click in blank space outside the component, and choose Close Component. Now you’re left with just the spiral.
It’s not very useful to have each part of this spiral locked inside a component. So press Ctrl + A (PC) or Cmd + A (Mac) to select all of the components, then right-click on any of them and choose Explode.
Save this (button at the top left corner). Next issue, we'll make rotated copies of this spiral, and use them to make Fibonacci flowers. b
Leonardo Fibonacci was a mathematician from Pisa, Italy. His father was a merchant and managed a trading post in Algeria where his son first learned about numbers and math. In his later travels for business, Fibonacci learned how people kept track of inventory, profits, losses, and other important calculations. In 1202, Fibonacci published a book of math calculations, Liber Abaci. It popularized the Hindu-Arabic number system we use today with numbers 0-9 and a place value (people used Roman numerals before). The book included many problems useful to business, for example, tracking profits and losses. Buried in the book is a math calculation for rabbit breeding, what today we call Fibonacci numbers. Each number in a sequence is the sum of the two numbers that precede it: 0, 1, 1, 2, 3, 5, 8, 13, 21, and so on. While this sequence is named after Fibonacci, it’s also mentioned in ancient Sanskrit texts that predate the publication of Fibonacci’s book. People have been entertained by interesting math sequences for thousands of years. For example, Romanesque broccoli spirals and some other plant leaves resemble the Fibonacci sequence. The Fibonacci sequence when run to infinity also approaches the Golden Ratio. But it’s complicated math: a logarithmic spiral whose growth factor equals the Golden Ratio, 1.618033...plus way too many numbers to print here! Another interesting fact about Leonardo Fibonacci is that his real name was Leonardo Bonacci. The Fi part was added in the 1800s when European mathematicians rediscovered and popularized his book, Liber Abaci, and the Fibonacci sequence. And after writing about the rabbit breeding calculation in his book, Fibonacci never showed interest in the unusual sequence he had discovered. Instead, he was known for his interest in useful math calculations. b
Ciao!
If you’ve been keeping up with the latest technology news, you've likely seen a term called “IoT” pop up. Some people talk about how great it is, others say it’s unnecessary, and some are even saying it might cause a big security scare! What is this “IoT” thing? IoT stands for the “Internet of Things”, and it describes, basically, gadgets and gizmos that connect to the internet in some way. While everyone is very familiar with computers, phones, and laptops connecting to the internet, the term “Internet of Things” is about new gadgets being invented to use the world wide web, or old devices that have been upgraded to connect to the internet. One of the most popular IoT gadgets right now is the Amazon Echo. The gadget itself is nothing special; it’s just a speaker and microphone with a processor running the show. Once it connects to the internet, however, it can do a lot more than its hardware suggests! It sends all of its data to the Amazon servers, which then sends back information to the Echo. Just ask "Alexa" a question, and you'll get the answer, via the Echo. THOMAS KOLNOWSKI, UNSPLASH
Other IoT gadgets range from useful tools to luxury items. On the useful end, Google’s Nest technology can turn a house into a "smart home." Nest allows doorbells to send a notification to a smartphone when someone rings it or enables a thermostat to learn a person's habits and security cameras to send a live feed to an app while the owners are out. All of these need the internet in order to talk to another device, which is why they’re a part of the Internet of Things. IoT gadgets are also very useful in the medical world. Imagine a health gadget that attaches to a person and monitors their health signs, then automatically alerts the health services if something goes wrong. This is the amazing future we could see when IoT is fully developed, and it’s why people are so excited to see it grow. Of course, with gadgets now beaming camera footage and health statistics to our smartphones, it’s a little tricky for our current 4G technology to keep up with all this. That’s why the IoT space is very excited to see the development of the new, shiny 5G format. 5G is speculated to reach speeds 100x faster than 4G (at a whopping 10 Gigabits per second!), which will allow IoT devices to beam as much data as they please
to smartphones, no matter where in the world they are. Unfortunately, all this can create a huge security risk. Hackers already use the internet as an access point to other people’s computers and servers, so having all these new gadgets connecting to the internet gives them more ways to enter a network. That’s why it’s so important for IoT devices to have an impenetrable defense protecting it. Think about how connected the world is to the Internet. Imagine what would happen if these devices lost their connection to the Internet. Similarly, what objects around your home do you think would really benefit from being connected to the Internet? How much cooler would your alarm clock be if it would remind you of all the things you had to do when you woke up? b
DAVID BERKOWITZ, FLICKR
DAN LEFEBVRE, UNSPLASH
9
Concepts
he ? t s s g I n t i Wha net of Th Inter
BY SIMON BATT
Languages
10
BY CLARISSA LITTLER
HEATHER HARVEY, FLICKR
Assembly Last issue we talked about C, a language without a runtime that—despite being 40 years old—is still used all the time in programming operating systems, microcontrollers like the Arduino, and anything where you need a language that's "close to bare metal" as some programmers say. Well, in this issue we'll be talking about the language, or rather languages, that are as close to bare metal as possible: assembly languages! Assembly languages are the last human readable programming languages before the actual bitstrings that are the instruction codes to the processor itself. Every different family of processor designs has its own assembly language. There are two major families of assembly languages/processor designs today: x64 (sometimes also called x86-64 or specifically Intel 64 or AMD64 if you want to name the manufacturer) and Arm. x64 includes the AMD and Intel chips you find in your desktop, laptop, or even most gaming consoles—with the notable exception of the Switch! The other major family is Arm. Arm chips tend to be less powerful but use less power and generate less heat. These are the kind of processors you find in cell phones, tablets, and—as you might have guessed—the Nintendo Switch! All assembly languages have things in common because all modern processors have things in common. They all have operations for doing arithmetic; they all have some way of jumping to different places in the code; they all have some way of making choices
about what code to run next; and they all have instructions for interacting with memory. They also all have ways of interacting with registers. Registers are an important concept when we're talking about how processors work. They are are the fastest form of storage in the entire computer! Registers are storage built right into the CPU itself that can be accessed during a single clock cycle. A clock cycle is what's being measured when you see processor speeds described in GHz. For a 2 GHz processor, performing an operation on a register takes 0.5 billionths of a second. Well, since you can both read from and write to the same register in a single clock cycle, like if you're incrementing a number by one, it’s even faster than that. That's incredible! RAM is at best around ten times slower. So, operations on registers are important. That's why every instruction set/assembly language is mostly made up of very fast operations that act on registers only, rather than on the RAM. Assembly languages tend to be complicated when getting started, and both Arm and x64 have their quirks. So rather than spend time trying to introduce either Arm assembly or x64 assembly I'm going to do something a little different: I'm going to link you to my own assembly language for a simplified, fake processor. https:// github.com/clarissalittler/asmarlanguage. I'm calling this fake architecture/language Asmar, which I pronounce like ASMR—the genre of videos and streams of
people quietly talking and making noises into the microphone to be relaxing. Tiny sounds. Tiny language. It makes sense in my head, at least! A full treatment of even Asmar is beyond the scope of what we cover in this article but let's look at a program in Asmar. This calculates the factorial of 4. Jmp main .fact MovI 1 r15 .loop JCon r0 body endfact .body Mul r0 r15 r15 SubI 1 r0 r0 Jmp loop .endfact JmpR r14 .main MovI 4 r0 Pc r14 AddI 3 r14 r14 Jmp fact Print r15 How do you read this program? The first thing to note is that there are two kinds of lines: ones that start with a . and ones that start with a capital letter. The ones that start with a dot are labels that mark lines of code so you can jump to them. The ones that start with a capital letter are the instructions! We discuss the meaning of the instructions in the online version of this article and at the linked GitHub repo. Head on over to my GitHub repo for the Asmar interpreter, instructions how to download/run it, and more detailed explanation of the language! Happy hacking! b
tidbitz Bees have brains for basic math. Building on their finding that honeybees understand the concept of zero, Australian and French researchers have discovered bees can perform addition and subtraction. The small brains of bees can manage numbers and rules. They can recognize colors as symbolic representations of addition and subtraction then use this information to solve problems. Bee-yoo-tee-ful! b https://phys.org/news/201902-bees-brains-basic-math.html
A + Bee = ?
DAVID CLODE, UNSPLASH
A Lab, in Your Hands! If you have a smartphone, there are a number of apps you can download to do science. And some apps, like eBird and NASA Globe Observer, let you participate in actual scientific research. Other apps, like Star Walk and The Elements, teach you more about the natural world. MyShake, shown here, allows you to contribute to earthquake prediction models. b
11
Not So Bad After All? Video games could be a shortterm answer to scienceâ&#x20AC;&#x2122;s gender problem! A woman who grew up loving to play Zelda and Mario wondered if her love of games led to her love of physics and engineering in school. She discovered that girls who played nine plus hours of video games a week were 3.3 times more likely to study STEM. This accounted for their socioeconomic background, ethnicity, past performance and how good they felt they were at their chosen subject. Video gameplaying boys, meanwhile, were only 1.5 times as likely to take up a STEM degree. b https://theconversation. com/video-games-couldbe-a-short-term-answerto-sciences-genderproblem-105328
https://www.popsci. com/best-science-apps VERKEORG, FLICKR
IMAGE FROM MYSHAKE.BERKELEY.EDU
BY SIMON BATT
Concepts
12
OLDSKOOL PHOTOGRAPHY, UNSPLASH
If you’ve ever seen an exciting spy movie, there was probably a scene where someone unlocked a lock by putting their finger or eye against a device. This may seem like fancy technology that’s only seen on the big screens, but the truth is, these kinds of scans are very quickly rolling out to the public. With iPhones using fingerprint scanning as an unlock method, and Windows 10 recently adding methods to use your body as a validation tool, it’s quickly becoming less of a spy gadget and more of a public tool. These kind of scans are called ‘biometric scans’, and they focus on
parts of the body that are unique to you. Usually, biometric scans either use fingerprints or eyes to validate a user. These are quick and easy to scan, while also being unique enough to prevent false validations from occurring. You may already know about the unique nature of fingerprints; they’re often used by the police to identify who handled what objects. Computers can use this identifying element of fingerprints to check if you are who you are. They do this by scanning in the ridges and dips on your fingers, then comparing it to its log of your finger. If it’s a match, you’re in!
Fingerprints are an easy one; but how can you identify someone by their eyes? It turns out that the iris (the colored part of an eye) is a perfect way to identify someone. If you look very close at an iris, you’ll see that it has a complex pattern of colors, which is unique to each person. Computers can scan for this pattern to identify people with just a glance. Programming these scans is very tricky. A computer doesn’t know what ‘a fingerprint’ or ‘an iris’ is, so you can’t give it two images and expect it to match them automatically! Scanners have to take the image of the
13
w o N k o Lo ! e r He fingerprint or iris and convert it into data, which it then compares to what it has on its database. This can be hard to do accurately; people may put their finger on the scanner in different orientations, and the iris can grow and shrink depending on the amount of light in the room. When the scanner receives a fingerprint or iris scan, it needs to take all this into account when matching it to a user’s profile. This requires a lot of complicated mathematics to be accurate! And this is only scratching the tip of the iceberg. While fingerprint and iris scans are the more common
types on devices, you can also scan the contours of someone’s face, and detect their voice patterns from a spoken sentence. All of these have their own challenges for security developers to defeat. But why are we doing all of these special scans to access a phone or laptop; isn’t a password enough? If you think about it, biometric scans are a lot safer than passwords. Passwords can be cracked or stolen, but a biometric scan is much harder to ‘take’. They’re not impenetrable— fingerprint scanners can be defeated with a mold of the user’s finger, for instance—but they’re a lot safer than
basic passwords. They’re so useful, in fact, that special USB attachments are available that can read your fingerprint. Plug it into a computer that supports fingerprint logins, and you can touch your finger on it to login to your PC. This is great for people who have sensitive data on their computers, or just for those who don’t want others prying in their computer! Compare your fingerprints with other people and see how they differ. If you were programming a biometric scan, what bits would you look out for to identify people?
b
14
In the Middle: A Deeper Dive Into Everyday Stuff
BY TIM SLAVIN
Your
eyboard Has a History
Two examples of teleprinters
RICHARD ASH, FLICKR.
A page from a book teaching typewriting, by Charles E. Smith and Underwood Typewriters, 1912
WIKIMEDIA
DENNIS VAN ZUIJLEKOM, FLICKR.
DIMITRIS KAMARAS, FLICKR.
These guys in the Netherlands love manual typewriters so much they go to "Type-In" events like this.
A Blickensderfer typewriter from 1892
NEWTOWN GRAFFITI, FLICKR.
The Underwood typewriter is still a classic
TAKOMA BIBLIOT, FLICKR.
MARCIN-WICHARY, FLICKR.
Some keyboards were shaped differently than the standard rectangle. This is a Hansen Writing Ball from 1873.
An electric typewriter by Smith-Corona
ANTHONY ALBRIGHT, FLICKR.
Just another day at the office, circa 1875.
Believe it or not, the keyboard was invented long before the computer. First, there were typewriters, which had keyboards. Typewriters work by pressing keys into an inked ribbon, which in turn makes an imprint on paper. The idea of imprinting type on paper has been around since the 1500s in different forms, as ideas and one-off inventions. An obvious example is the first printing press. Typewriters are a natural extension of the printing press. In 1575, an Italian printmaker Francesco Rampazzetto created a machine to impress individual letters on paper. In 1714, Henry Mill in Britain patented a machine to type letters on paper. In the early 1800s, several Italian inventors created versions of a typewriter. One inventor, Agostino Fantoni, built his typewriter to enable his vision-impaired sister to write. Modern typewriters were soon invented and mass produced from the 1860s onwards. Typewriters came in all shapes and sizes, and there were many popular brands. Typewriters had no motor or power. They were powered by fingers striking the keys! These were called manual typewriters. Eventually electric typewriters were invented, reducing the effort and speeding the process. Next came teletype machines, or teleprinters. While they use the same key arrangement as a typewriter, computer keyboards descend directly from these teletypes or teleprinters, devices that could send and receive messages from one teleprinter to another or to a network of teleprinters. Teleprinters did much more than typewriters. These devices used dedicated telephone circuits, switched networks like a telephone company, radio waves, and microwaves. Teleprinters used modems to connect to computers through telephone lines. They were also used to generate punch cards and paper tape for computers to process. They could produce and be controlled by computer codes. Today teleprinters have been replaced by computers, with their computer keyboards. Computer keyboards were created only when the traditional way to input data into a computerâ&#x20AC;&#x201D;punch cards and paper tapeâ&#x20AC;&#x201D;became obsolete. But today, in software specifications, you might still see TTY, which is shorthand for teletypewriter, another name for teleprinters. Typewriter and computer keyboard layouts also have their own history. Most keyboards use the QWERTY layout. But there are other layouts, for example, Dvorak and Colemak. And keyboards found in non-English speaking countries use QWERTY as their start point, changing keys and key combinations to print letters and characters unique to their language. The QWERTY keyboard gets its name from the first six keys of the top left row of letters on your keyboard. The order of letters, numbers, and characters on a keyboard resulted from experiments done in the 1860s by Christopher Latham Sholes, a printer and newspaper editor from Milwaukee, Wisconsin. He found the QWERTY keyboard to be the easiest for the human hand to work with. 150 years later, QWERTY is still used everywhere people need to type data. b
ALAN LEVINE, FLICKR
15
3D Printing
16
BY JENNIFER NEWELL
Teatime
Take a close look at the images A, B, and C, to the right. Can you identify anything that they have in common? If you noticed that all three contain a teapot, good eyes! You have just discovered an inside joke among graphic artists known as the Utah Teapot. Why would graphic artists from companies ranging from Pixar to Microsoft occasionally throw a teapot into their work? This teapot is one of the earliest 3D objects used with great success by graphic artists. During the 1970s, computer scientists specializing in graphics needed objects to run through their algorithms in order to determine whether or not the algorithm would render an accurate image. To test out their algorithms, they would measure an object, note key points (known as Bezier control points) and enter these points into the algorithm. If the image that appeared on the screen was an accurate 3D rendering of the real object, then they had evidence that their algorithm worked. Graphic artists needed test case objects that met certain criteria. The objects could not be too complicated nor too simple. Ideally the object would cast a shadow on itself, reveal reflective textures, have various curvatures and saddle points, and not be easily confused with other objects. Coming up with an ideal test case to run through an algorithm turned out to be a challenge in and of itself. At the time, the University of Utah was a leader in computer graphics. Graduate student Martin Newell was struggling to come up with an object to test in the algorithms he had designed. He mentioned his dilemma to his wife Sandra over an afternoon tea, and she suggested he try out their Melitta teapot. Martin could see the teapot might be just what he needed, so he sketched it, input key points into his algorithm, and ran his code. Indeed, the teapot was just what he needed! Since Newell had done all the work of entering the key data for the tea pot, other graphic designers and computer scientists began using the data to test out their algorithms as well. Over time, the Melitta teapot became a standard test case in computer graphics, somewhat analogous to the “Hello World” program that frequently appears in the world of software design. Today, Newell’s original teapot can be found on display at the Computer History Museum in Mountain View, California. As probably the only object at the museum that is also commonly found in the kitchen cupboard, it serves as a fun connection between an age old tradition and a breakthrough in computer science. b
The original Melitta teapot
A
C
Sending Satellites Into Danger B
A 3D-printed version of the famous teapot
IMAGES FROM THE SIMPSONS, MICROSOFT WINDOWS "PIPES" SCREENSAVER, AND PIXAR'S TOY STORY. 3D-PRINTED TEAPOT IMAGE BY CREATIVE TOOLS, FLICKR; LARGE TEAPOT IMAGE BY ANDREW MILLER, FLICKR
17
History
BY AMY HANSEN
NASA IMAGE
After thousands of hours of planning, building and testing, Mona Kessel's and her team's new satellites are orbiting Earth. These probes are going to one of the most dangerous parts of the Solar System—the Van Allen Radiation Belts, discovered in 1957. They’re collections of energized particles near Earth. Most satellites rocket quickly through the area with all their shielding down around the delicate instruments. Her team wanted to slow down and actually examine that part of space. So it was with some trepidation that she and her team turned on the two Van Allen Probes on August 30, 2012. The probes worked! The crew celebrated, but they were still in for a big surprise. Kessel's team chose to study the Van Allen Radiation Belts because they are important. Every time our Sun sends a burst of particles and energy toward Earth, the radiation belts fill up and expand, as part of a geomagnetic storm. These storms are part of space weather, and they can affect all of our satellites including GPS, weather and communication satellites. Airlines don’t fly near the North pole if they know a solar storm is coming because the radiation hurts the people on the plane. The team knew that radiation belt’s high-energy particles would destroy a normal computer. And "fancier" computers are more likely to be damaged because they have a lot of small transistors that could be short-circuited by the high-energy particles. So the Van Allen Probe designers used low-power computers with limited memory (with 50 times less memory than a cell phone). These computers are better able to withstand the storms of high-energy particles. Then they put them in shielded boxes. Finally they designed timers that automatically reset the system when needed. Soon the team received their first set of data. “We saw something very unusual,” Kessel says. Suddenly they could see clearly that the belts aren’t always made up of two bands of radiation as everyone had thought. Sometimes there are three! Imagine finding a new mountain on your way to school. You’ve made that trip a thousand times before. The mountain wasn’t there. And suddenly it is! Physicists who study space usually have long and drawn-out studies. Often the information they find changes our understanding of the universe in incremental ways. This discovery was much more dramatic. They found the third Van Allen Radiation Belt and then found out it is not always there. It ebbs and flows with space weather, which is another reason to keep studying it and learn how to predict when it will reappear. The probes themselves were expected to last two years. But there again, the team was surprised. The shielding and careful electronics have worked and the satellites are still working today, nearly seven years later. b
Electronics
18
BY LES POUNDER
Create a Clap-Controlled You'll Need:
• A computer with access to the Internet • An Adafruit Circuit Playground Express • Dollar store toy In the 1980s and 90s there were many commercials for novelty products. A fun one was the clapcontrolled room light. We can create one and use a dollar store toy as a diffuser to create a subtle light. Let's use an Adafruit Circuit Playground Express which has the two components needed for this project: a small microphone (which will detect our claps to control the LEDs), and the LEDs which are built-in 10 neopixels. We can even have these LEDs choose a random color each time they turn on! In this project we will learn about: events and how we can use them to start our code; conditional tests and how they can be used to change the flow of our code; inputs and outputs, and how the computer will understand what to do; variables and how we can use them to store the state of our lights; and finally about generating random numbers. Writing the code
Plug in your Adafruit Circuit Playground Express. (Let's call this a CPX going forward.) The CPX will appear as a USB flash drive, but for now just leave it plugged in to work with it later. To write the code we'll use the Makecode editor at https:// makecode.adafruit.com., which is a block based way to write code.
On the left of the screen we have a CPX simulator, which we can use to test our code before we write it to the CPX. In the center we have a section where the blocks that we use to code are stored. These blocks are stored based on their function/use. For example we can control the LEDs using the LIGHT blocks, all we need to do is click on the block to see all of the blocks that can be used to do this. Then we drag the blocks into the large gray coding area to the right of the screen. Go to the LOOPS section and find the “on start” block. Drag this into the coding area. This is a loop that will run only once: when the CPX is powered up. When our CPX powers up we need it to create a variable, a container that will hold data (in this case a toggle), to record the state of the LEDs, with 1 meaning ON and 0 meaning OFF. To create a variable we go to VARIABLES and click “Make A Variable…” Call the variable “toggle” and then drag “set toggle to 0” into the “on start” loop. Now when the CPX powers up our toggle variable will be set to 0.
Now let's create another new loop, called “on loud sound”, and it lives in the INPUT section. Drag “on loud sound” into the coding area. Inside of this loop we shall insert a conditional test. It's found in LOGIC and it's called “if true then...else”. Drag this block into the loop. For the next step we shall use our conditional test to check two values against one another. This is called a comparison and for this we need the “0 = 0” block found in LOGIC. Drag this block so that it replaces the “true” part of the conditional test. The comparison will test to see if the value of our “toggle” variable is equal to 0. To do this we go back to VARIABLES and drag the “toggle” block into the first “0” of the comparison. If the value of “toggle” is 0, it will first turn on the neopixel LEDs on the CPX. To do this we use the “set all pixels to …” block from LIGHT. In fact we can drag two of these blocks into the code, one for the “if” section and another for the “else” For the block in the “else” section, change
19
Nightlight the color to black, as this will turn off the LEDs. To set the color of our LEDs, use a block called “red 255, green 255, blue 255” found in the LIGHT section. This uses numbers from 0 to 255 to control the intensity of each color. With this, we can mix our own colors! If you have used Photoshop to edit images you will know this as RGB color values. Drag this block into the first “set all pixels” block so that it replaces the existing color. So how can we create a random color each time we turn the light
on? Well by going to the MATH section we can use the “pick random 0 to 10” block. Drag this block three times and use it to replace the 255 value for red, green and blue. Then change the values so that they read “0 to 255” for each color.
Now for the last two blocks! Go to VARIABLES and drag two “set toggle to 0” blocks. Place one inside the “if” part of the conditional test, and change the “0” to a “1” This will ensure that our CPX knows that we want the light to be on, and stay on. The second “set toggle to 0” will go in the “else” section and it will activate when we clap to
CLAP! CLAP!
turn the LEDs off. This relies on the conditional test skipping the first test as our “toggle” variable is storing the value “1” so that means our “else” condition is true, causing the LEDS to turn black (off) and for the “toggle” variable to be reset to 0. All of the code for this project should look like this. Check your code before moving on.
To save our work we need to go to the bottom of the screen and use the save dialog. Name your project “clap-lights” and click on the Download box. We now have a copy of the code in our Downloads folder. In order to save this to our CPX we need to follow the instructions given in the editor.
Our CPX is already connected to the computer, so we can just press the RESET button and see that our LEDs light up green. A new drive will appear called CPLAYBOOT, drag the project code file from the Downloads folder into the CPLAYBOOT drive and let go. After a few seconds the board will be programmed and ready. Place the dollar store toy over the CPX, you may need to trim or cut a hole for the USB cable. Clap your hands a few times. Does the CPX light up? Do the LEDs turn off? Each time you clap the lights on they will turn on in a different color. All we need to do is clap to turn the lights on and off! Well done! You have made your own clap-activated night light! Happy Hacking! b
There's lots more online. Check the link for this article on the back cover.
Programming
20
BY PATRICIA FOSTER
Squares and Patterns A
You’ve learned how to print triangles in Python. In this article we’ll write some code to display another classic shape, with a twist. And we’re going to spice our shapes up with exciting patterns. Open a browser and navigate to www.repl.it/languages/python3. A On your left you’ll see your editor, where you write your code. On your right is your console, which displays the result of the code. The Basic Square
Before we dive into the exciting stuff, we need to nail the basic square. Imagine your square as a grid with an equal number of rows and columns, where each box contains its own little star. B To output this we’re going to use a nested for loop, which is a fancy way of saying “a for loop inside a for loop”. There are easier ways to print a square—like printing an entire row at once, instead of one star at a time—but the double loop comes in handy for the decoration phase. The inner loop: for col in range(7): print("*", end=" ") print()
B
If you run the code by clicking the green “run” button at the top of the Repl.it screen, you’ll see a single row of stars. Essentially, our simple “print” operation is repeated seven times in the loop, one for each column in the first row. In Python, print statements automatically add a “newline character”. Since we want our stars to be next to each other, and not on different lines, we need to specify that our end character is a space. We only add the newline character once the entire row is printed. If we want seven rows, then we need to repeat that whole block of code seven times—using another for loop. Simply pop your three lines of code under a new loop, and you’re good to go. C for row in range(7): for col in range(7): print("*", end=" ") print()
C
The Hollow Square
In this exercise, you don’t want to print every star in the grid. You only want stars in the first row, last row, first column and last column; otherwise, you print a space. Since we’re adding a condition to our program, we need to add an "if" statement. Programming has a couple odd quirks. When you’re counting, for example, you typically start at 0 instead of 1, which means our columns are labelled 0-6 instead of 1-7. The first row is Row 0, and the last row is Row 6.
D
for row in range(7): for col in range (7): if col == 0 or col == 6 or row == 0 or row == 6: print("*", end=" ") else: print(" ", end=" ") print() Use the double equals (==) when comparing numbers! D Check the online version of this article for more. The patterns are limitless. Maybe a giant ‘X’? Or a diamond pattern? Play with your "if" statements and see what pictures you can create. Remember to avoid hard coding wherever possible! b
Meet Allie Weber Allie Weber has been thinking about inventing since she was five. When she told her parents she wanted to build a robot for the science fair, they told her to wait until she was older. The next year she told them she was going to start creating her robot. After a few hours, she came back up with “Robie” the recycled robot, already half done. Weber has been inventing ever since. Her maker talents have even carried her into a role on the new Science Channel series, MythBusters Jr. Weber and some fellow junior MythBusters test myths, just like the original hosts, Adam and Jamie. We sat down with Weber to ask her about the experience, as well as what science projects she is working on next. What was the process like of getting picked to be on MythBusters Jr?
It was actually pretty interesting. A talent agent from the production company was looking for kids with a background in STEM, and they found me through an article in my local newspaper about one of my inventions, the "Got Your Back Binder Strap". I had a few Skype interviews, one while I was at space camp. Eventually I got the call saying that I would be on the show, and I was so excited. I was probably bouncing off the walls all day. Were you a fan of the original show? Did you have a favorite myth?
I watched a lot of the original show, and my favorite was the "Indiana Jones" episode where they tested all the myths from that movie series. I really like Indiana Jones, and it was cool to see if using a whip to swing across a trench really would have worked. I also really like "Duct Tape Island" because it’s a ridiculous idea to see if you could use duct tape to build what you need to survive, but you could try to make those things at home too. What resources would you recommend to kids who want to learn more about STEM and making? Do you have any favorite websites?
There are a lot of platforms that can help. The Sparkfun website has a lot of kits as well as tutorials. Digikey electronics has almost any component on the face of the planet you can order when you’re looking for parts. Adafruit has a lot of fun projects. I also recommend the online kids site DIY.org. It lets you explore all kinds of skills through challenges and you earn badges and get to talk with other kids about their projects. I was on there a lot when I was 10 and 11 and am still a huge fan. You can check out my YouTube channel at Tech-Nic-Allie Speaking. It has tech toy reviews, showcases of my inventions and innovations, and also cool how-to videos. What new maker skills are you working on now?
I feel like I have done a bit of everything but don’t consider myself a master in anything. I code in Arduino, work with Python, can handle the block coding stuff in multiple platforms, 3D design, work with power tools, wiring, soldering, 3D printing, boards, Arduino, raspberry pi, machine sewing, quilting, woodworking, upcycling, electronics repair, and I've even done some welding and car repair. I don’t see them as skills as much as tools I have used to make my prototypes or projects. So when I need to use one, I learn more and build my skills as I go. I’m working on a small materials engineering project which is more chemistry-based for this year’s science fair, which is new territory for me. b
21
Profiles
BY ERIN WINICK
Concepts
22
y s a E y l d r i e W
BY CLARISSA LITTLER
A
B
C
D
E
E
How simple can a computer be? In the past, we've talked about things like Turing machines and the lambda calculus, which are simple ways of describing all possible computations. This time we'll be talking about an incredibly simple machine that, surprisingly, is just as powerful as a Turing machine, the lambda calculus, or any computer you've ever seen! Conway's Game of Life is an example of something called a cellular automata, which is like a giant checkerboard with simple rules that determine whether a cell
is on or off, or alternatively, alive or dead. The individual squares of the board are called cells. The Game of Life has three rules, calculated one square at a time each round. For each cell, count how many neighbors it has that are alive, where the "neighbors" of a cell are in the eight squares surrounding the cell, and then: • If the cell is alive and has two or three neighbors that are alive then it's alive on the next round; • If the cell is alive and has more than three or less than two neighbors that are alive then it dies; • If the cell is dead and has
exactly three neighbors that are alive then it's alive on the next round. Let's look at an example using the Scratch implementation of the Game of Life that I wrote. If our board starts out like A, then let's break down how many neighbors are alive for each relevant cell B. By the rules we've outlined, the alive cells on the next step are the middle one with two neighbors that are alive, and the cells above and below it, which each have three alive. This means that the next round of the game looks like C. You can also act out the Game of Life by hand using either a piece
IMAGE: RADICALEYE.COM
F
G
H
I
of paper you draw a grid on, like this D or on a chessboard like this E. That's not super exciting, at least not yet. Here's where the Game of Life gets weird. This pattern is called a glider F. I don't want to immediately tell you what happens if you start with this pattern and run the Game of Life. Try it yourself on either of the implementations I link to* or on your own with pen and paper or a chessboard. Have you tried it? Okay, well if you followed it correctly you should have seen a sequence like the
following images G, H, I, J. The glider comes back around to the exact same shape but further down and to the right on the board. In other words, the glider is a pattern that moves. This is the key that lets the Game of Life act like a computer! Gliders and other moving patterns, like the Light Weight Spaceship, commonly abbreviated as LWSS, let the programmer send information between parts of the program. It's not easy to do, though! It took years before someone proved what computer scientists suspected: that the Game of Life is, in fact, a
The background is a detail of the classic â&#x20AC;&#x153;puffer train" image, This is what it looks like after 800 generations, or applications, of Game of Life transition rules
J full computer that can calculate anything your PC at home can. This construction was first built by Paul Rendell and available at his site: http://www.rendell-attic.org/gol/ tm.htm. Definitely watch the YouTube videos he has of the Game of Life Turing machine! It's gigantic, complex, and really cool! The lesson to take away from all of this is that computation is much weirder than you might think and can look like so many things other than just the computers we know and love! b
* Check out the link on the back cover of this issue for more info!
23
Scratch
24
BY CLARISSA LITTLER
For info on Scratch go to https://scratch.mit.edu
The Game of Life, in Scratch On the previous two pages is an article on Conway's Game of Life, and how this strange game played on a big checkerboard has all the computational power of any computer. What you may not have noticed is that all our examples actually came from an implementation of the game in Scratch. Let's learn to code it up, because there are some pretty neat tricks involved! Review the very basics of the Game of Life on the previous two pages. How do we encode this game in Scratch? The first important concept is that each cell is going to be represented by a clone of a generic cell sprite. This, in my opinion, makes it a lot easier to handle the user interface by letting you click on cells to turn them on or off individually. You might be wondering: "If each cell is a separate clone how do we figure out what each of their neighbors is doing so we can run the simulation?" I wondered this myself for awhile! After all, Scratch doesn't give you a way to send a message to just one clone. I decided to have a two-part way of representing the board. The cloned cells are the first part of the representation and they handle the user-interface and displaying the state of the simulation. The second part of the representation, the board itself, is actually a list! Each item in the list is a row of the board. Each row of the board is a string of 0s and 1s, with 0 meaning the cell is dead and 1 meaning that the cell is alive. We link the two by giving each cloned cell “this sprite only” variables keeping track of what row and column in the board they represent! This is a pretty common trick in
a lot of programming languages: you fake having a 2D thing like a board by using a 1D thing like a list, and putting some extra structure in each element of the list. In some languages you would make a list-oflists, but that's not easy in Scratch, so instead we use strings as the content of each row. (It's not impossible to have list-of-lists in Scratch, but you'd have to make all the row-lists by hand before starting the program. Since we want to allow for different sizes of boards, this is awkward and inconvenient. You could try doing it that way, though, and see if it makes the code simpler!) Using lists-ofstrings means that we need to write some custom blocks that allow us to treat a string like a list. These are the Modify string and Modify string2 blocks. There are two of them to prevent name overlaps between the one on the Backdrop and the one on the Cell sprite. Now, the final trick is that we actually need two boards: the "real" one and the "working" one. The reason is that when we’re calculating the new state of each cell we need to keep the original board intact and not change it as we’re working. An example is in order! Let's take a blinker as an example:
Let's assume that we're just modifying the same board as we go. Then after the row above the blinker is finished the board will look like:
The problem, though, is that now the left cell in the blinker has two neighbors which means it does not disappear! The same ends up being true of the right cell in the blinker. So by the time the next step in the simulation is done you've got this (right, top), instead of this (right, below). That's not good! So in our custom block Update space, which does the real work of enacting the rules of the Game of Life, we read the state of the list variable called Board, and write the result of the calculation to the list variable called TempBoard. At the end, after we've calculated the state of every cell on the board, we copy the temporary board back to the real board. Then, broadcast a message to tell all of the cell clones to update their internal state and costume based on the state of the board! I really liked making this little program, in part because it's not the kind of thing people usually make in Scratch. It's a good demonstration of the kinds of "serious" programs that Scratch is good at. Experiment with the code, try playing with the rules of the Game of Life, or even just try to recreate the code yourself in your own way! b
Bakuro puzzles are Kakuro puzzles (basically crossword puzzles with numbers) that use binary numbers. They are also like Sudoku puzzles, in which you determine what value to place in empty puzzle squares. Paul Curzon at TeachingLondonComputing. org, with support from Google, has created a set of Bakuro puzzles, and blank forms to create your own. In their simplest form, binary numbers use a 1 or 0 to indicate a number value based on their location in a string of binary numbers. Each position in the binary number string—counting from right to left—has a number value of 1, 2, 4, 8, 16, and so on. The position of each 1 in the string is used to add up the value of the binary number. Here’s an example with a 5-digit binary number: 5 4 3 2 1 <== position of value, counted from right to left 16 8 4 2 1 <== value of each position, as a power of 2 These binary numbers and their values are added up based on the position of the 1 within the 5-digit binary number: 00001 = 1 00011 = 2 + 1 = 3 00111 = 4 + 2 + 1 = 7 01111 = 8 + 4 + 2 + 1 = 15 Do you see how these binary numbers equal one less than the value of the next position in the binary number? 00111 equals 7 while 01000 equals 8. And 00011 equals 3 while 00100 equals 4. To convert numbers into binary numbers, start with the nearest power of 2 represented in the binary number. For example, to convert the number 6 into binary, the nearest power of 2 is 4 and leaves you with a remainder of 2
(6 – 4). The remainder of 2 can be converted into binary with a 1 placed in the second position, counting from the right of the binary number, as shown here: 0 0 1 1 0 =4+2=6 16 8 4 2 1 <== value of each position, as a power of 2 5 4 3 2 1 <== position of value, counted from right to left. With this basic understanding of binary numbers, you can start to solve Bakuro puzzles. Empty cells in the grid (right) must be filled only with powers of 2: 1, 2, 4, and 8 in this example that uses 4-digit binary numbers. The numbers or blocks must equal the number given in the binary number clue at the top and left of the puzzle. In the puzzle above, the first column cells must equal the binary number 1001 which converts to 9. The two 1 digits are in the 8 and 1 position, as explained above. Let's solve this puzzle. The value of each position of a 1 digit tells you what numbers to enter in the cell (but not in what order: you have to look at the clue on the left of each row to learn the correct order). Here, your top left most empty column cell must include an 8 or a 1 because the 1 digits are in the 8 and 1 positions. The 1001 binary number adds up to 8 + 1 or 9. Now look at the far left column and the 0011 and 1100 numbers. The top row binary number converts to 3 (0011) and the bottom row converts to 12 (1100). For 0011, the 1 digits are in the 1 and 2 value positions. For 1100, the 1 digits are
in the 4 and 8 value positions. In the top row, we need to figure out how to divide up the left column 1001 binary number, which converts to 8 and 1. The top left row 0011 binary number tells us the row values are either a 1 or a 2 because the 1 digits are in the columns with value of 1 and 2 (1+2=3). We can put a 1 in the top left empty cell. The bottom row 1100 binary number tells us that row uses an 8 or 4 because the 1 digits are in the binary number columns with a value of 4 and 8 (8+4=12). So the top left empty cell should be filled with 1 and the bottom left empty cell should be filled with an 8. This equals 1001 or 9 at the top of the left column. This leaves us with the right empty column to fill. With a 1 in the top left solution cell and an 8 in the bottom left solution cell, we need the top row to equal 3 and bottom row equal 12. The 0011 binary number for the top row has the 1 digits in the 2 and 1 value positions. Therefore, the top right empty cell must be a 2. The top left empty cell already has a 1. The 1100 binary number for the bottom row works the same way. The 1 digits are in the 8 and 4 value positions. The bottom right empty cell, therefore, must be a 4. The bottom left empty cell already has an 8. Check this solution by calculating the value of the right column. The binary number is 0110 with the 1 digits in the 4 and 2 value positions. Our right column solution of 2 and 4 equals 6, means that we’ve solved this puzzle! b
These puzzles are addictive! For more number fun, check out the link to the online version of this article on the back cover.
25
Puzzles
! o r u Bak
BY TIM SLAVIN
Programming
26
BY PATRICIA FOSTER
Deluxe Dessert Generator In a previous issue, we created a Random Dessert Generator in Python to spit out new, exciting desserts from a mishmash of flavors. Now, we’re going to take that code and turn it into something sleeker and fancier, like the kind of code you might see in professional settings. Introducing Random Dessert Generator 2.0—the Deluxe Edition! What is "Better Code?"
There’s no single answer. Sometimes “better” means “simpler”, because simple code is easier to debug, especially when you have multiple programmers. Alternatively, “better” could mean “faster”. People are naturally impatient, after all—we don’t like waiting for webpages to load, and we don’t like lag in our video games! The Old Dessert Generator
from random import choice flavor = ["cherry", "chocolate", "vanilla", "caramel"] bonus = ["swirl", "volcano", "mousse", "sprinkles"] dessert = ["ice cream", "doughnut", "pie", "cookies"] new_dessert = choice(flavor) + " " + choice(bonus) + " " + choice(dessert) print(new_dessert) A High-Level Change
“High-level” changes are about structure. Every program is a series of tasks: create a character, explore the map, find the treasure. When you’re designing a program, you want to order and group those tasks together in smart ways that accomplish your software goals. Our Dessert Generator does three things: (1) it creates lists of words, (2) it chooses random elements and HEATHER FORD, UNSPLASH
strings them together into a delicious dessert, and (3) it displays the result onscreen. This process is simple and efficient, but what if we want to add a second flavor? First, we’ll need to add the new list. Second, we’ll have to update the line that cobbles together the dessert. from random import choice flavor = ["cherry", "chocolate", "vanilla", "caramel"] flavor2 = ["cream", "coconut", "pineapple"] bonus = ["swirl", "volcano", "mousse", "sprinkles"] dessert = ["ice cream", "doughnut", "pie", "cookies"] new_dessert = choice(flavor) + " " + choice(flavor2) + " " + choice(bonus) + " " + choice(dessert) print(new_dessert) Updating two lines of code seems like a small change—and it is! The problem is that one change is affecting two different tasks. In a large program, tasks are often squirrelled away in separate files, and this “small” change wouldn’t be so small. Is there a way to restructure our code to prevent this? Try: from random import choice flavor = ["cherry", "chocolate", "vanilla", "caramel"] flavor2 = ["cream", "coconut", "pineapple"] bonus = ["swirl", "volcano", "mousse", "sprinkles"] dessert = ["ice cream", "doughnut", "pie", "cookies"] all_lists = [flavor, flavor2, bonus, dessert] new_dessert = "" for l in all_lists:
new_dessert += choice(l) + " " print(new_dessert) This new code uses a “list of lists” to deliver all the dessert inputs in a tidy little bag. As an analogy, imagine packing for a family trip. Each person has their own suitcase, and there might be a communal “food bag” with snacks, or a “beach bag” with towels and sunscreen. This system of bags is much more organized than throwing everything into the car in a huge pile. The car then acts as the “master list” which groups all the bags together. In the new code, our “for loop” goes through each list (represented by the character “l”) one at a time. For each one, we randomly choose an input, add it to the new dessert, and move on—just like going through each bag in the car, removing one item, and moving on. The main benefit of this system is flexibility. You can put as many lists as you want in the master list—two, five, one hundred, three thousand—and the code for “task 2” will work regardless. And if you want to change the program to a “goofy nickname generator” or a “random movie title generator” it’ll be easier to reuse code. There are other improvements in the online version of this article. These small improvements won’t make much of a difference in a program like the Random Dessert Generator. But if you take a large, complex piece of software like Google or Facebook, then thinking about high-level structure and lowlevel optimization is key. Besides, who doesn’t like having better code? Or dessert?! b
Psst! Check out the link on the back cover of this issue for more info!
How to Decide? Imagine your class of 30 students has earned a lunch party. Your teacher says the class can choose one of the following meals: pizza, hamburgers, or sandwiches. The class votes and the final count is recorded in the chart below: Number of Students
1st Choice
2nd Choice
3rd Choice
12
pizza
sandwich
burger
10
burger
sandwich
pizza
8
sandwich
burger
pizza
By examining this chart we see that pizza received twelve first place votes, while hamburger and sandwich only received ten and eight respectively. Since more people chose pizza first over any of the other choices, your class gets a pizza party, right? If it seems to you that there might be a problem with hosting a pizza party based on the votes in the example above, you are onto something. This is because although pizza has the most first place votes, 12, it also has the most last place votes, 18. To make sure most students are happy, we wouldnâ&#x20AC;&#x2122;t want to serve a dish that over half of the students put in last place. So if we take what is known as a pairwise vote we get a very different result. Compare each choice with just one of the other choices. For example, if the students in this class could choose between only pizza
and hamburger, we would see that 12 students would choose pizza but 18 students would choose hamburgers. How about pizza compared to sandwiches? Again, 12 people would rather have pizza and 18 would be happier with a sandwich. And if they could only choose between hamburgers and sandwiches then 20 would choose a sandwich and 10 would choose a hamburger. Even though sandwich received the fewest first choice votes, it actually beats both pizza and hamburger if we compare choices two at a time. These are examples of two of many systems of voting. The first, in which the choice that receives the most first place votes wins, is called plurality. In the second example we did a pairwise comparison of each choice. This is known as majority rule, and the winner is sometimes referred to as the Condorcet winner, after the French philosopher and mathematician Marquis de Condorcet. Around the time Condorcet proposed his voting method, another French mathematician (and sailor) John Charles de Borda, popularized yet another system, known as the Borda count. Using the Borda count, a voter gives her/his
ERIC KILBY, FLICKR
27 first choice one point, second choice two points, third choice three points. The winner of the election is the candidate with the lowest point count. Can you determine the Borda count winner from our example? Many people have never considered the voting method used when they are electing political leaders. This is very troubling, as we have just seen that in some cases changing the way we count votes has serious consequences. For example in 1970 in Chile, there was a presidential election between Salvador Allende, Jorge Allesandri, and Radomiro Tomic. Salvadore Allende had just less than 38% of the vote. But Allende won the plurality vote even though he was probably also the most disliked candidate. At this time in Chile, if no candidate won over 50% of the votes, then congress would decide. Eventually, Chileâ&#x20AC;&#x2122;s congress elected Salvador Allende. But electing a strongly disliked candidate often leads to rebellion. Three years later Allende was overthrown by a coup. The election of Allende provides an extreme example of how voting rules can contribute to major political instability. In the United States, the method of counting votes in local elections can vary city to city. Check out the voting system in the country, state, or city where you live. You might be surprised at what you find! b
Algorithms
BY JENNIFER NEWELL
Parents and Teachers
28
BY TIM McGUIGAN
Constructing STEAM with While programming is a great start to a technology education, recently I was tasked with thinking more deeply about enrichment for younger children. A friend of mine with two daughters, ages 8 and 4, approached me about ways to get them interested and invested in technology. After getting some exposure during a recent Hour of Code activity, his daughters showed a spark of interest that he wanted to build upon. His question sent me off on a bit of a quest. I considered what each of the STEAM disciplines looked like at an elemental level and what the best approach would be for teaching these skills to his daughters. Being a middle school teacher, I am well versed in the robotics and programming options available for pre-teens and teens. However, thinking about what computer science looks like at an elemental level was a new exercise. There's certainly no lack of apps similar to Code.org’s Hour of Code initiative that teach block programming though a gamelike interface. But, something about an app running on a tablet seemed like it would teach more about tablets than computing. To find an answer to his question, I went back to a learning theory called Constructionism developed by Seymour Papert in the early 1980s. Building on the earlier theory of Constructivism (with a “v”) developed by Jean Piaget and others, Papert’s theory of Constructionism says that
children learn best when building some sort of real, physical thing, like a sand castle or a sidewalk drawing. Following a set of instructions or listening to a lecture is not enough to build knowledge. To learn a concept fully children need the experience of making something. They also need the experience of solving real-world problems. I began to look at STEAM fields as a set of skills for problem solving. As a professional roboticist, you should be adept at engineering, hardware, and math as much as programming. Modern programmers need almost as much expertise in command-line programming and version control as they do in logic and loops. If you take any subset of technology and begin to walk these skills back to more elemental skills, you are left with a set of skills that teach kids to be nimble problem solvers. In the end, building tangible things to solve a real-world problem is the best advice I can give. For young learners, microcontrollers like Arduino or Raspberry Pi are a cheap and meaningful pathway to many elemental STEAM activities. While programming is a fundamental skill, learning how to construct a computer from basic hardware gives young learners a great foundation to build on—literally. Since many of the components (USB, HDMI, GPIO) are kidfriendly, even kids as young as 4 or 5 can take part. By building the computers that they will soon program, they are
constructing their knowledge of computers (with a little parental help of course). From there, these activities can diverge into quite a few different territories. Learning how to install an operating sySTEAM and use the command line is a great lesson that teaches the fundamentals of Computer Science. Companies like Kano and Pi-top provide wonderful kits for kids to build their own stand-alone computers using microcontrollers. Add additional boards, motors, and sensors, and the activity teaches the fundamentals of robotics. In a similar way, using robotics components to tackle an engineering challenge, like an automatic dog bowl-filling machine, teaches children to ponder how to reinvent the things around them using technology. In Papert’s theory of Constructionism, the teacher is more akin to a facilitator than an architect. Their role is to help guide students to develop solutions on their own. Parents (even those who are new to technology) are natural facilitators with their children, and these activities are immensely beneficial for all parties. Solving problems around the house with technology can be a fun activity for a rainy Saturday or a summer afternoon. Parents get a deeper connection to kids fascinated with the potential of technology, and children benefit by gaining skills that will be essential in the years ahead. b
29
Microcomputers
FABRICE FLORIN, FLICKR
“We learn to do something by doing it. There is no other way.”
—John Holt
Thank you for reading this issue of beanz ! Check out the links below to read stories from this issue online with links to learn more. Sharing Is Caring http://beanzmag.com history-video-games
Now Look Here! http://beanzmag.com/ how-biometric-scans-work
Weirdly Easy http://beanzmag.com/ conways-game-of-life
Mix Up Something New With Glitch http://beanzmag.com/ glitch-web-tools
Your Keyboard Has a History http://beanzmag.com/ computer-keyboard-history
The Game of Life, in Scratch http://beanzmag.com/ scratch-game-of-life
Teatime http://beanzmag.com/ design-utah-teacup
It's All Blurry! http://beanzmag.com/ sketchup-blurry-circles
Sending Satellites Into Danger http://beanzmag.com/ van-allen-belt
Bakuro! http://beanzmag.com/bakurobinary-number-puzzles
Create a ClapControlled Nightlight http://beanzmag.com/ clap-night-light
Deluxe Dessert Generator http://beanzmag.com/ python-dessert-generator
The Fibonacci Spiral http://beanzmag.com/ sketchup-fibonnaci-spiral What Is the Internet of Things? http://beanzmag.com/ what-is-iot Assembly http://beanzmag.com/ assembly-language Python Triangles http://beanzmag.com/ python-triangle-generator tidbitz http://beanzmag.com/ april-2019-news-wire
Squares and Patterns http://beanzmag.com/ python-squares-patterns Meet Allie Weber http://beanzmag.com/ meet-allie-weber
How to Decide? http://beanzmag.com/ algorithms-voting Constructing STEAM with Microcomputers http://beanzmag.com/ ibe! constructing-steam- Subscr microcontrollers
http://beanzmag.com/subscribe