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

Collatz Conjecture: The Unsolvable Problem

Recently I discovered a series of videos called Numberphile. I only watched two, both about a very interesting problem: the Collatz Conjecture.

Imagine you take a number. If it is even, divide it by two, if it is odd, multiply it by three and add one. Take the next number and repeat. Simple, right?

Let’s try it with the number 7.

3 * 7 + 1 = 22

22 / 2 = 11

3 * 11 + 1 = 34

34 / 2 = 17

3 * 17 + 1 = 52

52 / 2 = 13

3 * 13 + 1 = 40

40 / 2 = 20

20 / 2 = 10

10 / 2 = 5

3 * 5 + 1 = 16

16 / 2 = 8

8 / 2 = 4

4 / 2 = 2

2 / 2 = 1

Let’s continue from 1, then.

3 * 1 + 1 = 4

4 / 2 = 2

2 / 2 = 1

The idea of the Collatz Conjecture is that it will always reach 1, and that once it reaches one, it will keep on looping 1,4,2,1,4,2 forever. Nobody knows why this phenomenon happens.

Another interesting problem comes from counting how many steps it takes to get from a certain number to 1 with the Collatz Conjecture. I wrote a program for it which you can see right here:

The problem is finding the pattern between the number and Collatz Conjecture operations. So far, no one has been able to, and some mathematicians think no one will.

Thanks for reading!

For a program which calculates the steps to get from a number to 1 using the Collatz Conjecture, click here.

Book Review: Best Practices Of Spell Design

Not too long ago, I put together a book review on the book Computational Fairy Tales. If you did not read my review, it`s a book which explains computer science through a medieval-ish story line. The author, Jeremy Kubica, wrote a sequel called Best Practices Of Spell Design. Whereas Comp(Computational Fairy Tales) teaches you about programming concepts and algorithms, Best Practices teaches you the best way to use those tools when designing software.

The Plot: Experienced wizard Marcus has a huge problem: A wizard called Hannaldous cast a spell on the castle, and while intending to create a magic shield around the castle, he accidentally puts it in the process of destruction. Marcus must now create a counter-spell, with help from his apprentice Shelly. As the book goes along, multiple software best practices are introduced.

Remarks: As a sequel to Comp, Best Practices remains in the same universe, and seems  to be a few months after the darkness is stopped in Comp. It personally taught me a lot of good coding habits that I would not find in most other coding books.

For example, I used to write an if statement like this:

if value == 3

But Best Practices taught me that to avoid accidentally changing the value, it’s safer to put the constant first such as:

if 3 == value

I also learned about unit tests for functions, and how it can help avoid errors.

Another thing I learned is refactoring, a form of optimization in which you change the structure of the code entirely, while keeping the same functionality. Before I learned about refactoring, whenever I wanted to add a certain functionality, I would just update the current structure, causing a lot of chaos. A better way is to use refactoring to restructure the code in a way to include the new functionality while keeping the code tidy and preserving the original functionality.

It also has a lot of references to Comp, such as Ivan mentioning Princess Ann`s apprenticeship under Breadstita. finally, it is packed with humor, which I love and believe should be essential to any fictional story.