Created
June 15, 2012 00:02
-
-
Save siosio/2933736 to your computer and use it in GitHub Desktop.
なんか違うものになってしまったけど
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
class Buzz implements Comparable<Buzz> { | |
private int index | |
private Buzz(int index) { | |
this.index = index | |
} | |
def static start(int index) { | |
while (!isBuzz(index)) {index++} | |
new Buzz(index) | |
} | |
def static end(int index) { | |
new Buzz(index) | |
} | |
Buzz next() { | |
int i = index + 1 | |
while (!isBuzz(i)) {i++} | |
new Buzz(i) | |
} | |
@Override | |
int compareTo(Buzz o) { | |
this.index <=> o.index | |
} | |
@Override | |
String toString() { | |
String.valueOf(index) | |
} | |
private static isBuzz(int index) { | |
index % 3 != 0 && index % 5 == 0 | |
} | |
} | |
println (Buzz.start(1)..Buzz.end(500)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment