summaryrefslogtreecommitdiffstats
path: root/Algorithms/Part-I/1-Percolation
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2013-11-15 10:04:28 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2013-11-15 17:10:17 +0100
commit0ef8f59188456d50b71e408a4a57e64ba5e8e39a (patch)
tree5e3a525dfef2296962d3e1f1f4f8dae274f8591d /Algorithms/Part-I/1-Percolation
parentb748bc695362b353af08a9d9019876761500012f (diff)
downloadcoursera-0ef8f59188456d50b71e408a4a57e64ba5e8e39a.zip
coursera-0ef8f59188456d50b71e408a4a57e64ba5e8e39a.tar.gz
Algorithms-I : 1-Percolation: add Percolation.java
Diffstat (limited to 'Algorithms/Part-I/1-Percolation')
-rw-r--r--Algorithms/Part-I/1-Percolation/Percolation.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/Algorithms/Part-I/1-Percolation/Percolation.java b/Algorithms/Part-I/1-Percolation/Percolation.java
new file mode 100644
index 0000000..a866013
--- /dev/null
+++ b/Algorithms/Part-I/1-Percolation/Percolation.java
@@ -0,0 +1,72 @@
+/* vim: set expandtab tabstop=4 shiftwidth=4 : */
+
+// package pkgname;
+
+import java.io.File;
+import java.util.Date;
+import jargs.gnu.CmdLineParser;
+
+public class Percolation {
+ public Percolation(int N) // create N-by-N grid, with all sites blocked
+ public void open(int i, int j) // open site (row i, column j) if it is not already
+ public boolean isOpen(int i, int j) // is site (row i, column j) open?
+ public boolean isFull(int i, int j) // is site (row i, column j) full?
+ public boolean percolates() // does the system percolate?
+}
+/**
+ * Class Percolation
+ *
+ * @author <john.doe@nope.com>
+ * @date 02/03/13
+ */
+ public class Percolation {
+
+ /*
+ * print usage and exit with status 1
+ */
+ private static void printUsage () {
+ System.err.println("Usage : Percolation [{-d, --debug} a_float] [ --input file_name]");
+ System.err.println(" debug : debug verbosity");
+ System.err.println(" input : path to input file");
+ }
+
+ /**
+ * application entry point
+ */
+ public static void main (String [] args ) {
+
+ CmdLineParser parser = new CmdLineParser();
+ CmdLineParser.Option debug = parser.addIntegerOption('d',"debug");
+ CmdLineParser.Option input = parser.addStringOption("input");
+
+ try {
+ parser.parse(args);
+ } catch(CmdLineParser.OptionException e) {
+ System.err.println("\n"+e.getMessage());
+ printUsage();
+ System.exit(2);
+ }
+
+ int debugLevel = ((Integer)parser.getOptionValue(debug,new Integer(0))).intValue();
+ String inputFile = (String)parser.getOptionValue(input);
+
+ if(debugLevel>0){
+ System.out.println("Debug Trace :");
+ System.out.println("\t"+new Date( ) );
+ System.out.println("\tdebug level : "+debugLevel);
+ System.out.println("\texcel file : "+inputFile);
+ }
+
+ if(inputFile!=null && !inputFile.equals("")){
+ File f = new File(inputFile);
+ if(!f.canRead()){
+ System.err.println("Fatal Error : Unable to read "+inputFile);
+ System.exit(1);
+ }
+ }
+
+ System.exit(0);
+ }
+}
+
+