Skip to content

Instantly share code, notes, and snippets.

@bchetty
bchetty / T9Spelling.java
Created May 23, 2013 22:22
T9Spelling - GCJ 2010 (Africa)
import java.util.*;
import java.io.*;
public class T9Spelling {
public String translate(String phrase) {
HashMap<String, String> alphaMap = getKeypadDictionary();
StringBuilder sbTranslatedMessage = new StringBuilder();
for(int i=0;i<phrase.length();i++) {
if(i != 0) {
@bchetty
bchetty / AllYourBase.java
Created May 23, 2013 22:30
All Your Base - GCJ 2009
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.math.BigInteger;
import java.io.*;
public class AllYourBase {
public BigInteger convert(String str) {
BigInteger res = new BigInteger("0");
int base = 0;
@bchetty
bchetty / AlienNumbers.java
Created May 23, 2013 22:38
GCJ 2008 - Alien Numbers
public class AlienNumbers {
public String convertFromOneNumberSystemToOther(String alienNum, String srcLang, String targetLang) {
int iSrcLangBaseNum = srcLang.trim().length();
int iTgtLangBaseNum = targetLang.trim().length();
int iAlienNumInDecSystem = 0;
int iAlienNumLen = alienNum.length();
for(int i=0;i<iAlienNumLen;i++) {
iAlienNumInDecSystem += srcLang.indexOf(alienNum.charAt(i)) * Math.pow(iSrcLangBaseNum,(iAlienNumLen-1-i));
@bchetty
bchetty / ReverseWords.java
Created May 23, 2013 22:48
Reverse Words - GCJ 2010 (Africa)
import java.util.*;
import java.io.*;
public class ReverseWords {
public String reverseWords(String phrase) {
List<string> wordList = Arrays.asList(phrase.split("[ ]"));
Collections.reverse(wordList);
StringBuilder sbReverseString = new StringBuilder();
for(String word: wordList) {
@bchetty
bchetty / Googol.java
Created May 23, 2013 22:59
Googol Number
public class Googol {
public static void main(String[] args) {
long googol1 = (long) Math.pow(10,100);
System.out.println("Googol1 : " + googol1);
System.out.println("Max Value of Long : " + Long.MAX_VALUE);
BigDecimal googol2 = new BigDecimal(Math.pow(10,100) + "");
System.out.println("Googol2 : " + googol2);
BigDecimal bigDecimal = googol2.multiply(new BigDecimal(Math.PI + ""));
@bchetty
bchetty / JCompiler.java
Created May 24, 2013 20:11
Compile Java files at runtime.
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Locale;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
import javax.tools.JavaFileObject;
@bchetty
bchetty / BigIntTest.java
Created May 24, 2013 20:22
Looping through a range of BigInteger values.
import java.math.BigInteger;
public class BigIntTest {
public static void main(String[] args) {
BigInteger bigInt1 = new BigInteger("1000000000000000");
BigInteger bigInt2 = new BigInteger("1000000000000500");
//Loop from bigInt1 to bigInt2
for(BigInteger bigInt = bigInt1; bigInt.compareTo(bigInt2) < 0; bigInt = bigInt.add(BigInteger.ONE)) {
System.out.println("I'm so big now : " + bigInt);
@bchetty
bchetty / pom.xml
Created May 24, 2013 20:35
Maven-Shade plugin usage
<build>
<plugins>
<plugin>
<groupid>org.apache.maven.plugins</groupId>
<artifactid>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
@bchetty
bchetty / pom.xml
Created May 24, 2013 20:39
Maven plugin for YUI compressor.
<build>
<plugins>
<plugin>
<groupid>net.alchim31.maven</groupId>
<artifactid>yuicompressor-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compress</goal>
</goals>
@bchetty
bchetty / pom.xml
Created May 24, 2013 20:40
Plugin repository for Maven YUI compressor plugin.
<pluginrepositories>
<pluginrepository>
<name>oss.sonatype.org</name>
<id>oss.sonatype.org</id>
<url>http://oss.sonatype.org/content/groups/public</url>
</pluginRepository>
</pluginRepositories>