Thursday, December 4, 2014

Breaking YouTube: Thoughts on Psy's Gangnam Style getting all the views

In the past few days, I have seen a few articles about Psy's Gangnam Style "breaking YouTube." In some of the articles, they are claiming that the video broke YouTube, or almost broke YouTube. Here are three articles that I have seen on my Facebook feed in the last couple days about this fascinating event!

http://www.bbc.com/news/world-asia-30288542
http://www.smosh.com/smosh-pit/articles/psy-nearly-brings-down-youtube
Or for those who want to see it in Korean:
http://www.huffingtonpost.kr/2014/12/03/story_n_6260814.html


Looking at these links, I quickly realized that Psy's video didn't break YouTube, it simply found a bug in the code. What happened is that Gangnam Style simply hit the maximum value for a computer integer and the view count stopped there.  Integers are sometimes called "whole numbers," and computers often use 32-bit integers, meaning that the computer uses 32 bits (or 1's and 0's) to store the value of the number. I find it interesting that the view count stopped, because other things could have happened. Consider the following C program:
#include <stdio.h>

int main()
{
    int value = 2147483647;
    printf("2,147,483,674 + 1 = %d\n", value + 1);
    return 0;
}

If you compile and run this program, you will see the output:

2,147,483,674 + 1 = -2147483648

Had YouTube just kept adding to the count past the maximum, we would have seen a negative number of views. This tells us that the number 2,147,483,648 is the max value for a 32-bit integer. It also tells us that something was in place to prevent this number from wrapping around to a negative number. Perhaps there was a check that the the new view count can't be less than the last view count, or perhaps that negative view counts aren't allowed.

Also YouTube could have prolonged this problem by using something called an "unsigned int," meaning that it only used positive numbers (hence doubling the maximum value).

YouTube has now apparently upgraded to 64-bit integers, creating a new max value of 9,223,372,036,854,775,807. With this, each person on Earth would need to watch the video an average of 1,294,508,356 times before it broke again! However, they could have used unsigned 64-bit integers for a maximum view count of 18,446,744,073,709,551,615, but I guess 9.22 quintillion views was enough for YouTube.

So, how long would it take everyone on Earth to watch the video and reach the limit? If we assume each person is only using one computer at a time, we can try to guess.
Psy's video has a time of 4:12 or 252 seconds, so all people on earth would need to watch it for about the next 326,216,105,712 seconds, 5,436,935,095 minutes, 90,615,584 hours, 3,775,649 days, 10337 years, 1033.7 decades, 103 centuries, or 10 millennia.

Let's all open our browsers and watch the video a few more times!

Thursday, April 17, 2014

Khan Academy & Friday Blogging

I just noticed that I haven't written anything in over a year, so I am going to try and do a better job of posting regular content. Hopefully I will find time in my schedule to post something every Friday, but we will see if I can keep that going.

Khan Academy Math


My Mission Progress today
This week I want to talk about Khan Academy (www.khanacademy.org).  I have been playing with Khan Academy to keep my math skills nice and sharp. OK, my math is probably beyond most of what is on Khan Academy, but I do find that the math drills on the site keep me mindful of "simple" mistakes that I often make. Also they do dive into some pretty in depth topics from calculus and differential equations, so if somebody has mastered all the math on Khan Academy they know a lot of math.

One of my goals on Khan Academy is to get a 100% completion for all the math lessons. At first I thought it would all be "trivial", but working through the statistics exercises helped me to realize there are a few bits and pieces that need to be brushed up. I'm also hoping that they will continue to add mastery problems from calculus and differential equations.

I had played around with Khan Academy back when I was a high school teacher and I liked the setup, but it was a little bulky to try and master everything from the past. So when I logged in recently I was pleased to see that they added a new Mastery Challenge feature that allows you to quickly gain mastery in topics; this is much nicer than the previous method requiring repeated completion of drills. As a user you can gain mastery through a mastery challenge (kind of like a test) or through practice (kind of like homework).  Mastery challenge is a quicker way to gain mastery so I have been working on that to better optimize my time on the site.

Sample Mastery Challenge problem
If I was a high school teacher again I would want to tell my class, "Hey just go play with Khan Academy". Sure, this might not go over well with the administration, but this site does a really good job of assessment. As a teacher I always wanted to be more of a coach than an authoritarian, and I think the current Khan Academy website allows for teachers to act in a role that is more a helper and facilitator, then the role of a lecturer.  When I look at the math questions they are doing a really good job of asking a wide range of questions to check for understanding. They ask questions in multiple ways, and find a way to work inquiry into their assessment. Overall I think any math teacher should be aware of the current state of the website.

Programming

They also have pages to teach programming, so I have been poking my head around those lessons. They have a very in depth system for teaching Javascript, a language that I don't know well and haven't used much. Despite my lack of experience in Javascript I can see that are taking a good approach to teaching programming.

Community of Programmers

They have created a community of programmers by allowing students to share their programs online. Sometimes I have fun just going through the programs and playing games people have made.

What makes this really cool is that if someone likes a game, they can take the program and modify it! This is the perfect way to teach students to write readable code, so that it can be more easily shared with other people. A lot of non-programmers and new-programmers don't realize that it is important to have good comments and good formatting of a program because people spend more time reading code than writing code. I wish this was around when I taught my intro to programming high school course!

Cryptology

So while the majority of the programming on Khan Academy is focused around Javascript they have some other interesting units to teach topics in Computer Science. I've been having fun going through the site playing with some of the Computer Science activities for teaching Cryptography and code-breaking. Most of what I have done so far is very trivial, but it is a fantastic introduction to cryptology. I haven't got that far into the lessons, but I hope that they get into the connection between number theory and cryptology at some point.

Currently they have some very cool activities allowing people to play with ancient cryptology (I haven't played with the modern stuff yet, but I'm guessing there are programs for that too). Like the general programming lessons the crypto programs are also a part of the community, so anyone can take the programs and play with them and share them with others.

My Khan Academy Energy Points as of today

Other Topics

While my focus has been to look at math and programming topics, I do want to point out some of the other topics available to study on the website. I love science and plan to work through a lot of these lessons, but I haven't had a chance to yet. In the past they were just videos online, but seeing how they have overhauled the math/programming lessons I am guessing that if they are "Video Only" they will probably be turned into awesome lessons before too long.

Here is the topic list with most of the non math topics:

Science Topics:

Biology, Physics, Chemistry, Organic Chemistry, Cosmology and Astronomy, Health and Medicine,

Economics:

Microeconomics, Macroeconomics, Finance and Capital markets, Entrepreneurship

Humanities:

History, Art History, American Civics

Test Prep:

SAT, MCAT, GMAT, CAHSEE, IIT JEE, AP Art History

From the various topics on the website I think it would be fun to look at some of the science projects and play with them. Perhaps I will post some of them online here if I find anything interesting.


Ok, so that was what I had on my chest about Khan Academy.
Like I mentioned earlier I hope to try and write something every week.