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 5 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
176 changes: 176 additions & 0 deletions exercises/baffling-birthdays/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"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": [
{
"uuid": "f7b3eb26-bcfc-4c1e-a2de-af07afc33f45",
"description": "matching birthday for same date",
"property": "matchingBirthday",
"input": {
"birthday1": "2000-01-01",
"birthday2": "2000-01-01"
},
"expected": true
},
{
"uuid": "7193409a-6e16-4bcb-b4cc-9ffe55f79b25",
"description": "matching birthday for same year and month but different day",
"property": "matchingBirthday",
"input": {
"birthday1": "2012-05-09",
"birthday2": "2012-05-17"
},
"expected": false
},
{
"uuid": "d04db648-121b-4b72-93e8-d7d2dced4495",
"description": "matching birthday for same month and day but different year",
"property": "matchingBirthday",
"input": {
"birthday1": "1999-10-23",
"birthday2": "1988-10-23"
},
"expected": true
},
{
"uuid": "3c8bd0f0-14c6-4d4c-975a-4c636bfdc233",
"description": "matching birthday for same year but different month and day",
"property": "matchingBirthday",
"input": {
"birthday1": "2007-12-19",
"birthday2": "2007-04-27"
},
"expected": false
},
{
"uuid": "df5daba6-0879-4480-883c-e855c99cdaa3",
"description": "matching birthday for different year month and day",
"property": "matchingBirthday",
"input": {
"birthday1": "1997-08-04",
"birthday2": "1963-11-23"
},
"expected": false
},
{
"uuid": "70b38cea-d234-4697-b146-7d130cd4ee12",
"description": "random birthdays return specified number of birthdays",
"scenarios": ["random"],
"property": "randomBirthdays",
"input": {},
"expected": "length == groupsize"
},
{
"uuid": "d9d5b7d3-5fea-4752-b9c1-3fcd176d1b03",
"description": "random birthdays have fixed year per batch",
"scenarios": ["random"],
"property": "randomBirthdays",
"input": {},
"expected": {
"years": {
"fixed": true
}
}
},
{
"uuid": "8da69a53-6900-4b63-897d-9f025f149fd2",
"description": "random birthdays have random year between batches",
"scenarios": ["random"],
"property": "randomBirthdays",
"input": {},
"expected": {
"years": {
"random": true
}
}
},
{
"uuid": "d1074327-f68c-4c8a-b0ff-e3730d0f0521",
"description": "random birthdays have random months",
"scenarios": ["random"],
"property": "randomBirthdays",
"input": {},
"expected": {
"months": {
"random": true
}
}
},
{
"uuid": "7df706b3-c3f5-471d-9563-23a4d0577940",
"description": "random birthdays have random days",
"scenarios": ["random"],
"property": "randomBirthdays",
"input": {},
"expected": {
"days": {
"random": true
}
}
},
{
"uuid": "ade37c87-f41d-4929-962a-286b4d1d048a",
"description": "has matching birthdays with matching birthday pair",
"property": "hasMatchingBirthdays",
"input": {
"birthdays": ["1970-01-19", "1975-06-03", "2003-01-19"]
},
"expected": true
},
{
"uuid": "1d155b33-c6e1-46b9-81fa-09123ae378ea",
"description": "has matching birthdays without matching birthday pair",
"property": "hasMatchingBirthdays",
"input": {
"birthdays": ["1984-04-05", "2000-09-17", "1966-10-12"]
},
"expected": false
},
{
"uuid": "89a462a4-4265-4912-9506-fb027913f221",
"description": "probability for matching birthday for one person",
"scenarios": ["random"],
"property": "probabilityForMatchingBirthdays",
"input": {
"groupSize": 1
},
"expected": 0.0
},
{
"uuid": "ec31c787-0ebb-4548-970c-5dcb4eadfb5f",
"description": "probability for matching birthday for ten people",
"scenarios": ["random"],
"property": "probabilityForMatchingBirthdays",
"input": {
"groupSize": 10
},
"expected": 11.7
},
{
"uuid": "b548afac-a451-46a3-9bb0-cb1f60c48e2f",
"description": "probability for matching birthday for twenty-three people",
"scenarios": ["random"],
"property": "probabilityForMatchingBirthdays",
"input": {
"groupSize": 23
},
"expected": 50.7
},
{
"uuid": "e43e6b9d-d77b-4f6c-a960-0fc0129a0bc5",
"description": "probability for matching birthday for seventy people",
"scenarios": ["random"],
"property": "probabilityForMatchingBirthdays",
"input": {
"groupSize": 70
},
"expected": 99.9
}
]
}
15 changes: 15 additions & 0 deletions exercises/baffling-birthdays/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Instructions

Your task is to implement a solution that verifies 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 set of randomly generated birthdates contains at least one matching pair.
- Calculate the probability of at least one match for different group sizes.

~~~~exercism/caution
The Birthday Paradox assumes that birthdays are uniformly distributed within a single year.
While the year should vary between different random birthdate generation calls, all birthdates within a single call must share the same year.
~~~~
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 graduation, 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 365 possible birthdays, so you confidently accept.

To your astonishment, after collecting just 32 birthdays, you've already found a match.
Magnanimous, 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 = "Verify the Birthday Paradox's probabilities."
source = "Erik Schierboom"
source_url = "https://github.com/exercism/problem-specifications/pull/2539"
Loading