Created
February 17, 2012 12:46
-
-
Save jnegre/1853231 to your computer and use it in GitHub Desktop.
Possible answser for http://wouter.coekaerts.be/2012/puzzle-clowns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package you; | |
import clowns.Clown; | |
import clowns.Volkswagen; | |
public class You { | |
private static class BandOfClowns extends Clown { | |
final int id; | |
final Volkswagen vw; | |
public BandOfClowns(int id, Volkswagen vw) { | |
System.out.println("One more clown, I'm #" + id); | |
this.id = id; | |
this.vw = vw; | |
} | |
public int hashCode() { | |
if (id != 1) { | |
vw.add(new BandOfClowns(id - 1, vw)); | |
} | |
return super.hashCode(); | |
} | |
} | |
public static void main(String args[]) { | |
Volkswagen vw = new Volkswagen(); | |
vw.add(new BandOfClowns(20, vw)); | |
vw.done(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment