MEM Java Fun
- Sun's Java Homepage
- The Java Language Specification (Bathroom reading material!)
- Escape character reference (and related String/char info)
- Float/Double spec link, i.e. why doesn't 5.0/0 throw a divide by zero error?
- Helpful Java Tools (Ant, JUnit, and Clover)
- Jakarta Ant: automates building and running code tests.
- JUnit: popular framework for writing unit tests.
- Clover: shows code coverage.
- GlassFish: a web container designed to hose all of Java Enterprise Edition (JEE)
- JBoss: another option for doing what GlassFish does
- Link to the page Jayson showed with example reports (ProteomeCommons.org's Tranche Dev build)
- IO Examples (File IO Included)
- Playing with JDBC
- Download HSQLDB
- core.Database.java
- Specifications of Interest
- Tutorials
TextTwist Challenge (Link to Game)
Our first challenge will be to use the scrabble dictionary to efficiently play the TextTwist game offered by Yahoo! This challenge will have two parts: correctly unscrambling anagrams and efficiently unscramble thousands of words. Formal rules.
- Correctly unscramble the following names to a single word: "Al Kaline", "Al Green", "Eric Clapton", "Liam Brady", "Lou Reed", "Tom Cruise"
- Score at least 10k on TextTwist and send Jayson a screenshot.
- Correctly unscramble the list of words Jayson provides in a file (will provide later in the week)
- Whitespace might be included with the words. Be sure to remove it.
- Capitalization might be used with the words. Be sure to handle it.
The fastest code to correctly unscramble the list of words that Jayson provides wins the challenge. Remember that you can use buffered file I/O, multiple threads, and the profiler to speed up your code.
Files you'll need
- Enable 2k Word List
- Dictionary.java: Loads words from a file and gives you an array of Strings.
- Main.java: template for the main code.
Wednesday TextTwist Challenge Scrambled Words
The scrambled words are in the file linked below. Each word is delimited by a comma and no new-line spaces are provided.
- scrambled-words.txt
- If you are interested, here is the code that was used to make the above.
Provide your results in a file that has one line for each scrambled word. On that line specify the scrambled word followed by a comma and any words that can be made from using all letters. If more than one word is possible, delimit possible words with a comma. For example:
folo,fool,loof otps,opts,stop,pots
Rock-Paper-Scissors Challenge
Prepare yourself for an intense battle of wit. Not only are we learning Java, but we're practicing for the Rock-Paper-Scissors world championships. In this challenge you must create up to two players for a Rock-Paper-Scissors tournament.
Download the ZIP file below to get started.
- The Rock, Paper, Scissors Packages
- Tuesday's Players: RockPaperScissorsPlayers.jar (only .class files, no source!)
- Wednesday's Players: WednesdaysRockPaperScissors.jar (only .class files, no source!)
Make a sub-class of Player that plays our your ideal strategy for Rock-Paper-Scissors. Send in this player to Jayson, and he'll add it to the grand tournament that everyone is playing in.
Remember. Rock beats scissors. Paper beats rock. Scissors beats paper.
Tuesday's Rock-Paper-Scissors Player Standings
Regular player standings without including Jayson's learning player.
*** Statistics after playing 10000 tournaments ***
BadMoe: 4939 wins or 49.39%
RickPlayer: 1785 wins or 17.85%
FooPlayer: 1379 wins or 13.79%
RandomForTheWin: 1114 wins or 11.14%
PlayerThomas: 678 wins or 6.78%
BeatRepeaters: 72 wins or 0.72%
RockForTheWin: 21 wins or 0.21%
PaperForTheWin: 14 wins or 0.14%
ScissorsForTheWin: 7 wins or 0.07%
*** Tables of Wins/Loses/Ties versus a particular opponent ***
BadMoe BeatRepeaters FooPlayer PaperForTheWin PlayerThomas RandomForTheWin RickPlayer RockForTheWin ScissorsForTheWin
BadMoe 0/0/0 2699/96/152 2797/1250/406 2004/0/0 3962/242/444 1549/1645/551 4534/806/472 2063/0/0 2027/0/0
BeatRepeaters 96/2699/152 0/0/0 254/1556/242 1246/107/51 68/1771/268 768/800/252 95/2184/194 1198/86/49 1228/94/64
FooPlayer 1250/2797/406 1556/254/242 0/0/0 1498/0/0 618/1592/514 1065/1125/371 872/1713/691 1517/0/0 1553/0/0
PaperForTheWin 0/2004/0 107/1246/51 0/1498/0 0/0/0 0/1549/0 630/547/220 0/1748/0 1170/0/0 0/1250/0
PlayerThomas 242/3962/444 1771/68/268 1592/618/514 1549/0/0 0/0/0 1149/1142/338 328/2471/593 1604/0/0 1558/0/0
RandomForTheWin 1645/1549/551 800/768/252 1125/1065/371 547/630/220 1142/1149/338 0/0/0 1235/1260/433 581/600/209 663/583/204
RickPlayer 806/4534/472 2184/95/194 1713/872/691 1748/0/0 2471/328/593 1260/1235/433 0/0/0 1704/0/0 1690/0/0
RockForTheWin 0/2063/0 86/1198/49 0/1517/0 0/1170/0 0/1604/0 600/581/209 0/1704/0 0/0/0 1138/0/0
ScissorsForTheWin 0/2027/0 94/1228/64 0/1553/0 1250/0/0 0/1558/0 583/663/204 0/1690/0 0/1138/0 0/0/0
With Jayson's learning player. Ack, dynamic strategy is still dominating!
*** Statistics after playing 10000 tournaments ***
LearningRockPaperScissors: 7417 wins or 74.17%
RandomForTheWin: 1005 wins or 10.05%
BadMoe: 862 wins or 8.62%
RickPlayer: 310 wins or 3.1%
FooPlayer: 244 wins or 2.44%
PlayerThomas: 121 wins or 1.21%
BeatRepeaters: 31 wins or 0.31%
PaperForTheWin: 8 wins or 0.08%
ScissorsForTheWin: 8 wins or 0.08%
RockForTheWin: 4 wins or 0.04%
*** Tables of Wins/Loses/Ties versus a particular opponent ***
BadMoe BeatRepeaters FooPlayer LearningRockPaperScissors PaperForTheWin PlayerThomas RandomForTheWin RickPlayer RockForTheWin ScissorsForTheWin
BadMoe 0/0/0 1878/79/95 1638/577/255 261/6099/215 1453/0/0 2188/106/331 1167/1143/410 2185/350/296 1430/0/0 1431/0/0
BeatRepeaters 79/1878/95 0/0/0 207/1228/180 113/2474/103 1154/48/13 70/1439/172 728/684/229 61/1596/142 1207/66/22 1142/51/17
FooPlayer 577/1638/255 1228/207/180 0/0/0 29/4213/21 1334/0/0 453/1128/272 811/887/290 630/921/485 1284/0/0 1311/0/0
LearningRockPaperScissors 6099/261/215 2474/113/103 4213/29/21 0/0/0 1669/0/0 4124/9/2 1604/1544/522 4678/141/111 1709/0/0 1669/1/0
PaperForTheWin 0/1453/0 48/1154/13 0/1334/0 0/1669/0 0/0/0 0/1350/0 533/515/160 0/1349/0 1159/0/0 0/1092/0
PlayerThomas 106/2188/331 1439/70/172 1128/453/272 9/4124/2 1350/0/0 0/0/0 905/870/278 252/1473/390 1220/0/0 1270/0/0
RandomForTheWin 1143/1167/410 684/728/229 887/811/290 1544/1604/522 515/533/160 870/905/278 0/0/0 960/941/311 532/553/193 616/505/196
RickPlayer 350/2185/296 1596/61/142 921/630/485 141/4678/111 1349/0/0 1473/252/390 941/960/311 0/0/0 1353/0/0 1296/0/0
RockForTheWin 0/1430/0 66/1207/22 0/1284/0 0/1709/0 0/1159/0 0/1220/0 553/532/193 0/1353/0 0/0/0 1143/0/0
ScissorsForTheWin 0/1431/0 51/1142/17 0/1311/0 1/1669/0 1092/0/0 0/1270/0 505/616/196 0/1296/0 0/1143/0 0/0/0
Scrambling Code
This is the code that I used to scramble words. You don't need to run this code! It is only intended so that you can have an example of file input/output and so that you can see that I'm not using any fancy tricks.
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
/**
* This is the code that makes the random file with scrambled string values.
*/
public class MakeRandomList {
public static void main(String[] args) throws Exception {
ArrayList chars = new ArrayList();
// the output file
FileWriter fw = new FileWriter("C:/scrambled-words.txt");
// read all of the words
InputStream is = Dictionary.class.getClassLoader().getResourceAsStream("WORD.LST");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
for (String s= br.readLine(); s != null; s = br.readLine()) {
// randomly keep a word
if (Math.random() < 0.3) continue;
// sramble
char[] ca = s.trim().toCharArray();
for (char c : ca) {
chars.add(c);
}
// optionally capitalize
if (Math.random() > 0.5) {
char c = chars.remove((int)(Math.random()*chars.size()));
chars.add(Character.toUpperCase(c));
}
// optionally add some white space
if (Math.random() > 0.8) {
chars.add(' ');
}
// scramble
Collections.shuffle(chars);
// print out the word
String output = "";
for (char c : chars) {
output += c;
}
fw.write(output+",");
System.out.print(output+",");
// clear/recycle the buffer
chars.clear();
}
br.close();
isr.close();
is.close();
// close the file writer
fw.flush();
fw.close();
}
}
- Login or register to post comments
- Printer-friendly version
- jfalkner's blog
- 843 reads





