diff --git a/exercises/baffling-birthdays/canonical-data.json b/exercises/baffling-birthdays/canonical-data.json new file mode 100644 index 0000000000..20c27169e3 --- /dev/null +++ b/exercises/baffling-birthdays/canonical-data.json @@ -0,0 +1,208 @@ +{ + "exercise": "baffling-birthdays", + "comments": [ + "Dates are formatted as 'YYYY-MM-DD'.", + "", + "To increase the likelihood of consistent result, the tests should run the code returning random results many times.", + "", + "The expected probability values should be compared using some tolerance to allow for small deviations." + ], + "cases": [ + { + "description": "shared birthday", + "cases": [ + { + "uuid": "716dcc2b-8fe4-4fc9-8c48-cbe70d8e6b67", + "description": "one birthdate", + "property": "sharedBirthday", + "input": { + "birthdates": ["2000-01-01"] + }, + "expected": false + }, + { + "uuid": "f7b3eb26-bcfc-4c1e-a2de-af07afc33f45", + "description": "two birthdates with same year, month, and day", + "property": "sharedBirthday", + "input": { + "birthdates": ["2000-01-01", "2000-01-01"] + }, + "expected": true + }, + { + "uuid": "7193409a-6e16-4bcb-b4cc-9ffe55f79b25", + "description": "two birthdates with same year and month, but different day", + "property": "sharedBirthday", + "input": { + "birthdates": ["2012-05-09", "2012-05-17"] + }, + "expected": false + }, + { + "uuid": "d04db648-121b-4b72-93e8-d7d2dced4495", + "description": "two birthdates with same month and day, but different year", + "property": "sharedBirthday", + "input": { + "birthdates": ["1999-10-23", "1988-10-23"] + }, + "expected": true + }, + { + "uuid": "3c8bd0f0-14c6-4d4c-975a-4c636bfdc233", + "description": "two birthdates with same year, but different month and day", + "property": "sharedBirthday", + "input": { + "birthdates": ["2007-12-19", "2007-04-27"] + }, + "expected": false + }, + { + "uuid": "df5daba6-0879-4480-883c-e855c99cdaa3", + "description": "two birthdates with different year, month, and day", + "property": "sharedBirthday", + "input": { + "birthdates": ["1997-08-04", "1963-11-23"] + }, + "expected": false + }, + { + "uuid": "0c17b220-cbb9-4bd7-872f-373044c7b406", + "description": "multiple birthdates without shared birthday", + "property": "sharedBirthday", + "input": { + "birthdates": [ + "1966-07-29", + "1977-02-12", + "2001-12-25", + "1980-11-10" + ] + }, + "expected": false + }, + { + "uuid": "966d6b0b-5c0a-4b8c-bc2d-64939ada49f8", + "description": "multiple birthdates with one shared birthday", + "property": "sharedBirthday", + "input": { + "birthdates": [ + "1966-07-29", + "1977-02-12", + "2001-07-29", + "1980-11-10" + ] + }, + "expected": true + }, + { + "uuid": "b7937d28-403b-4500-acce-4d9fe3a9620d", + "description": "multiple birthdates with more than one shared birthday", + "property": "sharedBirthday", + "input": { + "birthdates": [ + "1966-07-29", + "1977-02-12", + "2001-12-25", + "1980-07-29", + "2019-02-12" + ] + }, + "expected": true + } + ] + }, + { + "description": "random birthdates", + "cases": [ + { + "uuid": "70b38cea-d234-4697-b146-7d130cd4ee12", + "description": "generate requested number of birthdates", + "scenarios": ["random"], + "property": "randomBirthdates", + "input": {}, + "expected": "length == groupsize" + }, + { + "uuid": "d9d5b7d3-5fea-4752-b9c1-3fcd176d1b03", + "description": "years are not leap years", + "scenarios": ["random"], + "property": "randomBirthdates", + "input": {}, + "expected": { + "years": { + "leapYear": false + } + } + }, + { + "uuid": "d1074327-f68c-4c8a-b0ff-e3730d0f0521", + "description": "months are random", + "scenarios": ["random"], + "property": "randomBirthdates", + "input": {}, + "expected": { + "months": { + "random": true + } + } + }, + { + "uuid": "7df706b3-c3f5-471d-9563-23a4d0577940", + "description": "days are random", + "scenarios": ["random"], + "property": "randomBirthdates", + "input": {}, + "expected": { + "days": { + "random": true + } + } + } + ] + }, + { + "description": "estimated probability of at least one shared birthday", + "cases": [ + { + "uuid": "89a462a4-4265-4912-9506-fb027913f221", + "description": "for one person", + "scenarios": ["random"], + "property": "estimatedProbabilityOfSharedBirthday", + "input": { + "groupSize": 1 + }, + "expected": 0.0 + }, + { + "uuid": "ec31c787-0ebb-4548-970c-5dcb4eadfb5f", + "description": "among ten people", + "scenarios": ["random"], + "property": "estimatedProbabilityOfSharedBirthday", + "input": { + "groupSize": 10 + }, + "expected": 11.694818 + }, + { + "uuid": "b548afac-a451-46a3-9bb0-cb1f60c48e2f", + "description": "among twenty-three people", + "scenarios": ["random"], + "property": "estimatedProbabilityOfSharedBirthday", + "input": { + "groupSize": 23 + }, + "expected": 50.729723 + }, + { + "uuid": "e43e6b9d-d77b-4f6c-a960-0fc0129a0bc5", + "description": "among seventy people", + "scenarios": ["random"], + "property": "estimatedProbabilityOfSharedBirthday", + "input": { + "groupSize": 70 + }, + "expected": 99.915958 + } + ] + } + ] +} diff --git a/exercises/baffling-birthdays/instructions.md b/exercises/baffling-birthdays/instructions.md new file mode 100644 index 0000000000..a01ec86796 --- /dev/null +++ b/exercises/baffling-birthdays/instructions.md @@ -0,0 +1,23 @@ +# Instructions + +Your task is to estimate the birthday paradox's probabilities. + +To do this, you need to: + +- Generate random birthdates. +- Check if a collection of randomly generated birthdates contains at least two with the same birthday. +- Estimate the probability that at least two people in a group share the same birthday for different group sizes. + +~~~~exercism/note +A birthdate includes the full date of birth (year, month, and day), whereas a birthday refers only to the month and day, which repeat each year. +Two birthdates with the same month and day correspond to the same birthday. +~~~~ + +~~~~exercism/caution +The birthday paradox assumes that: + +- There are 365 possible birthdays (no leap years). +- Each birthday is equally likely (uniform distribution). + +Your implementation must follow these assumptions. +~~~~ diff --git a/exercises/baffling-birthdays/introduction.md b/exercises/baffling-birthdays/introduction.md new file mode 100644 index 0000000000..97dabd1e6c --- /dev/null +++ b/exercises/baffling-birthdays/introduction.md @@ -0,0 +1,25 @@ +# Introduction + +Fresh out of college, you're throwing a huge party to celebrate with friends and family. +Over 70 people have shown up, including your mildly eccentric Uncle Ted. + +In one of his usual antics, he bets you £100 that at least two people in the room share the same birthday. +That sounds ridiculous — there are many more possible birthdays than there are guests, so you confidently accept. + +To your astonishment, after collecting the birthdays of just 32 guests, you've already found two guests that share the same birthday. +Accepting your loss, you hand Uncle Ted his £100, but something feels off. + +The next day, curiosity gets the better of you. +A quick web search leads you to the [birthday paradox][birthday-problem], which reveals that with just 23 people, the probability of a shared birthday exceeds 50%. + +Ah. So _that's_ why Uncle Ted was so confident. + +Determined to turn the tables, you start looking up other paradoxes; next time, _you'll_ be the one making the bets. + +~~~~exercism/note +The birthday paradox is a [veridical paradox][veridical-paradox]: even though it feels wrong, it is actually true. + +[veridical-paradox]: https://en.wikipedia.org/wiki/Paradox#Quine's_classification +~~~~ + +[birthday-problem]: https://en.wikipedia.org/wiki/Birthday_problem diff --git a/exercises/baffling-birthdays/metadata.toml b/exercises/baffling-birthdays/metadata.toml new file mode 100644 index 0000000000..11ac9d0f63 --- /dev/null +++ b/exercises/baffling-birthdays/metadata.toml @@ -0,0 +1,4 @@ +title = "Baffling Birthdays" +blurb = "Estimate the birthday paradox's probabilities." +source = "Erik Schierboom" +source_url = "https://github.com/exercism/problem-specifications/pull/2539"