Skip to content

Add baffling-birthdays exercise #2539

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a0915a8
Add `baffling-birthdays` exercise
ErikSchierboom Mar 6, 2025
b749603
Update exercises/baffling-birthdays/introduction.md
ErikSchierboom Mar 6, 2025
416e446
Update exercises/baffling-birthdays/introduction.md
ErikSchierboom Mar 6, 2025
e90009e
Consistency
ErikSchierboom Mar 6, 2025
17b5e11
Update instructions.md
ErikSchierboom Mar 7, 2025
9760873
Update instructions.md
ErikSchierboom Mar 7, 2025
7df140a
Update introduction.md
ErikSchierboom Mar 7, 2025
8659d9f
Update introduction.md
ErikSchierboom Mar 7, 2025
106670c
Update introduction.md
ErikSchierboom Mar 7, 2025
59258da
Lowercase birthday paradox
ErikSchierboom Mar 7, 2025
1e0ed9f
Use estimate
ErikSchierboom Mar 7, 2025
9a47667
Out of college
ErikSchierboom Mar 7, 2025
fdeb836
Change birthday to birthdates
ErikSchierboom Mar 7, 2025
6fc865c
Add leap year note
ErikSchierboom Mar 7, 2025
c8d1f72
Change quantity
ErikSchierboom Mar 7, 2025
1d6eda6
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom Mar 7, 2025
0650ae0
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom Mar 7, 2025
304daaa
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom Mar 7, 2025
a20320a
Use collection instead of set
ErikSchierboom Mar 8, 2025
a717d1d
Estimate
ErikSchierboom Mar 8, 2025
76b8f12
Simplify instructions
ErikSchierboom Mar 8, 2025
de2675f
Simplify canonical data
ErikSchierboom Mar 8, 2025
d5dfc36
Update instructions.md
ErikSchierboom Mar 8, 2025
beb85f7
Update instructions.md
ErikSchierboom Mar 8, 2025
0470709
Another attempt
ErikSchierboom Mar 8, 2025
893130f
Tweaks
ErikSchierboom Mar 9, 2025
48c7205
Update canonical-data.json
ErikSchierboom Mar 9, 2025
3af6486
Update canonical-data.json
ErikSchierboom Mar 9, 2025
3a0a257
Use nesting and improve naming
ErikSchierboom Mar 9, 2025
8f55762
More work
ErikSchierboom Mar 9, 2025
7019b71
Merge properties
ErikSchierboom Mar 10, 2025
cddceb0
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom Mar 10, 2025
ead1f83
Update exercises/baffling-birthdays/introduction.md
ErikSchierboom Mar 10, 2025
9ba5c1d
Update exercises/baffling-birthdays/instructions.md
ErikSchierboom Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 209 additions & 0 deletions exercises/baffling-birthdays/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
{
"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
}
]
}
]
}
24 changes: 24 additions & 0 deletions exercises/baffling-birthdays/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Instructions

Your task is to estimate the birthday paradox's probabilities.

To do this, you need to:

- Determine if two birthdates have the same month and day.
- 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.
~~~~
25 changes: 25 additions & 0 deletions exercises/baffling-birthdays/introduction.md
Original file line number Diff line number Diff line change
@@ -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 their birthdays.
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
4 changes: 4 additions & 0 deletions exercises/baffling-birthdays/metadata.toml
Original file line number Diff line number Diff line change
@@ -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"
Loading