Thursday, May 1, 2014

[Minecraft Mod] Day 2

It's day 2 now since I've started looking into Java more.

So far, I have learned the following:
- Subclasses
- Generic Class, Anonymous Class, Abstract Class
- Overriding superclass's methods
- Using ArrayList

With these knowledge, with the downloaded "GameExample" project from, I was able to add a few more things to it as told by the exercise.

The exercise was to:
- add inventory system with tabs for different types of items
- add a functionality to drop an item on the map
- add weight property to items so players cannot carry more items than his limit
- add random item generation across the map

Out of these 4, I have done the last 3 because I didn't want to bother creating an Inventory Class with Tabs subclass. With time of the essence (not really...), I wanted to learn the next lecture's materials and possibly start on forging Minecraft mod today. With most of the questions and exercises given by vswe done, it is taking a longer time than I expected although now I believe I can answer the most basic interview questions.

This is a game purely made out of text so don't expect to see something great xD
Here is the link for downloading the code:

Wednesday, April 30, 2014

[Minecraft Mod] Day 1

Well, it is day 1 of starting on how to create a minecraft mod.

Even with the computer network programming that I have learned from school, I am still not too familiar with Java especially in terms of Object-Oriented Programming (OOP). 
Therefore, I have decided to take things slow and not worry about submitting anything since I have the entire summer!

So, I am watching videos starting from "Thinking with Objects"
from the website

Although the videos may be too fast-paced for somebody who has just been introduced to programming, I didn't have any problems following it. It goes fast enough for me to fully understand the problem and its solution in details.

Currently, I am writing project for exercise 2 from subclasses lecture.
Hopefully, by today I will get through "Thinking with Objects" today to start on "Forging a Minecraft Mod" tomorrow

Saturday, April 26, 2014

Summer vacation officially started!

Finally, winter semester of 2014 is done.
And now, I'm officially having summer vacation.

It has been a rough ride but thinking about projects I want to make got me excited!
I've created a list of projects I want to work on along the semester so hear me out.

I shall be taking summer school though.. so that's kind of a bummer but it's better than doing nothing I guess O_o

List of things to do over the summer:
1. Barcode jpeg generator and reader
        Basically from the wikipedia page of barcode protocol, I will create a program that will create image files, such as jpeg, for generation of such barcode with an input of a number and a reader that reads barcode jpeg file to show the number. This is my first time playing around with images in programming.. It will be my first step in creating what I had in mind long time ago.

2. Audio Cutter
        There are a lot of programs that allow us to cut audio but only to limited size. My galaxy phone's jack is currently broken so I had to move everything via Kies but due to some issues, I am only able to upload music that is less than 100MB. Given, one music mix file that I have is over 500MB, I could not find a freeware to cut this audio so it's just sitting in my computer :(
        I am probably just going to work with one file type (probably .mp3 or .mp4).

3. Resizing pictures
        Some of the e-books I read actually come out in picture files (.bmp) and its size is tremendous. I know you can simply resize the picture through something like mspaint but I wanted it done automatically with a click of a button or a commandline. So, I am going to look into it. It's probably really easy but that doesn't take away the fun in coding :D

4. Dotabuff team formation based on probability and filters
        Well, let's face it. I am in love with the game Dota and there is a website called dotabuff that tracks all the shared games played on the Dota server and it has some cool stats like top 10 heroes to play against and top 10 heroes to avoid for each hero. So, I was thinking of fetching html from each of these heroes and based on what opponents pick as their heroes, through simple calculations of probabilities provided, it suggests top 10 heroes I should pick.
        Given that 5 heroes are on the enemy team and there are many roles in the game, whether it be pusher, carry, support .., it will be a fun project with my first time dwelving into ui. I may make an android app for practice as well.

5. Android/Apple Reader
        Well, I am also planning to create a stable text reader (.txt and such) that allows a lot of customizations. Not like aesthetics but important stuff like the bg color, and font size, limitless size of text file reading.

6. Minecraft Mod
        Since I have just been introduced to Java, what better way is there to get familiar with object-oriented programming other than minecraft modding? I am overwhelmed by the vastness of minecraft mods in Mindcrack pack that I was recently introduced to by a great server Feed-The-Community.
        It's a great friendly community with lots of cool people.
        Their website is
        Visit for the tutorial in how to install Mindcrack and be awestruck by their lag-free server!!

Tuesday, January 21, 2014

[ECE361] Lab 01 - Socket Programming

So basically, today was a day I started programming in Java seriously.

I tried programming in Java but it was so different from C and C++ or any other languages I know that I just forgot about it.
I find the language very wordy for what it does (like how I need to first write the main function inside class function while "void"-ing the main!!!) Since I was always told not to use void main() in C, it just appeared awkward to me at first.

Anyways, without much difficulties, my partner and I were able to finish the lab within 2 hours where 1 hour was allocated for the TA in teaching us the language.

Then in the next 20 minutes, we were able to complete the optional "thread" lab.

The purpose of the lab was to create us a client-server architecture on the same machine.
Then after this step, we were to create a chatting program where there were no real distinctions between the client and the server except the server was listening to establish connection at first.

The IDE we used was eclipse.
With the functionality of auto-completion of words, programming in Java was so easy. (Ctrl + Space)
Moreover, eclipse has helped me add libraries whenever I tried to use a built-in function like InputStreamReader.

However, there is a question I need answering to:
Q: What is the class WriteThreadClass implements Runnable mean?

Download: (University of Toronto (U of T) ECE361 Lab 1)

Starting Winter Semester of 2014

It's been awhile since I've posted anything here.
Although to be fair, it was only for the summer break that I was maintaining this small blog.

Anyways, another semester has started and I am in high hopes of doing well this semester despite having to take 6 courses where 4 courses contain labs!!!

Some people may call me crazy but I am taking ECE344 (Operating Systems), ECE342 (Computer Hardware), ECE334 (Digital Electronics), ECE361 (Computer Networks I) as my lab courses at University of Toronto.

ECE342 and ECE334 labs seem easy and I personally think ECE361 won't be so bad as well (except for the fact that I am not so familiar with Java) but I heard from so many people that ECE344 will really screw me over in terms of time management.

But I guess I will just have to suck it up and do them step by step ahead of time.

With 3 weeks into the semester, it hasn't been so bad but it has zoomed past me really quickly.
However, I am hoping to gain a lot from each of the courses and I just wish I will not give up halfway during the semester!


Monday, July 8, 2013

[Project Euler] Problem 16 in C

Problem: Project Euler Problem 16
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
About the Problem
This problem just involves dealing with large numbers without losing precision.

Solving the Problem
This problem was not particularly hard since we have dealt with large numbers before (such as adding) like in  Problem 13.

I have just created a function where it takes two strings of numbers and multiply them to output/return a value   by reference.
void multiplyTwoNumbers(char *prod, char *num1, char *num2, int numDigits);

prod represents the result of multiplication between num1 and num2.
numDigits represent the number of digits I want to see.


Challenges Faced (Logic behind Code)
Unlike the code found in my Problem 13 solution, I have reversed the order of the numbers. This means ones digit is in char[0], tens digit is in char[1]. So, instead of writing a hundred twenty(120), the code would write (021).
I have done this because I would not need to know the length of the number in order to perform a multiplication of 2. Therefore, the code would not go through the same array twice, improving the performance.

Lastly, the only the sum of digits, which has associative property, was needed, so the ordering did not matter.

Next Step


Best Execution Time: 0.016s

Friday, July 5, 2013

[Project Euler] Problem 15 in C

Problem: Project Euler Problem 15
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
How many such routes are there through a 20×20 grid?
About the Problem
This is a problem where it asks us to create Pascal's Triangle (Please click on the link for more details) and add them all together to converge at one point.
So, I have created a Pascal's Triangle into one array of integers and added them all up to arrive at my answer.

Solving the Problem
Since I am only looking for the 20th level of the Pascal's Triangle, I could have used binomial theorem to arrive at 20th level of the Pascal's Triangle.
However, I have refrained myself from solving the problem in using binomial theorem because it felt slower to me since I need to calculate factorials of numbers up to 20. If I were to use this method for numbers over 100, I would need a much larger data (more than uint64 datatype probably) for accurately calculating the factorials.
Therefore, I had to choose with conventional way of constructing a Pascal's Triangle: series of additions.

There were two things I kept in mind while coding:
1) Minimal memory
        As a challenge to myself, instead of creating two dimensional array to store all the pascal's triangle values, I have limited myself into using only one array to sequentially go through each level of the triangle. In reality, the cost of writing the complex code outweighs the cost of memory but this is just for fun and practice :)

2) Modularity
        In case, I need to use Pascal's triangle in the future, I have tried to write the code in a clear manner as possible.      

I believe I have achieved these.

Challenges Faced (Logic behind Code)
The biggest challenge was figuring out a general pattern for adding the numbers using only one array.
So, the function that was hardest for me to write was increasePascalTriangleOneLevel(). The purpose of the function was to take an array of integers and add adjacent elements to place it in its respectable positions of the array. I found this particular hard because I needed to store its original elements without creating another array with the same size.

Naturally, in our mind, we would think
pTriangle[1] = pTriangle[0] + pTriangle[1]
pTriangle[2] = pTriangle[1] + pTriangle[2]
pTriangle[n] = pTriangle[n-1] + pTriangle[n+1]

However, this is exactly the problem I was discussing about.
Here is the picture to show the problem
Iteration 013310
Iteration 114310
Iteration 214710
Iteration 314780
Iteration 414781

You can see from iteration 2, due to lack of storing the original elements, it has given us completely wrong answers.

To prevent this from happening again, I needed to find a generalized way of adding for next level of Pascal's Triangle. Here it is:
temp[0] = pTriangle[0];  //exception of pattern at the start
temp[1] = pTriangle[1];
pTriangle[1] = temp[0] + pTriangle[1];
temp[0] = pTriangle[2];
pTriangle[2] = temp[1] + pTriangle[2];
temp[1] = pTriangle[3];
pTriangle[3] = temp[0] + pTriangle[3];
temp[n % 2] = pTriangle[n];
pTriangle[n] = temp[opposite value of n % 2] + pTriangle[n];
Note: opposite value of n % 2 means when n % 2 = 0, the result would be 1 or when n % 2 = 1, the result would be 0.

Therefore, putting all this together, I arrived at increasePascalTriangleOneLevel(); function without a problem!

By using this method, creating a 20 level pascal's triangle only resulted in 0.007s!
However, I was reminded that we have yet to add all the elements of the Pascal's Triangle to arrive at a true answer. This was easy.
All we needed to do was square each element and add them all together.

Another problem I came along, I needed to ask on stackoverflow.
I had forgotten initialize the last element of the array 0 so the code traversed outside the array giving me a hard time.
I will probably never make the same mistake again since it bothered the heck out of me all day!

Next Step


Best Execution Time: 0.007s