-
-
Notifications
You must be signed in to change notification settings - Fork 405
[#723] New practice exercise zebra-puzzle
#753
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
Add solution Add config file
|
Thank you for contributing to Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:
Automated comment created by PR Commenter 🤖. |
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.
WOW 😍 I did not expect another PR so soon. Amazing work again! And another very difficult exercise!
The CI is going to complain a bit about formatting. I think you need to do two or three changes:
- Run
./bin/check_formatting.shto find trailing whitespace and remove it - Run
mix formaton the whole exercise - Run
mix formaton.meta/example.ex, and for that I think you need to temporarily move it toliband back.
If you don't manage to please the CI's formatting checks, I can help out and add a commit :) I can be a bit annoying.
| @@ -0,0 +1,192 @@ | |||
| defmodule ZebraPuzzle do | |||
| @nationalities ~w(englishman norvegian ukrainian japanese spaniard)a | |||
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.
A small typo (also in the test):
| @nationalities ~w(englishman norvegian ukrainian japanese spaniard)a | |
| @nationalities ~w(englishman norwegian ukrainian japanese spaniard)a |
config.json
Outdated
| "cond", | ||
| "if", | ||
| "enum", | ||
| "keyword-lists", |
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.
I didn't see keyword lists in your solution, but I did see maps. Do you think we should swap this prerequisite for maps? Or should we have both? I'm also seeing recursion in your solution. Maybe that should also be a prerequisite?
A prerequisite doesn't mean you have to use that concept to solve the exercise, but it will stop people from solving it before they do know the concept (so that they can properly choose, for example enum vs recursion, or both).
@neenjaw thoughts?
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.
You're right. I did sort of use keyword lists at some point because when you enumerate on a map it turns into a keyword list, but I changed the implementation to use Map.new() instead, so I should remove this. I will swap the requirement with maps.
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.
Yes, I think swapping the pre-req with maps is a good step for this. While you are right, enumerated maps and key-word lists elements appear similarly I would hesitate to say that maps are transformed into keyword lists, the tuple-pair is the focus of that I think.
Personally I am okay with hard exercises appearing early in the exercise progression as long as the student has the tools to solve it. So i would just make sure that there isn't a hidden pattern in the code required to solve that would be taught more explicitly with another more "advanced" concept
| end | ||
|
|
||
| def filter_by_unique_relations(list) do | ||
| # Some values happen to exist only in one particulat house number |
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.
Probably typo?
| # Some values happen to exist only in one particulat house number | |
| # Some values happen to exist only in one particular house number |
| end) | ||
| |> Enum.concat() | ||
|
|
||
| # Add those values as contraints and filter |
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.
Probably typo?
| # Add those values as contraints and filter | |
| # Add those values as constraints and filter |
|
OK, I think I fixed the CI issues. What gave me most trouble was realizing that the Also in my debugging process, I had to fiddle with the - module_name=$(cat "${test_file}" | sed -rn 's/^defmodule (.*)Test do$/\1 /p')
+ module_name=$(cat "${test_file}" | sed -En 's/^defmodule (.*)Test do$/\1 /p')
doctest_code="doctest ${module_name}"
# Warning: GNU sed necessary, BSD (macOS) sed has incompatible options
- sed -i 's/use ExUnit.Case\(.*\)/use ExUnit.Case\1\n'" ${doctest_code}"'\n/g' "${test_file}"
+ sed -i '' -E $'s/use ExUnit.Case(.*)/use ExUnit.Case\\1'$'\\\n'" ${doctest_code}"$'\\\n/g' ${test_file} |
|
Cool use of sed to trim out the extra whitespace! I would prefer it not added to the test file source though, let me think if we have a "useful snippets" document which would be a good place for that |
|
Oh this doesn't trim out the whitespace, it lets |
|
Ah! Sorry, I misread the context of the sed. 😳 Yes, a separate PR to add those as comments would be fine |
| "enum", | ||
| "cond" |
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.
We need to make sure that adding these doesn't put us over the 8 exercise limit for the concept exercise @angelikatyborska
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.
I completely forgot about this 😱 was the limit 8 or 10? If the limit is 8, then we need to rethink 7 concepts. I think we can do that on a separate branch. I wouldn't want to block @jiegillet PR because of our previous carelessness 😅
~*~*~*~ enum ~*~*~*~
Practiced by:
10
[
'rna-transcription',
'resistor-color',
'raindrops',
'sum-of-multiples',
'anagram',
'hamming',
'transpose',
'connect',
'minesweeper',
'zebra-puzzle'
]
~*~*~*~ integers ~*~*~*~
Practiced by:
9
[
'collatz-conjecture',
'nth-prime',
'leap',
'all-your-base',
'change',
'luhn',
'armstrong-numbers',
'largest-series-product',
'clock'
]
~*~*~*~ maps ~*~*~*~
Practiced by:
9
[
'nucleotide-count',
'scrabble-score',
'grade-school',
'matrix',
'tournament',
'binary-search-tree',
'kindergarten-garden',
'custom-set',
'saddle-points'
]
~*~*~*~ pattern-matching ~*~*~*~
Practiced by:
11
[
'bowling',
'protein-translation',
'triangle',
'tournament',
'meetup',
'perfect-numbers',
'queen-attack',
'poker',
'alphametics',
'wordy',
'pov'
]
~*~*~*~ ranges ~*~*~*~
Practiced by:
10
[
'rotational-cipher',
'pangram',
'sum-of-multiples',
'nth-prime',
'isbn-verifier',
'grains',
'rail-fence-cipher',
'diffie-hellman',
'palindrome-products',
'difference-of-squares'
]
~*~*~*~ recursion ~*~*~*~
Practiced by:
11
[
'roman-numerals',
'strain',
'accumulate',
'matching-brackets',
'binary-search',
'binary-search-tree',
'prime-factors',
'pascals-triangle',
'spiral-matrix',
'sieve',
'pov'
]
~*~*~*~ regular-expressions ~*~*~*~
Practiced by:
9
[
'word-count',
'markdown',
'forth',
'acronym',
'run-length-encoding',
'isogram',
'phone-number',
'isbn-verifier',
'grep'
]
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.
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.
I'm looking at your solution and I wonder if there is a way to solve this using list comprehensions: generators to create the possibilities and filters to select the possible answers, but that said, the purpose of an example solution is to prove that it is solvable in elixir, not to have the best solution and yours works! 🎉
I'm thrilled to have yet another exercise to solve on this track!
Thanks @jiegillet!! You're on fire! 🔥
|
That's true, list comprehensions would make the possibilities creation cleaner, and possibly filters. I haven't used list comprehensions in Elixir very much yet. I'll look forward to seeing your solution on Exercism 🤣 I'll probably do more remaining practice exercises. |
|
@jiegillet About sed, there is a warning in the script (that I totally forgot about until now) that on a mac, you need to install GNU sed. Did you do that? I did, and I never had problems with the scripts. All I know is that GNU sed and BSD sed are somehow incompatible, but I'm not sure exactly how. Could that explain the problems you had with the script? It would be great if we had a single script that could detect which sed is present and adjust the sed call accordingly 🤔 |
|
The incompatibilities are things like different flags (GNU I'm not sure how to detect sed version, I can look into it and open a PR if it's worth it. |
If this something you're interested in doing, that would be great. If not, @neenjaw and I will figure something out. |
|
🤷♂️ I'm not sure it's really worth doing to automate it when it is mostly used by CI which runs on ubuntu. Just having the bsd-compatible form in a comment is all I'm looking for. |
|
OK, there's no reason to delay merging this! Let's merge and deal with the "practices" limit per concept in a separate PR. |
|
Thank you again @jiegillet ❤️ 🧡 💛 💚 💙 💜 |
I had fun with the previous PR, so here I go again with #723 .
It was pretty tough to solve, definitely the one that took me the longest out of all the exercises on Exercism that I have done so far. I would say that the algorithm that I came up with is complex, but the Elixir tools required to solve are fairly simple.
Please have a look :)