Skip to content
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

Add exercise yacht #972

Merged
merged 8 commits into from
Apr 14, 2024
Merged

Add exercise yacht #972

merged 8 commits into from
Apr 14, 2024

Conversation

ahans
Copy link
Contributor

@ahans ahans commented Apr 13, 2024

No description provided.

@ahans ahans mentioned this pull request Apr 13, 2024
12 tasks
@ahans
Copy link
Contributor Author

ahans commented Apr 13, 2024

I will obviously fix the GCC warning.

"blurb": "Score a single throw of dice in the game Yacht.",
"source": "James Kilfiger, using wikipedia",
"source_url": "https://en.wikipedia.org/wiki/Yacht_(dice_game)"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could you add a newline at the end of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, looks like auto-format on save removes it for some reason. It's back now. Sorry for this, I was under the impression that's the way how configlet creates the file and it's how you want it to be.

{
TEST_IGNORE();
const dice_t dice = { 2, 2, 4, 4, 4 };
TEST_ASSERT(score(dice, FULL_HOUSE) == 16);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the test we tend to use the type specific test macros from Unity rather than TEST_ASSERT(). Can you check if there are any suitable for this exercise?

exercises/practice/yacht/.meta/example.c Show resolved Hide resolved
Copy link
Contributor

@wolf99 wolf99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good stuff, a few small items to look at


static void test_not_yacht(void)
{
TEST_IGNORE();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most exercises there's a comment in this first TEST_IGNORE() line that explains that this should be deleted to enable the tests, e.g. in test_difference_of_squares.c
Do you mind adding such comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

config.json Outdated
"uuid": "dd360788-1dff-4a5d-89af-5bbd1199ae86",
"practices": [],
"prerequisites": [],
"difficulty": 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a 4? We have Eliud's eggs rated as a 2 and that's a fair bit less complicated.

Suggested change
"difficulty": 2,
"difficulty": 4,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whatever you find reasonable. Difficulties are all over the place. spiral-matrix is also a 4 and I would say that's more difficult than this. I updated it to 4 now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, many of these need to be revisited

}

typedef struct {
uint8_t faces[6];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint8_t faces[6];
int faces[6];

There's definitely nothing wrong with a fixed sized integer, but it's inconsistent with the typing of the rest of the solution. If we change this to int we should be able to remove stdint.h above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you'd rather use fixed-width types consistently, that's also fine with me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where exactly is this inconsistent? I use uint8_t everywhere except for the final score. Technically, that could also be a uint8_t, but some small change in the specification (let's say yacht is is not 50, but 300 points) would break this.

My main motivation here, though, was efficiency. 6 bytes will easily be passed via a register when doing function calls. 24 bytes could be a different story.

I can change it to int if you prefer. But I'd keep the uint8_t here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several places in this that use int instead of a fixed-width type. I understand your reasons for making the choice you made, but this is a learning aid, not production code. This optimization will have little meaning to someone scoring a dice game to learn the fundamentals of C. My thought is that seeing a mix of fixed-width and non-fixed-width types will be more surprising to someone solving the problem than a missed optimization.

#include "yacht.h"

#include <assert.h>
#include <stdbool.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <stdbool.h>

I think this is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A leftover from when has_count returned a bool. Removed that now.

#ifndef YACHT_H
#define YACHT_H

#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this include can probably be removed now?
Then I think this PR is good to go!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right! Hadn't had a chance to look at the diff myself yet! This one is gone now as well.

@wolf99
Copy link
Contributor

wolf99 commented Apr 14, 2024

LGTM, well done @ahans !

@ryanplusplus
Copy link
Member

Thanks!

@ryanplusplus ryanplusplus merged commit 7055555 into exercism:main Apr 14, 2024
4 checks passed
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.

None yet

4 participants