Ad
  • Default User Avatar

    "Out of interest do you know if this kind of data structure has been used anywhere?"

    I second that! Searched around the web for clues but found none so far.
    Also wonder what's the optimal data structure for implementing it - some kind of DAG? I'd very much like to see a purely functional solution.

  • Default User Avatar

    That's true but the description never promises more than "Define a function ... that takes one integer argument...". Don't mind me, I'm just a math nerd :)

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Not best Ruby practices, since it's using "for" and unnecessary "return", otherwise - nice.

  • Default User Avatar

    I'm not sure what you mean with your question :) While this:

    quantity - quantity/3
    

    means you drop every third mango from the calculation (because it's free by definition), your snippet - ((quantity / 3 ) * 2) * 2 - is not mathematically equivalent to the former (hint: integer division is not exactly like float division).

  • Default User Avatar

    I like your solution best (dunno if it's most idiomatic, being Elixir newbie myself), it's most readable and goes the farthest (along with g964's) before it hits some Erlang integer minimum (namely, -1.797e+308) when calculating the partial sum (according to my naive test set):

    test "fortune billion years, interest 1, inflation 1" do
      assert(
        Bankerplan.fortune(100000, 1, 1000, 69525, 1) == false
      )
    end
    

    Interestingly enough, the solution using Stream gives up some ~500 years earlier :) (probably due to the suboptimal interest rate calculation)

  • Default User Avatar

    Although it doesn't work for negative integers :)

  • Default User Avatar

    All tests pass green but I can't submit the solution - I can click the "Submit" button multiple times and it just runs the tests over and over again, not letting me proceed. :(

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution