A better system for choosing voters?

The past few days have been pretty ‘exciting’. Donald Trump has just been inaugurated to be the president of the USA, and he’s made tons of changes already(None of them very good). I keep thinking, so many people who voted for Trump made bad choices for not only themselves but their entire country! I mean, just because 2/3 of a country is unwise with voting, the other sensible 1/3 is being taken down with them! Imagine there was a cliff, and a few idiots were constantly grabbing other people, then jumping off the cliff. Won’t you hate that? Well, that’s what voting is, having people push you off cliffs.

Fortunately, I have a solution.

Behold, the Intelligent Voters course! This online course will help you vote for who is truly the candidate right for you and your country. This course will guide you through the basic principles of politics, like what tariffs really mean, and what it costs to be deported. When you finish this course, you will have a clear view of what candidates are really saying, without commercial-like campaign tactics muddying your choice. If the government agrees, taking the course will be mandatory for voting. Going back to our cliff analogy, imagine this course gating the life-ending cliff.

Is this course biased? You might think that at first, but I am not letting this course become official until it has been looked over by multiple parties.

Who can attend this course? This course is open to anyone, even if you are under 18. And yes, if you are under 18 and you pass the course, you will be able to vote, because why decline a voter if they can make clear decisions.

Okay, so I’m not actually going to establish a course like this(mostly because my country doesn’t need it, being Canadian). But it is a good idea and for anybody willing to reform our old system of democracy, I suggest this.



Game Update: Using d3.js library!

I’m sorry I didn’t post any updates on the game(or anything at all). I’ve been really busy lately, with school restarting and all, so I haven’t been able to find time for this blog.

Well, for the first post in about 23 days, I bring to you a big update for the game, in 5 characters:


Wait, what? d3.js? What is that? Well, it’s a function library for javascript to help create data-driven documents. Sounds boring right? Well, you’ll change your mind when you see what d3 can do! Imagine rainbow worms, interactive graphs, digital world maps, even web games can be made with this library!

I’ve already gone to the point in my game where I need interactive graphics, and that’s exactly what d3 provides.

Right now I’m still learning the way it works, and I made a few sample programs with it on my website. I’ll be constantly adding links to my new programs onto this post, so stay tuned!

For a colorful spin on a sine curve, click this link.

I am making a video game!

Okay, that title may have been a little shocking. But yes, I am making a video game on the Rails framework, soon to be published on the web.

The video game is all about the molecular biology of the eukaryotic cell. It may seem lame at first,  but trust me, it will be anything but lame. It also happens to be a school project.

You see, I decided to do an Independent Directed Study (IDS for short) as a school project, and as a topic to study, I chose Molecular Biology. As well as a research component, there is also a project feature in IDS, where students illustrate their research with movies, iBooks, and games. I, being a programmer, decided to make a video game. I also got a textbook to study, entitled: ‘Microbiology Of The Cell’.

In the game, you play as a constantly evolving organism. This organism will face many problems, and it is up to you to command the cells to stop it. If I had to pick a genre for it, it would be a Role Playing Game(RPG for short).

On this blog, I will constantly post logs on how my game was improved, until the game finally launches onto the web(The logs will be part of the IDS category).  Right now, I already have a few of the models, and the home screen is starting to form.

Stay tuned for more updates!


Chi-Square Analysis: The Pokemon GO Survey.

My last math assignment was to conduct a survey on a certain topic and population sample. I chose the topic to be Pokemon GO, and the sample to be 2 of the classrooms at my school. After I collected the results, I had to present them to my teacher, along with high-level analysis on the results. For many questions, I had to check whether there was a correlation between 2 facts. For that, I discovered a mathematical way to do it: chi-square analysis.

Chi-square analysis is used to check if there is a correlation between the results of a survey. Here is the formula for it:


Let me show you an example directly from the survey I conducted.

One of the things I wanted to find out was how much players liked Pokemon GO, to their level in Pokemon GO. This is the table I used:

0 10 20 30 40 Grand Total
5 2 1 3
6 1 2 3
7 1 1 2
8 1 1
9 2 2 1 1 6
10 1 1 2 4
Grand Total 1 7 8 1 2 19

Each row is the level range(10 is 10-19, 20 is 20-29), and each column is how much they like Pokemon GO.

You must now find the expected value for each cell of the table. To do so, simply multiply the column total with the row total, then dividing it by the grand total. Do this for each cell. Now that you have your expected values, do the formula for each cell, and since there is a sigma, add all of it up. Then, you should get your chi-square. What you need now is your P-value. I haven’t figured out how to calculate the P-value, so just enter your chi-square and degrees of freedom into a P-value calculator. You also need to know what the degrees of freedom are for the table. To find out, do this equation: (rowTotal – 1) * (columnTotal – 1).

I made a Google Slides presentation on the survey results. It is right below this text if you would like to see it.

For a handy chi-square calculator, click this link

Binary search and finding roots.

Binary search is one of my favourite algorithms. If you don’t know what it is, it is a searching algorithm with a logarithmic run-time and very simple logic, but it works only for sorted lists. Simply start in the middle element. If what you’re searching for is smaller then the middle element, go to the middle of the left side. If what you are searching for is bigger than the middle element, go to the middle of the right. Repeat this process until you find what you are looking for.

Surprisingly, this system can be used to find the square root of a number as we are searching for root in a sorted list of numbers on the number line. Suppose you want to find the square root of 9.

  • The middle of 0 and 9 is 4.5.
  • 4.5 squared is 20.25, not 9.
  • 9 is smaller than 20.25, so the square root of  9 should be smaller than 4.5.
  • 2.25, maybe? It is in the middle of 0 and 4.5.
  • However, 2.25 squared is 5.0625.

If you repeat that process over and over again(which I refuse to do), you will eventually reach 3, which is the correct answer.

In fact, you can even do this for cube roots, fourth roots, fifth roots, et cetera. Instead of checking the square of your current number each step, check the cube of the number power of 4, power of 5, power of… you get it.

I even created a program to execute this function, with the same logic I just explained. Down here is the gist for the program:

To use this program, click here.

Behold: The Online 4 Hours programming website!

As you may know, I love programming. And now, I am working on a webiste dedicated to the programs I make. And guess what? It is also a part of Online 4 Hours!

I will be creating connections between programs on my new website, and posts on my blog. For example, I have a blog post on voting systems, and a program that calculates the winner in an alternative vote! I already have the link to the post on my website, and the link to the program on my blog.

The website is up, and if you would like visit, just use this link.

Greek,Egyptian, and Hindu: The similarities in mythology.

I know the mythologies of many cultures. Greek, Egyptian, and Hindu mythology seem very far from each other, but there are many similarities between them which you may not have known.

Multiple gods

Okay, this is the most obvious similarity. I do find this interesting, though, for most religions nowadays believe in only one god, or none at all. However, these cultures saw the many different things that happen in the universe, and decided that one being could not have done everything

Order over chaos

Gaea and Uranus are born from chaos. The first island rises from the sea of chaos. The world and everything formed from chaos. Do you see a recurring pattern here? They all describe the very first thing in the universe, to be chaos. Surprisingly, they also describe chaos to be evil. The Egyptians called chaos Isfet, and described it as an evil force, constantly warring with Ma’at, or order. The Hindu god Shiva, an evil figure in most stories, was described to be the embodiment of chaos. Fact: Chaos is Greek for, the gap.  Nothingness.


Have you read Homer`s Illiad? Well, if you haven’t, there is a humongous war between the Greek city states and the kingdom of Troy. And you know what started it? A golden apple. In the middle of a huge wedding, The goddess Eris puts a golden apple on the table, with these words written: FOR THE FAIREST. It causes a giant argument between the goddesses, and kicks off a chain of events leading to the Trojan War. This comes to show that the Greek gods aren’t perfect, but is that trait exclusive to the Greeks? No. The world is lead to corruption for one mistake by the Egyptian god Osiris.  Indra’s pride results in the power of the Hindu Deva to vanish.  The list goes on. It is very strange to think that the beings who created everything are imperfect, and it adds a sense of reality to these otherwise myths.

It may sound crazy that there are similarities between the mythologies of three civilizations, completely isolated from each other, especially considering the major differences you can see at first glance. But hopefully, after reading this post, you will think in a different way.


LiD, and why you can become successful from studying goats.

Have you heard about LiD? It is the best concept ever to rise in education. A few years ago, professors in SFU gathered to discuss the idea of a broad education. They finally came with the conclusion that broad education sucks! And then, was born the concept of choosing one of dozens of highly interesting topics, ranging from the brilliant study of apples, to the unsolved mysteries of zebras. (But seriously, are zebras black with white stripes, or white with black stripes?). LiD was created!

In fact, many people can become successful using this system. Imagine you study goats as your LiD topic. During your observations, you realize that goats eat cash. Using this knowledge, you find work as a realtor!

One of the best parts of this system is the rule that you cannot change your topic. Imagine a boy who is given the LiD topic of jungles. He goes so extreme into his study, he retreats into the jungles of India! after three years, he returns to the city, knowing the jungle like the back of his hand. He goes to his teacher and asks, “I already know all there is about the jungle, for I have spent three years living with a savage pack of wolves in India. May I please change my LiD topic?” Guess what the teacher answered from the below options:

A: Why, of course you can change your topic!

B: No way, nobody can change a LiD topic!

C: Wait a second…

The answer is obviously B! Everybody knows LiD topics are for life! Three years studying jungles is nothing, even if you spend it living like Mowgli! The topic of jungles is almost as broad as the topic of metal!

Another good thing is that silly topics aren’t available as LiD topics. Cause really, who would waste their time studying computer science, when instead you can learn about the fascinating properties of wool! After all, this is the 21st century, and cotton farming may be the most important job there is! I mean, programming jobs are so 19th century, which is pathetic, considering JavaScript was made in 1995!

Conclusion: All shall follow the practices of LiD!(Even if your topic is rivers.)

Behold: The Collatz Conjecture Library!

You might have read my post on the Collatz Conjecture. If you didn’t, you can read it with this link. If you read it, you know I talked about a cool problem called the Collatz Conjecture, and also showed you a piece of code I made. Well, I updated the code, into a library of functions meant for calculating numbers on the Collatz Conjecture. I have the Gist right here:

There is a class called Collatz, and inside it 6 methods. The first two are simply for returning variables, nothing cool. The most important method inside it is find_steps, which calculates the amount of steps it takes to get from a certain number to 1. The find_max_steps method sees which number from a range of 1 to the method argument has the most steps. The final method, find_smallest steps, returns the smallest number whose steps are more than itself times the argument.

I’m thinking of posting this as a GitHub project, once I improve it. If you have any suggestions for more methods, or just to increase quality, please write in the comments. Thanks!

Voting: The big problems with a “Majority Rules” system.

Recently, school started, and we had to vote for the name of our class pet(which is a venus flytrap). These were the names up for voting:

  • Mochi
  • Jaws
  • Venus
  • Trapper
  • Gardenia
  • Furious Destroyer
  • Miri
  • Cilan

The voting system we were using was a system called First Past The Post, or Majority Rules. Just like the name describes, majority rules. There is a problem with that. For example, imagine these were the results of the election:

  • Mochi = 12%
  • Jaws = 13%
  • Venus = 13%
  • Trapper = 12%
  • Gardenia = 14%
  • Furious Destroyer = 13%
  • Miri = 12%
  • Cilan = 11%

Under First Past The Post, Gardenia would have won, since it has the most votes of any other name. However, it only beat the biggest loser, Cilan, by 3%, which in a class of 24 kids is basically nothing. in fact, 86% of the class voted against Gardenia, so that is very un-representative.

Fortunately, there is a better voting system. Single Transferable Vote, or STV,

STV can be used to select any number of candidates for one district. In this case we only need one, so to win, a candidate requires 100% of the vote. Let’s see how that works..

On election day,  voters do not write one candidate on their ballot. Instead, they rank all of the candidates from favorite to least favorite.  This is how the same election will go in STV:

  • Mochi = 12%
  • Jaws = 13%
  • Venus = 13%
  • Trapper = 12%
  • Gardenia = 14%
  • Furious Destroyer = 13%
  • Miri = 12%
  • Cilan = 11%

As you can see, no one has 100% of the vote yet. So, in each round, eliminate the biggest loser. In this case, the biggest loser is Cilan. Let’s say that the Cilan voters listed Gardenia as their second choice. Now, the results look more like this:

  • Mochi = 12%
  • Jaws = 13%
  • Venus = 13%
  • Trapper = 12%
  • Gardenia = 25%
  • Furious Destroyer = 13%
  • Miri = 12%

Still, no one has 100%. So, we eliminate the next biggest loser.

In this case, it’s a tie between Mochi, Trapper, and Miri. Suppose Mochi and Miri voters both listed each other as their second choice. Both of them are out, so we do the third choices, which for both voters is Venus. And let’s say Trapper voters split between Jaws and Furious Destroyer as their second choice. We will assume that it’s a 50-50 split, so now the results look like this:

  • Jaws = 19%
  • Venus = 37%
  • Gardenia = 25%
  • Furious Destroyer = 19%

The next biggest losers are Jaws and Furious Destroyer, so we eliminate them. Let’s say all of the voters on Jaws or Furious Destroyer listed Venus as their second/third choice. So those votes go to Venus, and the results look like this:

  • Venus = 75%
  • Gardenia = 25%

There are only two names left, and Venus obviously has the majority. So Venus wins.

The best part about this method of voting is that everyone feels represented. Mochi and Miri voters chose Venus as their second choice. Jaws voters chose Venus second, and so did Furious Destroyer voters. Trapper voters chose Venus as their third choice. last but not least, Gardenia and Cilan voters all chose Venus as their third choice.

Another good thing about STV is that it works well when multiple candidates can be chosen. You just divide the number of people you want to choose by 100.

Imagine that the USA decides to send three representatives from the state of California, and there are five people running.

  • Bob
  • Jim
  • Sally
  • Darth Vader
  • Mike

When people vote, the election goes something like this:

  • Bob = 10%
  • Jim = 10%
  • Sally = 10%
  • Darth Vader = 60% – Winner
  • Mike = 10%

In First Past The Post, Darth Vader would have won the first seat, but everyone else is tied, and there are still two seats left.

However, under STV, a candidate needs 100/number of winners to win. Darth Vader has 60 percent of the vote, and he was the only one to cross the 33% percent needed to win, so we take his extra votes and redistribute them.

Suppose every one who selected Darth Vader chose a different candidate as their second choice. If 3/8th of Vader voters chose Bob, 1/4 Jim, 1/4 Sally, and 1/8 Mike, then the results look like this:

  • Bob = 32.5%
  • Jim = 25%
  • Sally = 25%
  • Darth Vader = 33% – Winner
  • Mike = 17.5%

Then, the election continues, with votes being transferred through all the candidates.

And that, readers, is Single Transferable Vote.

Please tell your teacher about this the next time you vote for the movie you are watching in class.

For a program which calculates the result of a STV election with one winner(AKA an alternative vote election),  click here