Skip to content

Instantly share code, notes, and snippets.

@siosio
Created June 15, 2012 00:02
Show Gist options
  • Save siosio/2933736 to your computer and use it in GitHub Desktop.
Save siosio/2933736 to your computer and use it in GitHub Desktop.
なんか違うものになってしまったけど
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