-
-
Notifications
You must be signed in to change notification settings - Fork 554
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
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 b749603
Update exercises/baffling-birthdays/introduction.md
ErikSchierboom 416e446
Update exercises/baffling-birthdays/introduction.md
ErikSchierboom e90009e
Consistency
ErikSchierboom 17b5e11
Update instructions.md
ErikSchierboom 9760873
Update instructions.md
ErikSchierboom 7df140a
Update introduction.md
ErikSchierboom 8659d9f
Update introduction.md
ErikSchierboom 106670c
Update introduction.md
ErikSchierboom 59258da
Lowercase birthday paradox
ErikSchierboom 1e0ed9f
Use estimate
ErikSchierboom 9a47667
Out of college
ErikSchierboom fdeb836
Change birthday to birthdates
ErikSchierboom 6fc865c
Add leap year note
ErikSchierboom c8d1f72
Change quantity
ErikSchierboom 1d6eda6
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom 0650ae0
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom 304daaa
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom a20320a
Use collection instead of set
ErikSchierboom a717d1d
Estimate
ErikSchierboom 76b8f12
Simplify instructions
ErikSchierboom de2675f
Simplify canonical data
ErikSchierboom d5dfc36
Update instructions.md
ErikSchierboom beb85f7
Update instructions.md
ErikSchierboom 0470709
Another attempt
ErikSchierboom 893130f
Tweaks
ErikSchierboom 48c7205
Update canonical-data.json
ErikSchierboom 3af6486
Update canonical-data.json
ErikSchierboom 3a0a257
Use nesting and improve naming
ErikSchierboom 8f55762
More work
ErikSchierboom 7019b71
Merge properties
ErikSchierboom cddceb0
Update exercises/baffling-birthdays/canonical-data.json
ErikSchierboom ead1f83
Update exercises/baffling-birthdays/introduction.md
ErikSchierboom 9ba5c1d
Update exercises/baffling-birthdays/instructions.md
ErikSchierboom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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", | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"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"] | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"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"] | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"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 | ||
tasxatzial marked this conversation as resolved.
Show resolved
Hide resolved
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
"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 | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
{ | ||
"uuid": "e43e6b9d-d77b-4f6c-a960-0fc0129a0bc5", | ||
"description": "probability for matching birthday for seventy people", | ||
"scenarios": ["random"], | ||
"property": "probabilityForMatchingBirthdays", | ||
"input": { | ||
"groupSize": 70 | ||
}, | ||
"expected": 99.9 | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
] | ||
} |
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
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. | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
To do this, you need to: | ||
|
||
- Determine if two birthdates have the same month and day. | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- 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. | ||
jiegillet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
~~~~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. | ||
jiegillet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
~~~~ |
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
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. | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. | ||
BNAndras marked this conversation as resolved.
Show resolved
Hide resolved
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
~~~~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 | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
~~~~ | ||
|
||
[birthday-problem]: https://en.wikipedia.org/wiki/Birthday_problem | ||
ErikSchierboom marked this conversation as resolved.
Show resolved
Hide resolved
tasxatzial marked this conversation as resolved.
Show resolved
Hide resolved
|
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
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" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.