Tag Archives: java

Scrabble Problem

If I give you scrabble tiles and a dictionary, determine the valid words
from your collection of tiles.

package joshho;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;

public class Runner {
	ScrabbleSet set ;
	
	private class ScrabbleSet {
		char[] chars;
		public ScrabbleSet(String[] orig){
			chars = new char[orig.length];
			for(int i=0;i chars.length) return false;
			Arrays.sort(find);
			int s=0;
			for(int i=0;i chars[j]) continue;
					if(find[i] == chars[j]){
						s=j+1;
						break;
					}
					return false;
				}
			}
			return true;
		}
	}
	
	public void load(String y){
		set = new ScrabbleSet(y.split(" "));
	}

	public static void main(String[] args) throws IOException {
		args = new String[]{"Scrabble\\data\\english4000.dic",
				"g w x b d u t z q m o i e p o"};
		FileReader fr =  new FileReader(args[0]);
		BufferedReader br = new BufferedReader(fr);

		Runner r = new Runner();
		r.load(args[1]);
		System.out.println(args[1]);
		
		String line;
		while((line = br.readLine()) != null) {
			System.out.print(line+" ");
			System.out.println(r.set.checkWord(line.toCharArray()));
		}
		br.close();
		
		
	}

}

There’s probably a better way to do this, I am interested
to see what other solutions there are.

Playing with Jars

Recently, I came across a problem when updating a jar file.
How does one update a jar file with a class file using a particular packaging?

So you have a jar file named foo.jar with two elements in it, a package (fooPackage) containing multiple class files and your manifest.
You also have a class named bar.class that is packaged by fooPackage (*see bottom).
Do you think this will package it correctly?

>> jar uf foo.jar bar.class

No. Not really. It adds bar.class to foo.jar without a hitch, but does not keep your packaging path. Instead, it adds bar.class to foo.jar, but outside the package path you want.
If this was a stand-alone java application, this will not reflect your changes when running.

With this being said, I turned to a few external solutions to solve this problem.
After hours of frustration with a few programs (ie: DJ Java Decompiler), I finally ended up using WinRAR that did the trick and placed the bar.class in the correct package path (graphically).

*Note: When I say packaged by fooPackage I mean that the .java equivalent of bar.class has the code: package fooPackage;

GNU Crypto Usage Example in Java

So, how would one implement a cipher using the GNU Crypto algorithms?

First things first, get the jars at the very least.

Next, to ensure that your implementation of the Cipher in Java will work on all Java releases, ensure that you have the Base64Encoder file locally located within your project.

From here, a good modified working example can be found here: