Currently, the unary case (base 1) of the all-your-base exercise considers base 1 as invalid. However, for base 1, one may represent the number as the length of output (with any symbol). Would you consider adding the appropriate tests?
This comment neither recommends for nor against adding such tests (I have no recommendation in either direction), but provides three pieces of additional information that may help in making the decision.
B digits d_i must be in the interval 0 <= d_i < B. Accordingly for base 1, it would be more consistent with other bases if only 0 was accepted as valid digit for that base. If not, base 1 would be a special case.B would be to sum each digit d_i multiplied by an appropriate power of that base, \sum_{i=0}^n d_i B^i ( d_i are 0. A possible alternative is to contravene the above convention of 0 <= d_i < B in some defined way.Accordingly with the above pieces of information, the modifications I had to make to the existing code to support base 1 were the following diff:
diff --git i/exercises/all-your-base/verify.rb w/exercises/all-your-base/verify.rb
index 2c96d12..c624c17 100644
--- i/exercises/all-your-base/verify.rb
+++ w/exercises/all-your-base/verify.rb
@@ -5,10 +5,14 @@ json = JSON.parse(File.read(File.join(__dir__, 'canonical-data.json')))
verify(json['cases'], property: 'rebase') { |i, _|
base = i['inputBase']
- raise "no base #{base}" if base < 2
- i['digits'].reduce(0) { |a, e|
+ raise "no base #{base}" if base <= 0
+ val = i['digits'].reduce(0) { |a, e|
raise "nope, #{e} negative" if e < 0
raise "nope, #{e} too big" if e >= base
+ next a + 1 if base == 1
a * base + e
- }.digits(i['outputBase']).reverse
+ }
+
+ out_base = i['outputBase']
+ out_base == 1 ? [0] * val : val.digits(out_base).reverse
}
Unless there is a clever change to make to the usual algorithms, one might expect student implementations to also have to add similar things if these test cases were added.
Unless there is a clever change to make to the usual algorithms, one might expect student implementations to also have to add similar things if these test cases were added.
We're not looking to make this exercise more difficult or complex, so following this reasoning I personally vote _against_ adding base 1.
The required change seems _minimal_ though. Everything is changed inline, and a special case is added at the bottom of the solution
+ i['outputBase'] == 1 ? [0] * val : val.digits(i['outputBase']).reverse
I agree that from the perspective of the programming exercise, conforming to the general case seems to be a better option. Perhaps, we could add a note about it in the description, hence, ensuring that the exercise doesn't give rise to a mathematically incorrect assumption that base 1 is an invalid base.
@anupamsobti yes! That is always an option 馃憤. In that case I would suggest adding a section to the description along the lines of "although base 1 is considered [a valid base](url), for the sake of simplicity it's excluded in this exercise"
Sounds good. Does this need to be taken care of in individual tracks or is there a common place for descriptions in this repository?
The exercise's description.md is used for generating the track exercise README files, so the change should be made there.
Great. Shall I raise a PR?
@petertseng can you teach me (and others) how to use that tool you use to:
I couldn't find it in the docs -- hijacking this issue for now and then maybe add it via a PR to the docs. I'd like to apply your method whenever I merge something until we have the automatic-bot notifications Katrina talked about.
figure out which tracks have an exercise
The high-level strategy is to:
As https://github.com/exercism/exercism/issues/4418 states, it doesn't seem like there is a better strategy available. Someone might choose to add it to the API if desired.
I wrote an implementation of the above two steps of the high-level strategy:
Of course, any other implementation of the strategy will serve equivalent purposes. There may be other implementations I do not know about.
create an issue tell them what's happened
It sounds like this is about _what_ to write in the body of the issue rather than _how_ to do it. https://github.com/exercism/docs/issues/10 was the documentation but the link is outdated. I found some equivalent documentation in https://github.com/exercism/docs/blob/master/you-can-help/improve-exercise-metadata.md#evolving-exercises . So that says what you should keep in mind when writing the issue.
I have just read it and all the advice in there still seems relevant.
copy it to all those tracks repositories
Here are some possible ways I know of to do this.
Most helpful comment
Great. Shall I raise a PR?