Skip to content

rail-fence-cipher: add to track - #765

Merged
FridaTveit merged 13 commits into
exercism:masterfrom
LeonDsouza:master
Dec 31, 2017
Merged

FridaTveit merged 13 commits into
exercism:masterfrom
LeonDsouza:master

Conversation

@LeonDsouza

Copy link
Copy Markdown
Contributor

Reviewer Resources:

Track Policies

@stkent

stkent commented Sep 2, 2017

Copy link
Copy Markdown
Contributor

Oh, now I'm confused; which PR is the most up-to-date, @LeonDsouza? I see this one includes those config changes I mentioned in your other PR.

@Smarticles101

Copy link
Copy Markdown
Member

In order to fix the failing build, you need to add a folder src/main/java and put an empty .keep file in it in order for git to see it let you commit that folder. Otherwise, the build fails because the folder doesn't exist.

Also, as a side note, it's perfectly fine to keep using the original pull request when you push new changes. Github adds any more pushed changes to the pull request, and it also allows you to edit the title when you like. Just using one pull request helps to keep out confusion :)

@Smarticles101 Smarticles101 changed the title Merge | add to track rail-fence-cipher: add to track Sep 5, 2017

@Smarticles101 Smarticles101 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I left a few comments, most of them being minor. Thanks for your work on this @LeonDsouza sorry for the late review

Comment thread config.json Outdated
"difficulty": 1,
"topics": [

]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should have an indent of 4 spaces.

Comment thread config.json
{
"slug": "rail-fence-cipher",
"core": true,
"unlocked_by": null,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would you be able to estimate a difficulty and add topics? If not, we can open a separate issue for that once this gets merged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also core should be false. We've already decided a set of core exercises and we probably don't want to add to them at this point. See this issue for our discussion about which exercises should be core exercises. Also this issue and this PR where we changed the config.json structure after finding out exercises should only be unlocked by core exercises.

If you want @LeonDsouza, you could look through the core exercises (listed in this PR) and choose want you think should unlock this one. But it can also be kept as "core": false and "unlocked_by": null :)

Let me know if any of that didn't make sense! :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It also needs a uuid. These were introduced quite recently, see this PR. You can use this tool to generate one :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I just found this document which explains very well what needs to be in this file (including uuid, unlocked_by and core) :)

@Test
public void encodeWithThreeRails() {
railFenceCipher = new RailFenceCipher(3);
Assert.assertEquals("WECRLTEERDSOEEFEAOCAIVDEN", railFenceCipher.getEncryptedData("WEAREDISCOVEREDFLEEATONCE"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These lines might be easier to read with each parameter on a different line.

decrypted = buffer.toString().replaceAll(",", "").replaceAll("\\s+", "").replace("[", "").replace("]", "");
return decrypted;
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't have any comments on the example implementation. @FridaTveit usually does if she cares to look at it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The most important thing is that this file should be in .meta/src/reference/java/ instead of src/example/java/. Sorry about that, it's been changed very recently :) You can look at the other exercises @LeonDsouza to make sure your folder structure matches theirs :)

@LeonDsouza

Copy link
Copy Markdown
Contributor Author

Did those changes @Smarticles101 @stkent @FridaTveit. Got the build to succeed! 👍

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for making these changes @LeonDsouza! It's looking great :)

There are a couple of things to do with the config.json that still need changing. Let me know if you have any problems with that :)

I've also left a few comments on the example solution. Feel free to ignore them/disagree with me, they're only suggestions :)

Comment thread config.json Outdated
"conditionals"
],
"unlocked_by":null,
"uuid":"8382f1c7-4ba4-4d6e-abe1-2d5a2519a11a"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for adding the difficulty, topics and and unlocked_by! :) It's looking great, thank you for taking the time to do that!

A couple of things:

  • You've got unlocked_by twice, you only need it once.
  • This should be moved to where the other exericses with difficulty 6 are in this array, e.g. before spiral-matrix.
  • You've changed the spacing of everything in this file. That makes it hard to see which changes were actually yours and the spacing was fine as it was before. It would be great if you could change that back. Let me know if you have any problems with that :)

railFence.add(number, temp + c);
number += increment;
}
String buffer = "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use a StringBuilder here :)

railFence.add("");
}

int number = 0, increment = 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I find this a bit hard to follow. Using variables like number and increment makes it quite difficult to understand what you're doing since they don't describe what the variable actually is. From what I can tell number represents the currentRailNumber, so it should be named that :) It looks like you're using increment to increment the current rail number modulo the number of rails. To make that easier and more clear you could iterate over the characters with an old fashioned loop (so that you've got an index i) and then update the current rail number using:
currentRailNumber = i % numberOfRails

Does that make sense? Let me know if it doesn't or if you think it won't work :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm actually using the increment variable to know the extent of how far down or up i can go

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay. That still doesn't explain why it's called increment. The name of the variable should explain what you're using it for :)

increment = 1;
}
String temp = railFence.get(number);
railFence.remove(number);

@FridaTveit FridaTveit Sep 26, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove will return the item so you can do:
String currentCharacter = railFence.remove(number)
(I would also name it currentCharacter to make it more obvious what it is :) )


String getDecryptedData(String cipherText) {
String decrypted;
ArrayList<ArrayList<Integer>> railFence = new ArrayList<>(noOfRails);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any particular reason you're storing each rail as a list of integers? You could just store it as a string and append characters to it as you go through the ciphertext. That should make it easier to get the final output at the end :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've stored it in a kind of matrix form for a 2 loop iteration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, but since you're dealing with characters it makes more sense to store it as characters rather than integers. You can have a list of strings and loop through the characters of each string.

And as a tip for the future, it would be really helpful if you could respond to reviews relatively soon after we do them. For big reviews like this it takes time for me to get into the mindset of the code and understand what you're doing. If you had made these comments a month ago when I first reviewed this code I would have been able to give way more useful answers. And I'm guessing it would be easier for you too to change your code right after you wrote it instead of more than a month after.
I know you're probably very busy with work and things, but in that case it might be easier for you to work on smaller issues rather than trying to implement a whole exercise? Like I said, this is just a suggestion for the future since PRs that remain open for months become really hard to review. But I do really appreciate you trying to help improve the track :)

}
}

decrypted = buffer.toString().replaceAll(",", "").replaceAll("\\s+", "").replace("[", "").replace("]", "");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you really need these replaces?


int rowIncrementFactor = 0, step = 1;

for (int i = 0; i < cipherText.length(); ++i) {

@FridaTveit FridaTveit Sep 26, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, this is a bit hard to follow. Say you have n rails, then you want to go through the ciphertext and add each letter to the correct rail. You can find the correct rail by i % n I think. If i % n is 0 then you add it to the first rail, if i % n is 1 then you add it to the second rail. Does that make sense?

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You appear to have accidentally reverted all your changes to config.json which is why the build is failing. It was only the indentation changes I wanted you to revert, you still need to add the exercise to config.json as explained in the contribution guide. Let me know if you need any help with that or if you have any questions :)

@FridaTveit

Copy link
Copy Markdown
Contributor

Hi @LeonDsouza :) How's it going with this? :)

@stkent

stkent commented Nov 26, 2017

Copy link
Copy Markdown
Contributor

Poke @LeonDsouza :) How's it going? If you're too busy to finish this one off, let us know and we'll carry it across the finish line. I wouldn't want your hard work so far to be wasted 😢

@sjwarner-bp

Copy link
Copy Markdown
Contributor

Seeing as this has been inactive a little while, does anyone mind if I pick it up and finish it off so this work isn't wasted? 🙂

As a sidenote, what normally happens with abandoned PRs?

@stkent

stkent commented Dec 20, 2017

Copy link
Copy Markdown
Contributor

Seeing as this has been inactive a little while, does anyone mind if I pick it up and finish it off so this work isn't wasted? 🙂

I think it's safe to do so at this point.

As a sidenote, what normally happens with abandoned PRs?

I'm not sure this has happened often enough for us to have a 'normal' response. We trialed running probot on the repository a while back, but that was mostly for support-related issues and it was missing features we needed.

@sjwarner-bp

Copy link
Copy Markdown
Contributor

@stkent Thanks for letting me know!

As for finishing this one off, I've never amended someone else's PR before. I've seen before (example #1060) where others may push to a PR they haven't authored. If anyone could let me know how this is possible I'd be really grateful 🙂

@Smarticles101

Copy link
Copy Markdown
Member

@sjwarner-bp It's as simple as cloning the branch that will be merged through the pull request and committing to it! :)

@sjwarner-bp

Copy link
Copy Markdown
Contributor

Ok, so we have a passing build (I've updated config.json) - but I still think that the reference solution needs a little work 🙂

@sjwarner-bp sjwarner-bp changed the title rail-fence-cipher: add to track [WIPrail-fence-cipher: add to track Dec 23, 2017
@sjwarner-bp sjwarner-bp changed the title [WIPrail-fence-cipher: add to track [WIP] rail-fence-cipher: add to track Dec 23, 2017
@sjwarner-bp sjwarner-bp changed the title [WIP] rail-fence-cipher: add to track rail-fence-cipher: add to track Dec 24, 2017

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is looking great, thanks for working on this @sjwarner-bp! :)

I've left some comments but there are only a few important things:

  • The unlocked by exercise needs to be a core exercise
  • The readme is missing I think
  • I don't think the methods should be static

Apart from that it looks great! Thanks again for working on this! :)

Comment thread config.json Outdated
"loops",
"conditionals"
],
"unlocked_by": "atbash-cipher",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

atbash-cipher isn't a core exercise so it can't be unlocked by that. rotational-cipher would probably be a good exercise for it to be unlocked by? :)

@@ -0,0 +1,64 @@
public class RailFenceCipher {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This could be package private :)

@@ -0,0 +1,64 @@
public class RailFenceCipher {

private static int key;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this or any of the methods should be static. Either all the methods are static and you pass in the key to each method, or the methods are all instance methods and you pass in the key to the constructor. Since we prefer instance methods according to our policies doc I would suggest the latter :)


public static String getEncryptedData(String message) {
String[] lines = splitIntoLines(message, false);
String result = "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could use a StringBuilder :)

}
}

String result = "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could use StringBuilder :)

}

private static String[] generateEmptyStrings(int num) {
String[] strings = new String[num];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you do:

String[] strings = new String[num];
Arrays.fill(strings, "");
return strings;

? :)

@sjwarner-bp

Copy link
Copy Markdown
Contributor

Oops! Silly mistakes - hopefully they're all fixed up now 🙂

@FridaTveit FridaTveit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great! Thanks for all your hard work @sjwarner-bp and @LeonDsouza! :)

@FridaTveit
FridaTveit merged commit 1cd5cdc into exercism:master Dec 31, 2017
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.

6 participants