Ad
  • Custom User Avatar

    Well, it certainly isn't best practice.

  • Custom User Avatar

    Might seem a bit complicated, but I wanted to avoid writing all or any possibilities at all cost and see how it goes.

    There is only "one case" when addition will be greater than multiplying and it is when it involves a 1 operand.
    So whenever I found a 1 I add it to its smallest neighbour. (a + 1) * b > a * (b + 1) if a < b.
    If 1 is found at the beginning then I add it to the second operand hence the first line, avoiding to make the second line over complicated.
    The rest is just multiplied.

    Then the function might be of operands quantity free :) .

    If there is either a simpler or a "cleaner" (in a way of more Ruby friendly or better practise and still the same conditions) way of doing this I am interested :) .

  • Custom User Avatar

    You forgot about capacity

    [51.0, 41.2, 0.81, 2] => 100-51==49 (1)

    [25.6, 17.8, 0.69, 1] => 49-25.6==23.4 (1)

    [27.8, 19.0, 0.68, 4] => 23.4<27.8 (0)

    [11.2, 7.4, 0.66, 0] => 23.4-11.2-11.2==1 (2)

    [23.9, 15.6, 0.65, 3]] => 1<23.9 (0)

  • Custom User Avatar

    Either I do not understand with the kata or I disagree with the last test.

    From my understanding the following:

    [11.2,  7.4],
    [25.6, 17.8],
    [51.0, 41.2],
    [23.9, 15.6],
    [27.8, 19.0],
    

    Should sort into (from most desired to least):

    [51.0, 41.2],
    [27.8, 19.0],
    [25.6, 17.8],
    [23.9, 15.6],
    [11.2,  7.4],
    

    Which should give the result [1, 0, 1, 0, 1] (note that this is a special case where size AND value sort the same way).

    Instead we got strangely something like that? :

    [51.0, 41.2],
    [11.2,  7.4],
    [25.6, 17.8],
    [27.8, 19.0],
    [23.9, 15.6],
    

    As the exercise expect [2, 1, 1, 0, 0].

    That is super strange, no?