Skip to content

Instantly share code, notes, and snippets.

@toomasr
Created February 28, 2013 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toomasr/671913d846caa334c756 to your computer and use it in GitHub Desktop.
Save toomasr/671913d846caa334c756 to your computer and use it in GitHub Desktop.
import java.util.HashSet;
import java.util.Set;
public class MagicalLand {
public static void main(String[] args) {
for (int i = 0; i < (Math.random() * 500) + 2; i++) {
if (Unicorn.pat()) {
System.out.println("UNICORN #1: PAT THIS UNICORN ONCE");
}
}
for (int i = 0; i < (Math.random() * 500) + 2; i++) {
if (Unicorn.pat()) {
System.out.println("UNICORN #2: PAT THIS UNICORN ONCE");
}
}
System.out.println("END OF PROGRAM");
}
}
class Unicorn {
private static final Set<StackTraceElement> set = new HashSet<StackTraceElement>();
public static boolean pat() {
return set.add(Thread.currentThread().getStackTrace()[2]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment