Last active
April 17, 2025 15:58
-
-
Save zainab-ali/231e3ded6e8241d11e3927f9521bc0cc to your computer and use it in GitHub Desktop.
London Scala User Group Pizza Calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** This app calculates the number of pizzas needed for each | |
* London Scala event. | |
* | |
* Meat, vegetarian and vegan pizzas are all a Dominos Large | |
* size. Gluten-free pizzas come in a single small size. | |
* | |
* You can run this locally with: | |
* | |
* > scala https://gist.github.com/zainab-ali/231e3ded6e8241d11e3927f9521bc0cc -- <numberOfSignupsOnMeetupDotCom> | |
* | |
* For example: | |
* > scala https://gist.github.com/zainab-ali/231e3ded6e8241d11e3927f9521bc0cc -- 70 | |
*/ | |
/** This fraction of people who sign up show up. */ | |
val attendanceRate: Double = 0.6 | |
/** We assume Large Dominos pizzas. These each have 10 slices. */ | |
val slicesPerPerson: Double = 4 | |
val slicesPerPizza: Double = 10 | |
/** Our attendees have these dietary preferences. */ | |
val fractionOfMeat: Double = 0.5 | |
val fractionOfVegetarian: Double = 0.4 | |
val fractionOfVegan: Double = 0.1 | |
enum Flavour(val fraction: Double) { | |
case Meat extends Flavour(0.45) | |
case Vegetarian extends Flavour(0.4) | |
case Vegan extends Flavour(0.1) | |
case VeganGlutenFree extends Flavour(0.05) | |
} | |
case class PizzaCount(flavour: Flavour, count: Int) | |
@main def calculatePizza(signups: Int) = { | |
val numberOfPeople = attendanceRate * signups | |
val numberOfSlices = numberOfPeople * slicesPerPerson | |
val meatSlices = numberOfSlices * fractionOfMeat | |
val vegetarianSlices = numberOfSlices * fractionOfVegetarian | |
val veganSlices = numberOfSlices * fractionOfVegan | |
val counts = Flavour.values.toList.map { flavour => | |
val numberOfPizzas = Math.ceil(numberOfSlices * flavour.fraction / slicesPerPizza) | |
PizzaCount(flavour, numberOfPizzas.toInt) | |
} | |
counts.foreach(println) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment