You need to sign in or sign up before continuing.×
5 kyu

Help Suzuki pack his coal basket!

131 of 196user8476848
Description
Loading description...
Dynamic Programming
Algorithms
Data Structures
Mathematics
  • Please sign in or sign up to leave a comment.
  • Jam14man Avatar

    How can I remove an incorrect solution made due to imperfections in random tests?

  • ahmet_popaj Avatar

    Very nice finding out the dynamic, optimal solution to this one.

  • akar-0 Avatar

    COBOL translation (author gone).

  • bestwebua Avatar

    omfg, I have done this) @user8476848, thanks for this kata! Cheers!

  • Voile Avatar

    This is probably way too hard for a 5kyu.

    I'd suggest up-ranking it to 4kyu or so.

  • bestwebua Avatar

    This comment has been hidden.

  • pschoenfelder Avatar

    I'm not understanding something or one of the examples is incorrect.

    basket = 50
    pile = 'dust83dust 45 25 22 46'
    Test.assert_equals(pack_basket(basket,pile),'The basket weighs 47 kilograms')
    

    You cannot make 47 from any combination of 83, 45, 25, 22, and 46. What gives?

  • myjinxin2015 Avatar

    My poor greedy thief, why no guys to solve that one?

    https://www.codewars.com/kata/58296c407da141e2c7000271

  • zebulan Avatar

    @rollietikes,

    I just started on this kata and I am getting these odd error messages.

    returns The basket weighs 92 kilograms
     It should work with random inputs too: 'The basket weighs 92 kilograms' should equal 'The basket weighs 94 kilograms'
    
    returns The basket weighs 40 kilograms
     It should work with random inputs too: 'The basket weighs 40 kilograms' should equal 'The basket weighs 41 kilograms'
    
    returns The basket weighs 66 kilograms
     It should work with random inputs too: 'The basket weighs 66 kilograms' should equal 'The basket weighs 67 kilograms'
    

    My output seems to be matching what the test.it describes but that doesn't seem to be the correct answer. All of the other random tests where my output matches the test.it message, I get Test Passed.

    As I said, I just started on this kata and it's entirely possible that my code is wrong. If that is the case, something seems to be wrong with the error messages. Otherwise, it seems like something could be wrong with the random tests.

    I'm leaning towards my code being wrong since other people have passed this kata already but maybe you could take a look at the random tests just to make sure they are correct.

    Thanks!

    EDIT:

    Just to show you what I mean about the passing random tests:

    returns The basket weighs 192 kilograms
     Log
    The basket weighs 192 kilograms  # <-- I printed my a copy of my output right before the return statement
     Test Passed
    
    returns The basket weighs 91 kilograms
     Log
    The basket weighs 91 kilograms  # <-- I printed my a copy of my output right before the return statement
     Test Passed
    

    In those passing random tests, my output also matches the test.it message above saying what the return value should be.

  • Blind4Basics Avatar

    Nice one. 'Made me a little bit crasy, at some time... ;) (I am not confortable with greedy algorithms yet)

    Once again, I have some suggestions :

    • it lacks a test with basket lower that all the elements of "pile". By chance, I encountered this case in the random tests, but its occurence is rare, so for example, use : basket = 10 and pile='25 16'
    • if you use elements like "dust6dust34" to create piles for the random tests, you should have at least one basic test case with that too.

    If you apply those suggestions, you won't need anymore to display the pile used for the random tests (this display is not really easy to use right now, because you give the pile, but not the value of basket. Maybe add that if you want to keep the display of pile ?) and your output would be lightened so you could... :

    • had tags like "optimization" to your kata and so make it greedier, by increasing the number of random tests and the size of pile. I tried with pile of 400 elements and 400 random tests : it goes to something like 2.5 to 4s (tested on my algorithm and kjmosher's one).

    What do you think ?

  • gtnumen Avatar

    Good kata overall!

    Some super minor feedback:

    1. You could up the difficulty slightly by allowing strings like 'dust20dust5'.

    2. I also think that the testing limits could be better defined by stating that the maximum amount of coal pieces in the pile is 100, not just 1 <= pile <= 100, which I assume means up to 100 coal pieces.

    Other than that, it was fun. Thanks!

  • smile67 Avatar

    Only the second (but python is not my "main language"):-), good kata, well done;-)!

  • gabbek Avatar

    Thank you very much for awesome kata! :) Have a nice day!