-
Notifications
You must be signed in to change notification settings - Fork 542
Add Alphametics exercise. Fixes #182 #225
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
Hmm, it looks like travis fails on compiling example.rs due to missing dependencies. How should I fix that? Why is it even tries to compile that file? |
Gigasecond is a good example of an exercise that requires crates. You need to list them in your Cargo.toml file Sorry that it took me so long to get to this. Vacation + News = Me Avoiding My Computer. |
The exercise is not about any specific crate. I just used two convenient creates for the example code. I feel providing a pre-filled [dependencies] would make people think they should use those and I want to avoid that. |
Sure, but since your example code uses external crates it will not pass CI until those crates are declared as dependencies in the Cargo.toml file. When the CI runs it compiles your example.rs file and ensures that it passes all of the test cases. And that compilation can't happen unless the dependencies are declared. |
I see that, but what should I do if I don't want those dependencies to show up in Maybe there should be a Cargo-example.toml file? I feel like this pull request is not the right place to discuss that, do you want me to open an issue somewhere for this? Or do You think this is a non-issue and those dependencies for example code should be there for everyone? |
Funnily enough, I too have limited access so expect delays in responses from me.
I would prefer presenting a clean Cargo.toml to students, because I agree with your reasoning. If there is a strong desire to have this PR merged quickly, I would find acceptable a Cargo.toml with the dependencies for now if an issue is filed to discuss removing it and we at least come up with a plan.
It does seem to make sense to open a separate issue in this repo. Despite the fact that this PR is the first place where this problem comes up, it can be applicable to others as well so makes sense to have the separate issue. I would wait to post the following info in that issue, but since I have limited availability, I'll just say it now: In the Haskell track, package.yaml plays a similar role to Cargo.toml: You can declare dependencies there. I have some history to share. In exercism/haskell#189 (comment) , I noted that an example was depending on a package, and this package would show up in the delivered package.yaml to students. Eventually we have exercism/haskell#420 and presented a clean package.yaml to students, without example's dependencies (example uses a separate package.yaml file) We don't need to use the exact same solution, it only suffices that the example can use a separate Cargo.toml and that https://github.com/exercism/xrust/blob/master/_test/check-exercises.sh understands how to use it - I would suggest that if Cargo-example.toml exists, move it to Cargo.toml, otherwise do nothing - that way we don't have to maintain a whole bunch of unnecessary Cargo.toml files; we only have to maintain the ones that actually need a separate one. |
I'll agree. I can't think of many topics to add to https://github.com/exercism/xrust/blob/master/problems.md , I only have "string parsing", "math", "combinations" or something like that. |
char::from_digit(n as u32,10).unwrap() | ||
} else { | ||
// Otherwise just copy over the character | ||
c |
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.
do you ever expect this to happen if we call test_equation
? If it does happen, then the parse::<u32>().unwrap()
later on would fail, right? If so, I might consider just unwrap()
here as well, or have an unreachable!
in here.
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.
The else branch will run every time an equation is parsed. This will convert a String like "A + B == C"
to another String which looks like this "1 + 2 == 3"
. The the function chops up this string later and parses the individual numbers.
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.
Oh, so it is for the +
and =
and spaces. Got it.
// All available numbers for substitution | ||
let numbers: &[u8] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
|
||
// Iterate every combination with the length of uniqe letters in the puzzle |
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.
minor: spelling (uniqe -> unique)
I'll be able to take a closer look in about 96 hours. How are we doing on runtime? I only see in the test output that the last test ran for more than 60 seconds; is there someting that tell us how long does the entire thing take? |
As mentioned in the comment on the top of the file, this is a rather naive brute force example which will run for a long time on large inputs, like the last test. On top of that I did not do any tricks to make this solution faster in the hope of better readability. It is not that bad on my machine though, definitely under 10 seconds. 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.
Codewise, I have no changes to propose. 👍 on this front.
I have some minor formatting comments, but we have no requirement for format, so I have very little ground to stand on in making these comments. #143 did not get taken. So it could get merged without fixing them if nobody else cares.
If looking at https://travis-ci.org/exercism/xrust/builds/178855887, and recalling from https://github.com/exercism/xrust/blob/master/_test/check-exercises.sh that DENYWARNINGS doesn't actually run the tests, we can look at the difference between the DENYWARNINGS and the standard runs to try to see how long the tests take.
I cannot explain why beta only has a difference of 40 seconds, yet stable and nightly have differences of about 4 minutes.
Again, we have no standards on runtimes, so I have no ground to stand on to request anything faster. So let's not block merging this PR for this reason. If we start reviewing PRs and start hurting because Travis is taking too long, we may have to take some or all of the following measures:
- run Travis tests with --release (for all exercises? for only designated ones including alphametics?)
- don't run some of the long-running tests in Travis (the 8 letter and 10 letter ones, perhaps. How do we do that? TBD).
- solve column-by-column in the example solution to speed it up
extern crate alphametics; | ||
use std::collections::HashMap; | ||
|
||
fn test_helper(puzzle: &str, solution: &[(char, u8)]) { |
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.
perhaps just a single space between the :
and &
?
extern crate alphametics; | ||
use std::collections::HashMap; | ||
|
||
fn test_helper(puzzle: &str, solution: &[(char, u8)]) { |
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.
is there (should there) be a better name for test_helper
?
Then again, I don't have a particularly better one. assert_solution_matches
?
} | ||
// If we tested every combination and did not found a solution then return None | ||
None | ||
} |
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.
newline after?
if let Some(&n) = substitutions.get(&c) { | ||
// If the character is in the substitutions, get the number and | ||
// convert it to a char | ||
char::from_digit(n as u32,10).unwrap() |
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.
space after the comma?
|
||
[dependencies] | ||
itertools = "0.5" | ||
permutohedron = "0.2" |
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.
newline after?
OK, since Ian's good and everything I said is dealt with, let's merge. I'll squash. |
Thanks! |
Thanks, @ijanos! |
I'm not sure where should we put this in problems.md. I think it belongs towards the end of "Getting Rusty". What do you think?