Skip to content

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

Merged
merged 52 commits into from
Jun 20, 2025

Conversation

quintuple-mallard
Copy link
Contributor

This PR adds hints.md,introduction.md, instructions.md, config.json, design.md, exemplar.js, captains-log.js, and captains-log.spec.js to a new exercise on the JavaScript track.

A couple of questions to a reviewer:

  • The other exercises have these files:
    .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?
  • How do I generate a UUID?

Copy link
Contributor

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.

@github-actions github-actions bot closed this Jun 18, 2025
@Cool-Katt Cool-Katt reopened this Jun 18, 2025
@Cool-Katt
Copy link
Contributor

Cool-Katt commented Jun 18, 2025

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.

@quintuple-mallard
Copy link
Contributor Author

Errors in tests fixed, and for loops now used.

Just a question - is there a toInclude method?

Copy link
Member

@SleeplessByte SleeplessByte left a 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...)

@SleeplessByte
Copy link
Member

Just a question - is there a toInclude method?

Yes: toContain(item)

Comment on lines 45 to 50
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())
}
});
Copy link
Member

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
})

@quintuple-mallard
Copy link
Contributor Author

Tests updated and uuid added.

This comment was marked as off-topic.

@quintuple-mallard
Copy link
Contributor Author

@SleeplessByte when I try to use corepack enable or pnpm install from the track's root directory I am given the message 'corepack' is not recognized as an internal or external command,
operable program or batch file. (or 'pnpm' is not recognized as an internal or external command,
operable program or batch file. , in the case of pnpm)

@SleeplessByte
Copy link
Member

@SleeplessByte when I try to use corepack enable or pnpm install from the track's root directory I am given the message 'corepack' is not recognized as an internal or external command, operable program or batch file. (or 'pnpm' is not recognized as an internal or external command, operable program or batch file. , in the case of pnpm)

Can you try node -v. It should say 22.x.y or 20.x.y. If it says not recognised or similar, or if the version is low, you either do not have Node.JS, or it's no longer supported. In that case go to Node.js and press the download button, install, then restart your computer / open a new terminal. Try node -v again.

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.
@quintuple-mallard
Copy link
Contributor Author

All tests (both configlet and corepack pnpm node) are now passing.
It seems that .gitignore, .npmrc, LICENSE, package.json, jest.config.js, global.d.ts, eslint.config.mjs, and babel.config.js are the same across exercises, should I go ahead and add them?

@quintuple-mallard
Copy link
Contributor Author

Is there anything else I should add or improve, or does it look good?

@kotp
Copy link
Member

kotp commented Jun 20, 2025

@SleeplessByte Thanks! I finally got it to work, and now the linting checks are passing. Screenshot (1)

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!)

@quintuple-mallard
Copy link
Contributor Author

@SleeplessByte Thanks! I finally got it to work, and now the linting checks are passing. Screenshot (1)

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!
I've changed it to text now.

@kotp
Copy link
Member

kotp commented Jun 20, 2025

Sorry!
I've changed it to text now.

Thanks. Hopefully the image did not leak the obfuscated information in the text version. I might never know. ;)

@SleeplessByte
Copy link
Member

All tests (both configlet and corepack pnpm node) are now passing. It seems that .gitignore, .npmrc, LICENSE, package.json, jest.config.js, global.d.ts, eslint.config.mjs, and babel.config.js are the same across exercises, should I go ahead and add them?

If you work on another exercise, we have:

corepack pnpm node scripts/sync.mjs

Copy link
Contributor

The "Sync all exercises" action has started running.

Copy link
Member

@SleeplessByte SleeplessByte left a 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.

@SleeplessByte
Copy link
Member

[warn] concepts/randomness/about.md
[warn] concepts/randomness/introduction.md
[warn] exercises/concept/captains-log/.docs/introduction.md
[warn] exercises/concept/captains-log/.meta/exemplar.js
[warn] Code style issues found in 4 files. Run Prettier with --write to fix.

This is me. Will fix with a format locally.

@SleeplessByte SleeplessByte merged commit 0539714 into exercism:main Jun 20, 2025
6 checks passed
@SleeplessByte
Copy link
Member

We're live.


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:

site update for new exercise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants