Skip to content

Instantly share code, notes, and snippets.

@ChrisGermano
Last active February 11, 2016 15:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisGermano/e149056e08aa7a9bcd65 to your computer and use it in GitHub Desktop.
Save ChrisGermano/e149056e08aa7a9bcd65 to your computer and use it in GitHub Desktop.
Determines the dankness of your .meme
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class dankness {
public static void main(String[] args) throws IOException {
if (!args[0].substring(args[0].lastIndexOf('.')).equals(".meme")) {
System.out.println("ERROR - File is not a .meme, aborting.");
System.exit(1);
}
FileInputStream in = null;
int foTwennies = 0;
int one = 0;
int two = 0;
try {
in = new FileInputStream(args[0]);
int c;
while ((c = in.read()) != -1) {
if (one == 52 && two == 50 && c == 48) {
foTwennies++;
one = 0;
two = 0;
continue;
}
if (one == 0) {
one = c;
} else if (one > 0 && two == 0) {
two = c;
} else if (one > 0 && two > 0) {
one = two;
two = c;
}
}
} finally {
System.out.println("File dankness: " + foTwennies);
if (in != null) {
in.close();
}
}
}
}
@ChrisGermano
Copy link
Author

Usage:
javac dankness.java
java dankness FILENAME+EXTENSION

Notes:
For easiest usage, run in same directory as the target file.
This will not increase the dankness of the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment