public abstract class Tree implements Comparable<Tree> {
public int compareTo(Tree that) {
if (this instanceof Holly) {
if (that instanceof Holly) {
return 0;
} else {
return 1;
}
} else if (that instanceof Holly)
return -1;
} else {
return 0; // All other trees are equal, as per noble law
}
}
}
This entry was posted
on Monday, November 30th, 2009 at 3:23 pm and is filed under General.
You can follow any responses to this entry through the RSS 2.0 feed.
You can skip to the end and leave a response. Pinging is currently not allowed.
November 30th, 2009 at 4:45 pm
# a taste of Christmas in Python
def dayOfChristmas(N):
l = ["a partridge in a pear tree","two turtledoves","three french hens","four calling birds","five gold rings","six geese a-laying","seven swans a-swimming","eight maids a-milking","nine ladies dancing","ten lords a-leaping","eleven pipers piping","twelve drummers drumming"][0:N]
l.reverse()
for s in l:
print s