Friday, May 8, 2015

Solution to Reverse Words

This is one solution to "Reverse Words" problem in google codejam hosted at https://code.google.com/codejam/contest/351101/dashboard#s=p1

import java.io.BufferedReader;
import java.io.FileReader;

/**
 * @author: Aniruddha Dutta Chowdhury (adchowdhury@gmail.com)
 * @since: May 8, 2015
 */

public class ReverseWords {

    public static void main(String[] args) {
        String filePath = "input.txt";
       
        try {
            BufferedReader br = new BufferedReader(new FileReader(filePath));
            String sCurrentLine;
            StringBuffer sb = new StringBuffer();
            int insertIndex = 0;
            char currentChar = '\b';
            while ((sCurrentLine = br.readLine()) != null) {
                //System.out.println(sCurrentLine);
                for(int iCharCounter = 0; iCharCounter < sCurrentLine.length(); iCharCounter++) {
                    currentChar = sCurrentLine.charAt(iCharCounter);
                    if(currentChar == ' ') {
                        insertIndex = 0;
                        sb.insert(insertIndex, currentChar);
                    }else {
                        sb.insert(insertIndex++, currentChar);
                    }
                }
                System.out.println(sb);
                sb = new StringBuffer();
                insertIndex = 0;
            }
        } catch (Throwable a_th) {
            a_th.printStackTrace();
        }
    }
}

Thursday, April 2, 2015

Hack to KUKU-KUBE

Hi

Its long since my last blog. Was caught up into many things and also was looking for something interesting to post.

This is hack to the game available in below link as of the date of publishing this blog. The idea is borrowed from "Imitation Game" & "Independence Day" movie.

http://www.kuku-kube.com/


Steps to make the game simpler are as follows:
1) Open the link in browser
2) Use firebug or other javascript debug tool. That can be invoked by pressing F12 on windows machines.
3) Copy the below whole code
4) Paste in the console area and execute
5) Now play the game. All tiles should be black & white. Which gives probability of scoring around 70 per minute.

function getScript(url, success) { 
 var script = document.createElement('script');
 script.src = url;
  
 var head = document.getElementsByTagName('head')[0],
 done = false;
  
 // Attach handlers for all browsers
 script.onload = script.onreadystatechange = function() {
  
   if (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete'){    
    // callback function provided as param
    success();    
    script.onload = script.onreadystatechange = null;
    head.removeChild(script);    
   };  
  };
}

getScript('http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js',function(){
console.log(jQuery("span").size())
});
setInterval(changeColor, 100);
function changeColor(){
var previousColor = null;
jQuery("#box").find("span").each(function(index, element){
  if(index == 0){
    previousColor = null;
  }
 // console.log(index + " : " + previousColor + " : " + jQuery(this).css("background-color"))
  if(previousColor == null){
    previousColor = jQuery(this).css("background-color");
    jQuery(this).css("background-color", 'black')    
  }else  if(jQuery(this).css("background-color") == previousColor){
    jQuery(this).css("background-color", 'black')
  }else{
    jQuery(this).css("background-color", 'white')
  }
})
}