Skip to content

Instantly share code, notes, and snippets.

@bchetty
bchetty / MissingNumber.java
Created May 24, 2013 20:44
Missing Number Problem.
public class MissingNumber {
public static void main(String[] args) {
MissingNumber missingNum = new MissingNumber();
System.out.println("Missing Number : " + missingNum.findMissingNum(new int[] {3,1,2,5,4,7,9,8}, 9));
}
private int findMissingNum(int[] intArray, int n) {
int res = 0;
int sum = 0;
@bchetty
bchetty / MissingNumbers.java
Created May 24, 2013 20:45
Missing Number's problem.
public class MissingNumbers {
public static void main(String[] args) {
//In the below code: Array Size = 8 and n = 10.
//So 2 missing numbers!
int n = 10;
int[] intArr = new int[] {3,1,2,5,4,7,10,8};
MissingNumbers missingNums = new MissingNumbers();
int[] missingNums = missingNums.findMissingNumber(intArr, n);
@bchetty
bchetty / DatabaseResourceLoader.java
Created May 24, 2013 20:55
Seam v2 Database Resource Loader.
@Scope(ScopeType.STATELESS)
@BypassInterceptors
@Install(precedence = Install.APPLICATION, dependencies = "org.jboss.seam.security.identity")
@Name("org.jboss.seam.core.resourceLoader")
public class DatabaseResourceLoader extends ResourceLoader {
@Override
public ResourceBundle loadBundle(String bundleName) {
return new ResourceBundle() {
public Enumeration<String> getKeys() {
//Locale locale = org.jboss.seam.core.Locale.instance();
@bchetty
bchetty / SpiralWalking.java
Created May 24, 2013 21:26
Spiral Walking in a rectangular grid.
public class SpiralWalking {
public static void main(String[] args) {
SpiralWalking sw = new SpiralWalking();
String res[][] = sw.walkSpirally(10,10);
for(int i=0;i<10;i++) {
System.out.println();
for(int j=0;j<10;j++) {
System.out.print(res[i][j] + " ");
}
@bchetty
bchetty / CaliperTest1.java
Created May 24, 2013 21:31
Simple Caliper Benchmark test program.
import com.google.caliper.Param;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import java.util.HashMap;
/**
* Simple Caliper Benchmark test program.
*
* @author Babji Prashanth, Chetty
*/
@bchetty
bchetty / Run.java
Created May 31, 2013 21:19
Simple Java program to execute Mac-OS commands (For Ex: To open a Finder Window) through a Java program.
import java.io.IOException;
/**
* Simple Java program to execute Mac-OS command (For Ex: To open a Finder Window) through a Java program.
*
* @author Babji, Chetty
*/
public class Run {
public static void main(String[] params) throws IOException {
Runtime.getRuntime().exec(new String[] {"open", params[0]});
@bchetty
bchetty / MagicTrick.java
Created April 24, 2014 11:07
GCJ 2014 - Magic Trick Problem
package com.bchetty.gcj2014;
import java.util.ArrayList;
import java.util.List;
/**
* GCJ 2014 - Magic Trick Problem
*
* @author Babji, Chetty
*/
@bchetty
bchetty / CookieClicker.java
Created April 24, 2014 11:39
GCJ 2014 - 'Cookie Clicker Alpha' problem solution
package com.bchetty.gcj2014;
import java.text.DecimalFormat;
/**
* GCJ 2014 - 'Cookie Clicker Alpha' problem soultion
* @author Babji, Chetty
*/
public class CookieClicker {
@bchetty
bchetty / DeceitfulWar.java
Created April 24, 2014 11:46
GCJ 2014 - 'Deceitful War' problem solution
package com.bchetty.gcj2014;
import java.util.Iterator;
import java.util.TreeSet;
/**
* GCJ 2014 - 'Deceitful War' problem solution
*
* @author Babji, Chetty
*/
@bchetty
bchetty / Inception.java
Created April 24, 2014 20:48
Java - Recursion Depth
**
* Inception
*
* @author Babji, Chetty
*/
public class Inception {
public static void main(String[] args) {
Inception inception = new Inception();
inception.dream(0);
}