Whilst I have no experience on what an issue is considered here, the problem can be solved without assuming that. It will take more iterations, though...
PS: To clarify and not saturate the comments section, the above means that that is not required to solve the problem and thus not an issue.
@notliam That also confused me, indeed.
In the description (original & current), each row shows the current stage: on the left, the modified array; on the right, the processing and its relation with the above array.
You propose to show the original array on the left and the modified one on the right. I think your suggestion would require changing the steps as well like this (plus some verbosity added):
The instructions are way more complicated than the problem itself. In case it sheds some light to prospective trainees:
Given an array X of positive integers, its elements are to be transformed by running the following operation on them as many times as required:
if X[i] > X[j] then X[i] = X[i] - X[j]
When no more transformations are possible, return its sum ("smallest possible sum").
For instance, the successive transformation of the elements of input X = [6, 9, 21] is detailed below:
X_1 = [6, 9, 12] # -> X_1[2] = X[2] - X[1] = 21 - 9
X_2 = [6, 9, 6] # -> X_2[2] = X_1[2] - X_1[0] = 12 - 6
X_3 = [6, 3, 6] # -> X_3[1] = X_2[1] - X_2[0] = 9 - 6
X_4 = [6, 3, 3] # -> X_4[2] = X_3[2] - X_3[1] = 6 - 3
X_5 = [3, 3, 3] # -> X_5[1] = X_4[0] - X_4[1] = 6 - 3
The returning output is the sum of the final transformation (here 9).
I see
X_5[1] = X_4[0] - X_4[1]
here as well as in the description, but it isX_5[0]
being changed fromX_4[0]
.This comment is hidden because it contains spoiler information about the solution
.. but that's not an issue. :D
Whilst I have no experience on what an issue is considered here, the problem can be solved without assuming that. It will take more iterations, though...
PS: To clarify and not saturate the comments section, the above means that that is not required to solve the problem and thus not an issue.
It's not required that
X[i]
must be the largest orX[j]
must be the smallest one.Why? Well, people familiar with competitive coding will instantly recognize what this kata is doing...
@notliam That also confused me, indeed.
In the description (original & current), each row shows the current stage: on the left, the modified array; on the right, the processing and its relation with the above array.
You propose to show the original array on the left and the modified one on the right. I think your suggestion would require changing the steps as well like this (plus some verbosity added):
Maybe it is more clear that way, I do not know.
Incomplete description:
Explain that
X[i]
is the largest element of X andX[j]
is the smallest one.Aha, this is where the typo in the description comes from ;) It should be
X_1 = [6, 9, 21] # -> X_1[2] = X[2] - X[1] = 21 - 9
I have updated the proposed Haskell translation with this as well.
Thanks for better detailed description, just updated kata
Haskell translation kumited.
Please review, and comment or approve.
The instructions are way more complicated than the problem itself. In case it sheds some light to prospective trainees: