Category Archives: Miscellaneous

Taxes and the Weekend

Saturday

I watched 5 Centimeters Per Second. Very touching. I then played LoL for few hours. I finished the day by watching The Promised Lands with Matt Damon as the main protagonist.

Sunday

I went to SF and attended the Cherry Blossom Festival. It was not that festive in my opinion. I expected a little more cultural events. But then again, I guess I had a higher expectation since it was in San Francisco. I forget that the volunteer work that I did was at festivals just like the one I attended. But I got takoyaki and they were pretty scrumptious.

lol and pushups

So my friend wanted to “get into shape” so he is doing pushups. 3 for every kill he gets in a LoL game, 1 for every assist. I decided to join him.

I just got 20 kills and 11 assists in one game. That is 71 pushups. I have only done 53 of them and I am tired. It doesn’t help that I already did 60 today.

basic Tree with traversals

I forgot to upload this yesterday. It is just practice writing tree traversals (pre/in/post order [depth] and breadth).

        var a = new Node(2);
        var b = new Node(3);
        var c = new Node(4);
        var d = new Node(6);
        var e = new Node(8);
        var g = new Node(10);
        a.left = b;
        a.right = c;
        b.left = d;
        c.right = e;
        e.right = g;
        var x = new Tree(a);
        console.log(x.DepthFirst("post"));
        console.log(x.BreadthFirst());
        function Tree(root) {
            this.root = root;
            this.DepthFirst = function(type) {
                switch (type) {
                    case "pre":
                        return this.PreOrder(this.root);
                    case "post":
                        return this.PostOrder(this.root);
                    default: // in-order
                        return this.InOrder(this.root);
                }
            };
            this.PreOrder = function(node) {
                var parentStack = [];
                var output = [];
                while (parentStack.length > 0 || node != null) {
                    if (node!=null) {
                        output.push(node.value);
                        parentStack.push(node.right);
                        node = node.left;
                    } else
                        node = parentStack.pop();
                }
                return output;
            };
            this.InOrder = function(node) {
                var parentStack = [];
                var output = [];
                while (parentStack.length >  0 || node!=null) {
                    if (node!=null) {
                        parentStack.push(node);
                        node = node.left;
                    } else {
                        node = parentStack.pop();
                        output.push(node.value);
                        node = node.right;
                    }
                }
                return output;
            };
            this.PostOrder = function(node) {
                var output = [];
                return this.PostOrderHelper(node);  
            };
            this.PostOrderHelper = function(node) {
                var output = [];
                if (node==null)
                    return [];
                output = this.PostOrderHelper(node.left);
                output = output.concat(this.PostOrderHelper(node.right));
                output.push(node.value);
                return output;
            };
            this.BreadthFirst = function() {
                var nodeQueue = [this.root];
                var output = [];
                do {
                    var node = nodeQueue.shift();
                    output.push(node.value);
                    if (node.left!=null)
                        nodeQueue.push(node.left);
                    if (node.right!=null)
                        nodeQueue.push(node.right);
                } while (nodeQueue.length > 0);
                return output;
            };
        }
        function Node(value) {
            this.left = null;
            this.right = null;
            this.value = value;
        }