Christmas Efficiency Gains: Replacing Santa with an algorithm

by Dan Zambonini

In the modern day world of technological advances, isn't it about time we replaced Santa Claus with an algorithm?


Trouble is, I'm having problems working out some of the explicit checks and equalities that need encoding. Can anyone help? This is as far as I've got (I've been referring to "Santa Claus Is Coming To Town" for the business logic):




foreach ($aoWorldPopulation as $oPerson)
{
if ($oPerson->isChild() &&
($oPerson->getNaughtyOrNice() == 'Nice'))
{
$oSanta->showerPersonWithGifts($oPerson);
}
}


Any ideas for how isChild() and getNaughtyOrNice() should be decided? Where does one stop and the other begin?


1 Comments

bazzargh
2005-12-21 09:39:45
there seems to be a bug in Santa

public class Santa {
private List list = null;
public List getList() {
if (list == null)
// making a list
synchronized(this) {
// checking it twice
if (list == null)
list = getNaughtyOrNice();
}
return list;
}
// ...
}


... no-one told Rudolf the red-faced programmer that double-checked locking was broken.