Repository navigation
zebra-puzzle: Add exercise - #1594
Conversation
Co-Authored-By: Jonas Weber <thriqon@users.noreply.github.com>
Co-Authored-By: Jonas Weber <thriqon@users.noreply.github.com>
sjwarner-bp
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
This is looking really great, thanks @lemoncurry! 😄
I've left a few comments, nothing major. Feel free to ask questions or disagree with me! 🙂
| return isJustRightOf(a, b) || isJustRightOf(b, a); | ||
| } | ||
|
|
||
| private void solve() { |
There was a problem hiding this comment.
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? 🙂
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? 🙂
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
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 🙂
| "difficulty": 6, | ||
| "topics": [ | ||
| "arrays", | ||
| "conditionals", |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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}; |
There was a problem hiding this comment.
Sicne you're not actually modifying this, could it be a static variable? 🙂
| return isJustRightOf(a, b) || isJustRightOf(b, a); | ||
| } | ||
|
|
||
| private void solve() { |
There was a problem hiding this comment.
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 -> { |
There was a problem hiding this comment.
Since this is iterating through the permutations maybe colorPermutation might be a more descriptive name? 🙂 Same for the other iterations through permutations 🙂
|
@FridaTveit Thank you for your great suggestions, I will work on it 😃 |
FridaTveit
left a comment
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 🙂
Reviewer Resources:
Track Policies