Skip to content

Instantly share code, notes, and snippets.

@slorber
Created February 19, 2013 14:00
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 slorber/4986150 to your computer and use it in GitHub Desktop.
Save slorber/4986150 to your computer and use it in GitHub Desktop.
import java.io.PrintStream;
import java.util.HashSet;
import java.util.Set;
/**
* @author Lorber Sebastien <i>(lorber.sebastien@gmail.com)</i>
*/
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 {
static {
PrintStream printOnlyOneStream = new PrintStream(System.out) {
private Set<String> alreadyWritten = new HashSet<String>();
@Override
public void println(String string) {
if ( !alreadyWritten.contains(string) ) {
print(string+"\n");
alreadyWritten.add(string);
}
}
};
System.setOut(printOnlyOneStream);
}
public static boolean pat() {
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment