-
Notifications
You must be signed in to change notification settings - Fork 543
Implement exercise Poker #347
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1c6256
Merge pull request #1 from exercism/master
coriolinus 564d49c
Implement exercise poker
coriolinus cf05f41
Add new exercise: poker.
coriolinus 6b0213c
Add example which passes all tests
coriolinus 4f54f5a
Finish preparing exercise
coriolinus e241b08
Add hints to readme
coriolinus 9b82d64
poker: put hints where they need to be
petertseng 05b72d2
poker: correctly list source
petertseng f4b2ae5
poker: README generator wrapped the lines
petertseng 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
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,7 @@ | ||
| # Generated by Cargo | ||
| # will have compiled files and executables | ||
| /target/ | ||
|
|
||
| # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
| # More information here http://doc.crates.io/guide.html#cargotoml-vs-cargolock | ||
| Cargo.lock |
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,8 @@ | ||
| ## Hints | ||
|
|
||
| - Ranking a list of poker hands can be considered a sorting problem. | ||
| - Rust provides the [sort](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.sort) method for `Vec<T> where T: Ord`. | ||
| - [`Ord` types](https://doc.rust-lang.org/std/cmp/trait.Ord.html) are form a [total order](https://en.wikipedia.org/wiki/Total_order): exactly one of `a < b`, `a == b`, or `a > b` must be true. | ||
| - Poker hands do not conform to a total order: it is possible for two hands to be non-equal but have equal sort order. Example: `3S 4S 5D 6H JH"`, `"3H 4H 5C 6C JD"`. | ||
| - Rust provides the [`PartialOrd` trait](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) to handle the case of sortable things which do not have a total order. However, it doesn't provide a standard `sort` method for `Vec<T> where T: PartialOrd`. The standard idiom to sort a vector in this case is `your_vec.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::{Less|Equal|Greater}));`, depending on your needs. ` | ||
| - You might consider implementing a type representing a poker hand which implements `PartialOrd`. |
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,8 @@ | ||
| [package] | ||
| name = "poker" | ||
| version = "1.0.0" | ||
| authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"] | ||
|
|
||
| [dependencies] | ||
| try_opt = "0.1.1" | ||
| counter = "0.1.0" |
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,6 @@ | ||
| [package] | ||
| name = "poker" | ||
| version = "1.0.0" | ||
| authors = ["Peter Goodspeed-Niklaus <peter.r.goodspeedniklaus@gmail.com>"] | ||
|
|
||
| [dependencies] |
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,54 @@ | ||
| # Poker | ||
|
|
||
| Pick the best hand(s) from a list of poker hands. | ||
|
|
||
| See [wikipedia](https://en.wikipedia.org/wiki/List_of_poker_hands) for an | ||
| overview of poker hands. | ||
|
|
||
| ## Hints | ||
|
|
||
| - Ranking a list of poker hands can be considered a sorting problem. | ||
| - Rust provides the [sort](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.sort) method for `Vec<T> where T: Ord`. | ||
| - [`Ord` types](https://doc.rust-lang.org/std/cmp/trait.Ord.html) are form a [total order](https://en.wikipedia.org/wiki/Total_order): exactly one of `a < b`, `a == b`, or `a > b` must be true. | ||
| - Poker hands do not conform to a total order: it is possible for two hands to be non-equal but have equal sort order. Example: `3S 4S 5D 6H JH"`, `"3H 4H 5C 6C JD"`. | ||
| - Rust provides the [`PartialOrd` trait](https://doc.rust-lang.org/std/cmp/trait.PartialOrd.html) to handle the case of sortable things which do not have a total order. However, it doesn't provide a standard `sort` method for `Vec<T> where T: PartialOrd`. The standard idiom to sort a vector in this case is `your_vec.sort_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::{Less|Equal|Greater}));`, depending on your needs. ` | ||
| - You might consider implementing a type representing a poker hand which implements `PartialOrd`. | ||
|
|
||
|
|
||
| ## Rust Installation | ||
|
|
||
| Refer to the [exercism help page][help-page] for Rust installation and learning | ||
| resources. | ||
|
|
||
| ## Writing the Code | ||
|
|
||
| Execute the tests with: | ||
|
|
||
| ```bash | ||
| $ cargo test | ||
| ``` | ||
|
|
||
| All but the first test have been ignored. After you get the first test to | ||
| pass, remove the ignore flag (`#[ignore]`) from the next test and get the tests | ||
| to pass again. The test file is located in the `tests` directory. You can | ||
| also remove the ignore flag from all the tests to get them to run all at once | ||
| if you wish. | ||
|
|
||
| Make sure to read the [Crates and Modules](https://doc.rust-lang.org/stable/book/crates-and-modules.html) chapter if you | ||
| haven't already, it will help you with organizing your files. | ||
|
|
||
| ## Feedback, Issues, Pull Requests | ||
|
|
||
| The [exercism/rust](https://github.com/exercism/rust) repository on GitHub is the home for all of the Rust exercises. If you have feedback about an exercise, or want to help implement new exercises, head over there and create an issue. Members of the [rust track team](https://github.com/orgs/exercism/teams/rust) are happy to help! | ||
|
|
||
| If you want to know more about Exercism, take a look at the [contribution guide](https://github.com/exercism/docs/blob/master/contributing-to-language-tracks/README.md). | ||
|
|
||
| [help-page]: http://exercism.io/languages/rust | ||
| [crates-and-modules]: http://doc.rust-lang.org/stable/book/crates-and-modules.html | ||
|
|
||
| ## Source | ||
|
|
||
| Inspired by the training course from Udacity. [https://www.udacity.com/course/viewer#!/c-cs212/](https://www.udacity.com/course/viewer#!/c-cs212/) | ||
|
|
||
| ## Submitting Incomplete Solutions | ||
| It's possible to submit an incomplete solution so you can see how others have completed the exercise. |
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.
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.
Note that this will be our first exercise of difficulty 6.
Historically, this track has only used difficulties 1, 4, 7, and 10, corresponding to the four sections (Introduction = 1, Getting Rusty = 4, Rust Gets Strange = 7, Putting it all Together = 10) in https://github.com/exercism/rust/blob/aea470a76a9c6f0005adebb2a00d969512da3b6e/problems.md. That file does not exist anymore as it has been replaced with https://github.com/exercism/rust/blob/master/problem_ordering.md . So we are not restricted to only doing 1 4 7 10. But you would be breaking new ground.
I am assuming all parties involved are OK with this. I'm also inferring that everyone agreed that this is harder than all exercises of difficulty 4 and easier than all exercises of difficulty 7.
This comment therefore does not require a response or anything to be changed, but I was obligated to write this comment for the sake of anyone who looks back on this PR and wonders about the origin of the first difficulty 6 exercise.