Skip to content

Split the billλ︎

In a restaurant a group of friends and relatives are having a reunion dinner after a year of not seeing each other.

Once the meal comes to an end, its time to pay the bill. So how would you write code to split the bill?

Start with the simplest possible approach, with everyone paying the same.

Create a new Clojure projectλ︎

Pracitcalli Clojure CLI Config provides the :project/create alias to create projects using deps-new project.

clojure -T:project/create :template app :name practicalli/split-the-bill
(str "Create code to calculate the bill, including what each person should pay")

Tke a look at the Who am I section for ideas on how to model the bill. Also look at More Than Average for ideas on how to write code to work out how to pay the bill.

Paying what was orderedλ︎

As not everyone had eaten the same amount of food or arrived at the same time, then there was an ask for everyone to pay just what they ordered.

So create a collection to capture what each person ordered and create an itemised bill so each person knows what they should pay.

Define a detailed bill based on what each person ordered, then create an itemised bill based on each persons order

Now it was realised that what everyone ordered is not what everyone ate. So now we need to take the order and create an itemised bill based on what everyone actually ate (lets suspend believe here a little and assume everyone knows exactly what they ate, and is honest about it).

Define a detailed bill based on what each person ordered, then create an itemised bill based on each person actually ate

Spliting the bill with a Social Groupλ︎

Extend the exercise by splitting bills over multiple events and activities with multiple people.