-
-
Notifications
You must be signed in to change notification settings - Fork 641
Add Concept Exercise for 'randomness': Captain's Log #2683
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
Conversation
Hello. Thanks for opening a PR on Exercism 🙂 We ask that all changes to Exercism are discussed on our Community Forum before being opened on GitHub. To enforce this, we automatically close all PRs that are submitted. That doesn't mean your PR is rejected but that we want the initial discussion about it to happen on our forum where a wide range of key contributors across the Exercism ecosystem can weigh in. You can use this link to copy this into a new topic on the forum. If we decide the PR is appropriate, we'll reopen it and continue with it, so please don't delete your local branch. If you're interested in learning more about this auto-responder, please read this blog post. Note: If this PR has been pre-approved, please link back to this PR on the forum thread and a maintainer or staff member will reopen it. |
If you've used configlet, which is our tool for managing tracks and things like generating exercices, then all the needed files should be auto-generated and you shouldn't need to manually attach a UUID, but in case you do configlet can also do that. Also worth checking out our (slightly outdated) CONTRIBUTING guide. |
Errors in tests fixed, and for loops now used. Just a question - is there a toInclude method? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I wrote an entire thesis on how to calculate the expected number of rolls to get all the values in the planet class thing, but when I tried to submit it I pressed back accidentally and then lost it all. Will write it again soon...)
|
test('planet classes are valid', () => { | ||
const planetClasses = ['D', 'H', 'J', 'K', 'L', 'M', 'N', 'R', 'T', 'Y']; | ||
for (let i=0;i<4; i++){ | ||
expect(planetClasses).toContain(randomPlanetClass()) | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. So I did this again.
In order to find out how many rolls we need to see each planet class in the following string:
'DHJKLMNRTY'
...we need to make a die that's fair with each side one class. There are 10 letters in the string. This math answer for a 6-sided die pointed me to terms to find this stats answer. We are looking for the 10 * harmonic(10)
which is just shy of 30.
However, that gets us the average and we need to find out a reasonable number to use as maximum or at least a high probability (>95%, preferably >99.5%).
So I made this simulation in R.
Then I ran it 5 times:
29.2
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.0 21.0 27.0 29.2 35.0 118.0
29.2544
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.00 21.00 27.00 29.25 35.00 131.00
29.528
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.00 21.00 27.00 29.53 35.00 118.00
29.0984
Min. 1st Qu. Median Mean 3rd Qu. Max.
11.0 21.0 27.0 29.1 34.0 100.0
29.53
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.00 21.00 27.00 29.53 35.00 93.00
This tells me that the average number is spot on, and that we can use 200 rolls to get all the values, but to make it completely improbable that a correct solution yields an incomplete set, we can do it 1_000
times.
describe('randomPlanetClass', () => {
test('planet classes are valid', () => {
const expected = 'DHJKLMNRTY'
const seen = {}
for (let i=0; i < 1_000; i++){
const actual = randomPlanetClass()
expect(expected).toContain(actual)
}
})
test('all planet classes can be returned', () => {
const expected = 'DHJKLMNRTY'
const seen = {}
for (let i=0; i < 1_000; i++){
const actual = randomPlanetClass()
seen[actual] = true
}
expected(Object.keys(seen).length).toBe(expected.length);
})
// remove the other test, it's no longer necessary
})
Tests updated and uuid added. |
Added captains-log to config.json
This comment was marked as off-topic.
This comment was marked as off-topic.
@SleeplessByte when I try to use |
Can you try Once that works, continue :) |
If `max` is 1 - Math.epsilon, the result is indistinguishable from 42000, and the tests fail. To fix this, Math.epsilon must be multiplied by more than 16.
All tests (both |
Not sure if I got this one entirely right.
Is there anything else I should add or improve, or does it look good? |
This link is at least not public, if no good, and the image is probably text, so why not show text? Otherwise (and if you are keeping it from me, that is fine too!) how do you read this image? I had to get around the link, capture the image, tweak it, run it through my OCR. Would have been much less work as text. (Oh, bad news, you were not able to keep it from me, you just made me work for it!) |
Sorry! |
Co-authored-by: Victor Goff <keeperotphones@gmail.com>
Thanks. Hopefully the image did not leak the obfuscated information in the text version. I might never know. ;) |
If you work on another exercise, we have: corepack pnpm node scripts/sync.mjs |
The "Sync all exercises" action has started running. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great and good to go. I rewrote some of the parts to be more in line with how we teach things in this track but overal really great stuff @quintuple-mallard . Appreciate you took this on and brought it to completion.
I'll batch all the changes, and then merge it. Should be live in minutes. I'll write a post announcing the new exercise.
This is me. Will fix with a format locally. |
I wrote a cheesy site update that will become visible... whenever it does. I don't know how long it takes to refresh. It will look something like: |
This PR adds
hints.md
,introduction.md
,instructions.md
,config.json
,design.md
,exemplar.js
,captains-log.js
, andcaptains-log.spec.js
to a new exercise on the JavaScript track.A couple of questions to a reviewer:
.gitignore, .npmrc, LICENSE, package.json, jest.config.js, global.d.ts, eslint.config.mjs, and babel.config.js. These are not mentioned in the docs though. Should I add these, or does that happen automatically somehow?