Skip to content

add run-length-encoding #277

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 1 commit into from
Apr 28, 2017

Conversation

divagant-martian
Copy link

No description provided.

@divagant-martian divagant-martian changed the title dibs: I will implement exercise run-length-encoding add run-length-encoding Apr 25, 2017
Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

Thanks for the work!

In addition to the comments, can you also add an empty file src/lib.rs as it was in #270?

@@ -55,6 +55,15 @@
]
},
{
"slug": "run-length-encoding",
Copy link
Member

@petertseng petertseng Apr 25, 2017

Choose a reason for hiding this comment

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

I personally would have placed it later since unlike beer song we have to read an input string. My choice would have been somewhere after hamming but somewhere before wordy.

But that is just a personal feeling, so let me know if here is in fact appropriate

Comment is outdated - this used to be right after beer song. I am OK right right before hamming.

version = "0.1.0"
authors = ["zombiefungus <[email protected]>"]

[dependencies]
Copy link
Member

Choose a reason for hiding this comment

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

just realised not all of our Cargo.toml have this line! Guess it's optional. The only exercise with a [dependencies] but no dependencies is acronym.

This line is included by cargo new though. So it makes sense to have.

pub fn encode(input: &str) -> String {
input
.chars()
.fold((String::new(),' ',0,1), |(mut acc, last, last_n, pos), c| {
Copy link
Member

Choose a reason for hiding this comment

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

spaces after the commas in the tuple? To be consistent with the fact that there are spaces after commas in other places

input
.chars()
.fold((String::new(), 0), |(mut acc, last_n), c| {
if c.is_digit(10) { // keep reading.. keeeep reading
Copy link
Member

Choose a reason for hiding this comment

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

is this comment meant to tell the reader of the code that it's necessary to keep reading (I don't see the value of this) or that the code should keep reading? Can the comment be clearer about what the code will read, in that case?

Copy link
Author

Choose a reason for hiding this comment

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

haha sorry, the idea is that you can't conclude that the number of digits to place is c because there may be other digits latter. This is just a personal comment, i'll remove it

.chars()
.fold((String::new(), 0), |(mut acc, last_n), c| {
if c.is_digit(10) { // keep reading.. keeeep reading
(acc, 10*last_n + c.to_digit(10).unwrap())
Copy link
Member

Choose a reason for hiding this comment

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

Since there's an is_digit followed by a to_digit.unwrap, what about using if let above? Less need to trust that the unwrap will succeed.

Copy link
Author

Choose a reason for hiding this comment

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

well, I am learning rust my self and I haven't used it. Maybe this should be implemented by someone with more experience

Copy link
Member

Choose a reason for hiding this comment

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

Then my challenge is to try it.

Copy link
Author

Choose a reason for hiding this comment

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

done

}

#[test]
// #[ignore]
Copy link
Member

Choose a reason for hiding this comment

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

whereas these should probably be uncommented, right?

I wanted to look for documentation where we say why we have tests ignored, but it is not present. Our documentation is not sufficient in this area. I will have to mention this in #279 .

#[test]
// #[ignore]
fn test_decode_empty_string() {
assert_eq!("" , cipher::decode(""));
Copy link
Member

Choose a reason for hiding this comment

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

there's a space before the comma here, but not in most other cases. Should it be removed?

#[test]
// #[ignore]
fn test_decode_string_with_no_single_characters() {
assert_eq!("AABBBCCCC" , cipher::decode("2A3B4C"));
Copy link
Member

Choose a reason for hiding this comment

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

there's a space before the comma here, but not in most other cases. Should it be removed?

#[test]
// #[ignore]
fn test_decode_single_characters_with_repeated_characters() {
assert_eq!("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB" ,
Copy link
Member

Choose a reason for hiding this comment

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

there's a space before the comma here, but not in most other cases. Should it be removed?

Copy link
Author

Choose a reason for hiding this comment

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

victim of copy paste

@@ -0,0 +1,87 @@
extern crate run_length_encoding as cipher;
Copy link
Member

Choose a reason for hiding this comment

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

I'm unsure about it because I wouldn't consider run-length encoding as a means to obscure a message to prevent it from being read. That's what I think the definition of a cipher, but I apologise if I was mistaken since English isn't my first language. I'm not sure I have a better suggestion though - simply encoding, perhaps? Is shortening it to rle acceptable in Rust?

@divagant-martian divagant-martian force-pushed the run-length-encoding branch 2 times, most recently from 93e3f54 to c9ccb53 Compare April 26, 2017 00:22
Copy link
Member

@petertseng petertseng left a comment

Choose a reason for hiding this comment

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

Thanks, everything looks good from my point of view. If nobody has anything to say in the next day or two let us merge it.

@divagant-martian
Copy link
Author

nice, thanks

@petertseng petertseng merged commit 25402ed into exercism:master Apr 28, 2017
@petertseng
Copy link
Member

There were no objections in 48 hours (and a few more). It is time to merge. Thank you for your contribution!

@divagant-martian divagant-martian deleted the run-length-encoding branch April 28, 2017 03:30
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.

2 participants