# The Vine City Code Crew

## Session #0101

How long do you think it would take you to count to 1,000,000, out loud? How long do you think it would take your little mighty mouse Raspberry Pi to print out the same? It’s race time!

Ok, so do this — grab a stopwatch and count as fast as you can to 10. BUT someone else has to listen to you and actually understand each number you said. So you can’t just say an unintelligible stream of gibberish and call it a day. Alright, do that three to four times. Record the time it took you in seconds each time. Now average those four numbers together — that is, add up all four and then divide that number by four if you’re not big on averages… What’d you get? Mine’s around 1.2 seconds to count from 1 to 10 out loud, give or take a tenth of a second.

Ok, so next step — let’s just assume you could count out loud all the numbers between 1 and 1,000,000 exactly that fast, without a break. It’s obviously a bogus assumption, because you surely can’t say “nine hundred and ninety-nine thousand, nine hundred and ninety-nine” as fast as you said “one.” But hey, who cares. This is our math experiment and we can do what we want. So in your face, math police.

So how many times would you do that 10 count cycle to get to 1,000,000? Well, that’d be exactly 1,000,000 / 10 = 100,000. So you’d count 10 numbers out loud, 100,000 times, right? Well, if each cycle takes you 1.2 seconds, then that looks a lot like 100,000 x 1.2 = 120,000 seconds! And that comes out to be:

120,000 seconds / 60 seconds = 2,000 minutes
2,000 minutes / 60 minutes = 33.33 hours

So you’d be counting that fast at that breakneck speed for almost a day and a half before you hit a million… Hope you don’t slow down, need to breathe, eat, sleep or take a bathroom break during that time!

The VC3 coders wrote a simple four line program in Python to have the Raspberry Pi do the same, using only:

`my_number = 1`
`while my_number < 1000001:     print my_number     my_number += 1`

That little “my_number += 1” bit is just shorthand for “my_number = my_number + 1”. So it means add 1 to the variable we called “my_number” and save the new result right back into “my_number,” over-writing the old value. So we’re increasing my_number’s value by one for each cycle of the loop. It’s essentially just like you do in your head when you’re counting up by one each time.

On our Raspberry Pis, the computer finished this little program in just a couple of minutes, displaying each number 1 to 1,000,000 on screen. If you actually take out the “print” statement (and just have the computer count the numbers without displaying them each time), it completes in a matter of few seconds. So yeah, a little faster than the we the human computer can do. That’s an obvious conclusion for you and me, but a fun illustration to get these coders to begin thinking about the power of computing.

Now give it a try for yourself! I wrote this tiny bit of code in an online Python website, but you can only count so high before the website gets mad at you and throws an error… So this example just goes to 10,000 instead of a million. But hopefully you get the idea. Rock it out here.

BONUS ROUND: How do you think you’d print out all the odd numbers between 1 and 1,000,000? How about all the even numbers? See the end for a possible answer!

Now that you know loops, if you had a computer that could sing to you, you could write a program to do “99 bottles of root beer on the wall.” (After all, we’re mostly all under 21 in this class!) ☺

99 bottles of root beer on the wall!
99 bottles of root beer!
Take one down, pass it around…
98 bottles of root beer on the wall!
98 bottles of root beer on the wall!

Let’s say your computer could actually belt it out to you if you used a computer function called “sing.” Then we could brew up something like this:

`num_bottles = 99`
`while num_bottles > 0:     sing( num_bottles + " bottles of root beer on the wall! " +      num_bottles + " of root beer! Take one down, pass it     around..." )`
`     num_bottles = num_bottles - 1`
`     sing( num_bottles + " bottles of root beer on the wall!" )`

Check out a working example here, where I have the computer print out the words with a little wait in between in each lyric that is displayed.

If you want to get a little more background on loops, or if you just want to watch a really great Big Block Sing Song video about time travelers (after all, they live in loops! Looper movie, anyone?) check out our Prezi here.

After getting all loopy that night, our tech guest speaker was none other than Josh Shoemaker. Josh is a really special speaker for us all. Josh has lived side-by-side with these kids in Vine City for probably five years or more. He’s a neighbor. A mentor. A role model. Josh has coached many seasons of boys basketball. He’s earned their trust and become their confidant and faithful friend.

All these words describe a bit about who Josh Shoemaker is, but they fall far short of doing him justice. This man has literally been there every time for The Vine City Code Crew, at every single event. And he continues to be an integral and influential part of helping shape The Crew moving forward. I can’t express my gratitude to him enough. If The Code Crew has inspired any coder to reach beyond who they are or what they thought they could be, Josh has been that same inspiration to me.

Thank you Josh.

Next up in our next post, the grand finale! The coders will put together what they’ve learned to fire off a light show. Stay tuned.

#### BONUS ROUND ANSWERS!

Give these two tiny programs a try here.

`# begin program 1 - start at ONE and add a 2 each time to # get 1,3,5,7... all the odd numbers! (up to 10,000)`
`raw_input("begin ODD counting! [press enter]")`
`my_number = 1while my_number < 10001:     print my_number     my_number += 2`
`# end program 1`

What’d ya get? Now try this:

`# begin program 2 - start at ZERO and add a 2 each time to# get 2,4,6,8... all the even numbers! (up to 10,000)`
`raw_input("begin EVEN counting! [press enter]")`
`my_number = 0while my_number < 10001:     print my_number     my_number += 2`
`# end program 2`

Look at you, getting your Python programming on. Boom!

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.