Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

DZone's Guide to

# Java Holiday Calendar 2016 (Day 24): How Many Santas Are There, Really?

### Yes, Virginia, there really is a Santa Claus. In fact, there might be a lot of them. Let's do some Java math to see how many Santas it takes to deliver presents around the world.

· Java Zone
Free Resource

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

Today, we are going to do some nonsense calculations. Is there a Santa, and if yes, how many Santas can we expect to find in the world?

## The Assumptions

Let us start with some assumptions. When this article was written, there was an estimate of 7,472,085,518 humans on Earth. Let us disregard the guys who live on the International Space Station, because presumably, Santa's reindeer cannot operate in near-Earth orbit. Luckily for those guys, Elon Musk can deliver their presents via Space X's delivery rocket instead.

A large number of the remaining people are not visited by Santa at all, including people of various religious affiliations or beliefs and people who are very poor. We assume that only one-third of the remaining persons are visited. We further assume that, on average, there are three persons per household (this is not unreasonable, taking the vast number of single-person-households into account). Furthermore, we assume that each person gets four presents on average (some rich ones get much more, some poor just get one, if they are lucky).

Additionally, we estimate that there is an average distance of 500 m (i.e. 0.5 km or 0.3 miles) between each household and that Santa's average sleigh speed is 4 m/s (i.e. 14 km/h or 9 mph) and that it takes Santa 1 second to drop of each present. It should be noted that the actual procedure of handing over presents differs from country to country. In the US, Santa is more likely to drop the packages down the chimney and curve the packages so that they always backspin and land in socks that are hung up near the fireplace, whereas in some European countries, he is more likely to deliver the packages in person. This is not covered in the model, though.

Because the speed of the sleigh is not extreme, Santa cannot take advantage of the fact that the Earth is rotating and that there different time zones. So, Santa can only work 24 hours.

## The Java Code

In Java, we can model the problem like this:

``````public class NumberOfSantas {

private static final long NUMBER_OF_PERSONS = 7_472_085_518L / 3;
private static final int PERSONS_PER_HOUSHOLD = 3;
private static final long NUMBER_OF_HOUSHOLDS = NUMBER_OF_PERSONS / PERSONS_PER_HOUSHOLD;
private static final int PRESENTS_PER_PERSON = 4;

private static final int AVERAGE_DISTANCE_BETWEEN_HOUSHOLDS = 500; // m (i.e. 0.5 km or 0.3 miles)
private static final int AVERAGE_SLEIGH_SPEED = 4; // 4 m/s (i.e. 14 km/h or 9 mph)
private static final int TIME_TO_DELIVER_PRESENTS = 1; // 1 s

private static final int WORKING_HOURS = 24;

public static void main(String[] args) {
long totalTimeS = NUMBER_OF_HOUSHOLDS
* (AVERAGE_DISTANCE_BETWEEN_HOUSHOLDS / AVERAGE_SLEIGH_SPEED)
+ TIME_TO_DELIVER_PRESENTS * NUMBER_OF_PERSONS * PRESENTS_PER_PERSON;

long noSantas = totalTimeS / (WORKING_HOURS * 3600);

System.out.format("There are %,d Santas in the world", noSantas);
}
}``````

Evidently, there is a large number of Santas out there because the program above outputs the following:

``````There are 1,316,455 Santas in the world
``````

(Ho, ho)^1.3 M...

Follow the Java Holiday Calendar 2016 with small tips and tricks all the way through the winter holiday season.

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:
java ,java math ,tutorial ,data model

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Opinions expressed by DZone contributors are their own.