Skip to content

Instantly share code, notes, and snippets.

@mcgray
Created February 19, 2013 21:15
Show Gist options
  • Save mcgray/4989993 to your computer and use it in GitHub Desktop.
Save mcgray/4989993 to your computer and use it in GitHub Desktop.
ZT Magical Java Puzzle: “Pat The Unicorns” solution
public class Unicorn {
private static String line;
public static boolean pat() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
if (line == null) {
line = stackTrace[2].toString().split(":")[1];
return true;
} else if (!line.equals(stackTrace[2].toString().split(":")[1])) {
line = stackTrace[2].toString().split(":")[1];
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment