Skip to content

zebra-puzzle: Add exercise - #1594

Merged
FridaTveit merged 5 commits into
exercism:masterfrom
lemoncurry:add-zebrapuzzle
Oct 15, 2018
Merged

FridaTveit merged 5 commits into
exercism:masterfrom
lemoncurry:add-zebrapuzzle

Conversation

@lemoncurry

Copy link
Copy Markdown
Contributor

Reviewer Resources:

Track Policies

lemoncurry and others added 2 commits October 9, 2018 20:14
Co-Authored-By: Jonas Weber <thriqon@users.noreply.github.com>
Co-Authored-By: Jonas Weber <thriqon@users.noreply.github.com>
@lemoncurry lemoncurry changed the title [WIP] Add new exercise zebra-puzzle Add new exercise zebra-puzzle Oct 9, 2018
@lemoncurry lemoncurry changed the title Add new exercise zebra-puzzle zebra-puzzle: Add exercise Oct 9, 2018

@sjwarner-bp sjwarner-bp 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.

I think that this looks great! I'll wait until another maintainer has reviewed it before merging (new exercises are a big deal!)

Thanks so much @lemoncurry 🙌

@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 really great, thanks @lemoncurry! 😄

I've left a few comments, nothing major. Feel free to ask questions or disagree with me! 🙂

Comment thread config.json Resolved
return isJustRightOf(a, b) || isJustRightOf(b, a);
}

private void solve() {

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 method is a bit big. Would it be possible to extract some of it into individual methods? For example extract each method passed to forEach? 🙂

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.

The structure of this solution relies on lambda capture. Restructuring that into multiple methods seems impractical to me, since there would be 5*5 parameters for the last method.
The solution was heavily influenced by the solution provided in the Go and Python track, which was adapted from a solution by Peter Norvig.

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 it'll be quite as bad as that 🙂 From a little playing around I think it looks like the last method will need at most 11 parameters. Not ideal but I think I might still prefer it to having one massive method. And it could be decreased by storing houses as a static variable and passing parameters as arrays, e.g. int[] colorPermutation instead of int red, int green, int yellow... if that makes sense? 🙂

So I still think it would be a nice improvement. But you absolutely don't have to do it if you don't want to! 🙂 If you'd rather have it merged as is then that's fine, I might open an issue for it which can be picked up by anyone later 🙂 Does that sound okay? 🙂

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.

See my latest commit for a solution using instance variables and private methods.

IMO the change diminishes the readability... it is more difficult to see the 'flow'.

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 looks great, thank you! 😄

I see what you mean, jumping from method to method can make it harder to see the flow. However, I also think it's very hard to take in and understand a really long method. When it's broken up into smaller methods then you can try to understand each piece individually and then use that to understand what it all does together. I find that easier, but I guess it varies from person to person 🙂

And as the solution to this exercise is a bit complicated (it being a logic puzzle) I guess no matter what we do the code will probably be a little bit difficult to understand 🙂

Comment thread config.json Outdated
"difficulty": 6,
"topics": [
"arrays",
"conditionals",

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'm not sure I would add arrays and conditionals. You don't necessarily need to use arrays and while you probably would use conditionals I'm not sure it's the main focus of the exercise. So I think it's fine just to have logic as the topic as it is very much an exercise about logic 🙂 What do you think @sjwarner-bp @lemoncurry? 🙂

@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 @lemoncurry, thanks for making those changes! 😄

I've added a few comments, nothing major just one method that can be private and some variable names that could possibly be a bit more descriptive 🙂 Let me know if you have any questions and feel free to disagree with me! 🙂

return builder;
}

static Stream<int[]> perms(int[] a) {

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 should be private 🙂 And I prefer not to have single letter variable names as they can be quite confusing. Maybe array or arrayToPermutate would be more clear? 🙂

arr[b] = tmp;
}

private static Stream.Builder<int[]> perms(int[] a, Stream.Builder<int[]> builder, int l) {

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.

These single letter variable names can be a bit confusing. Maybe array or arrayToPermutate and length would be more descriptive? 🙂

}

private void solve() {
int[] houses = new int[]{1, 2, 3, 4, 5};

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.

Sicne you're not actually modifying this, could it be a static variable? 🙂

return isJustRightOf(a, b) || isJustRightOf(b, a);
}

private void solve() {

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 it'll be quite as bad as that 🙂 From a little playing around I think it looks like the last method will need at most 11 parameters. Not ideal but I think I might still prefer it to having one massive method. And it could be decreased by storing houses as a static variable and passing parameters as arrays, e.g. int[] colorPermutation instead of int red, int green, int yellow... if that makes sense? 🙂

So I still think it would be a nice improvement. But you absolutely don't have to do it if you don't want to! 🙂 If you'd rather have it merged as is then that's fine, I might open an issue for it which can be picked up by anyone later 🙂 Does that sound okay? 🙂

int first = 1;
int middle = 3;

perms(houses).forEach(colors -> {

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.

Since this is iterating through the permutations maybe colorPermutation might be a more descriptive name? 🙂 Same for the other iterations through permutations 🙂

@lemoncurry

Copy link
Copy Markdown
Contributor Author

@FridaTveit Thank you for your great suggestions, I will work on it 😃

@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 look great, an excellent new exercise to add! 😄 Thanks for all the effort you put into it @lemoncurry! 😄

return isJustRightOf(a, b) || isJustRightOf(b, a);
}

private void solve() {

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 looks great, thank you! 😄

I see what you mean, jumping from method to method can make it harder to see the flow. However, I also think it's very hard to take in and understand a really long method. When it's broken up into smaller methods then you can try to understand each piece individually and then use that to understand what it all does together. I find that easier, but I guess it varies from person to person 🙂

And as the solution to this exercise is a bit complicated (it being a logic puzzle) I guess no matter what we do the code will probably be a little bit difficult to understand 🙂

@FridaTveit
FridaTveit merged commit 66dbda5 into exercism:master Oct 15, 2018
@lemoncurry
lemoncurry deleted the add-zebrapuzzle branch October 15, 2018 11:08
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.

3 participants