6 kyu

The lost beginning

349 of 787CatPlusPlus
Description
Loading description...
Fundamentals
Algorithms
Strings
Mathematics
  • Please sign in or sign up to leave a comment.
  • kn8 Avatar

    I found this kata to be very satisfying.

    The problem is really simple but the solution isn't. At least not until it hits you.

    Also, the idea of using the iterator in the string method was new to me, so this kata made me think "outside the box".

    Thanks to the creator of this kata!

  • ilumini Avatar

    Nice task. I consider it as first task to remember. And because I liked it I believe to stay here at Codewars to solve other tasks...

    About task. I liked that it has so many issues to solve. I solved it only by iteratble procces of eliminating errors with a lot of conditions. And I was shocked to see the best solution - how simple it is. Nevertheless I've got it only after couple iterations in debugging )

    It was like in math - best solution occured to be a proof out of contradiction.

  • CatPlusPlus Avatar

    I changed the description of the kata, as quite a large number of people did not understand it. Could you comment on the readability of the kata and suggest new ideas for refining the condition

  • avermakov Avatar

    Solutions that ignore the Numbers will never be truncated part of the description (such as mine) may pass.

    Thanks to @crringe for spotting this and @JohanWiltink for finding and edge case (91).

    Python fork: https://www.codewars.com/kumite/65b664eb8ee05703817e69b7

  • ianfshirley Avatar

    This description is incredibly unclear. How are we supposed to know if the input string can be split into single digits or two digits or not split at all?

    "123" -> [1, 2, 3] -> 1 "1234567891" -> [1234567891] -> 1234567891

    There's no explanation of why the two examples above are being split up differently.

  • dinglemouse Avatar

    How to reconcile this in the description?

    Size limit says: 0 < smallest number < 1 000 000 000

    But the example says: "1234567891" -> [1234567891] -> 1234567891

    But 1 234 567 891 exceeds the "smallest number" limit (??)

  • CatPlusPlus Avatar

    This comment has been hidden.

  • dbtx Avatar

    In C, I started by converting each character to its 1-digit number and storing them in an array of 140 int (and counting them in the same pass) because the description states:

    0 < length string < 140

    After my solution mostly worked, it still consistently crashed with signal 11, always in the test group up_to_30_medium_numbers, until I increased that array size to 149. I put it at 150 because it's a nice round number, and now I can see that is exactly large enough. That test randomly generates up to 30 * 5-digit numbers, contradicting the description.

    I would add a line to random_test() just after preparation of num and len: while (num * len >= 140) --num; or similar.

  • Azaren Avatar

    This comment has been hidden.

  • debugger4O4 Avatar

    Go there, I don't know where to take it, I don't know what

  • stefu28 Avatar

    The description is very unclear, for many it needs far more details, as it appears there is some alleged grouping of numbers, yet the limits dont give any clear explanation of wat is expected.

  • pavloslav Avatar
  • o2001 Avatar
  • pavloslav Avatar
  • o2001 Avatar

    Out of curiousity: are approaches that rely on mathematically guessing the number of fittings going to fail for certain types of inputs where the inner numbers' lengths change in a particular way (like str(int(''.join(map(str, islice(count(0), 1001))) + '1')) (starts out at single digits, then double, then triple, then quadruple, then ends with an out-of-place single digit). I tested some answers here on this one and some seem to return 1 instead of the entire number.

  • JohanWiltink Avatar

    LC translation

    this translation modifies the description ( don't worry, LC always does that; it requires additional specifications other languages don't )

  • KayleighWasTaken Avatar
  • KayleighWasTaken Avatar
  • KayleighWasTaken Avatar
  • Madjosz Avatar
  • raistln Avatar

    Sorry, i simple don´t understand the kata. What should I do? The description says we should find the smalllest number, but the smallest number is always a mono numeric number. I know i lost something in the description, but I don´t know what, maybe its in the translation to my language, but really I don´t know what do you want. Sorry In the other hand, thanks for making katas for people like me.

  • CatPlusPlus Avatar

    If anyone has any suggestions for kata or a desire for translation into another language, I would be very grateful :)

  • JohanWiltink Avatar
    s = s[:10]
    

    I misread. This generates numbers of 10 digits, which can go up to 9 999 999 999. You need s[:9].

  • JohanWiltink Avatar

    The biased random generator ( the one that appends s[:u] ) generates inputs that break num < 2_000_000.

    Yes, writing biased random generators correctly is hard.

  • Voile Avatar

    This is a much easier version of this kata ;-)

  • Blind4Basics Avatar

    temporary issue to avoid prematured approval

    And good night. ;)

  • JohanWiltink Avatar

    Needs (a) fixed test(s) which would fit a lower number with a truncated last number in the string, eg.

    431243 -> 431243, not 4312
    577495 -> 577495, not 57749
    

    This currently relies on random tests, which do not always generate cases that catch this bug ( which my Python solution has ).

  • JohanWiltink Avatar

    Random tests need to use a reference solution.

    If num = 910, repeat = 1 should be generated, the correct result is 9, not 910.

  • Blind4Basics Avatar

    Two more:

    • actually, string is the name of a python module... 'x) => s
    • you could simplify the examples in the description, like "72637236" => 72637236. This way, they are language agnostic (for 95% of the languages, I guess)
  • Blind4Basics Avatar

    Hi again,

    • the typical inputs constraints should be given in the description
    • the argument name shouldn't be str: this a bad practice, because it's a builtin.

    cheers

  • Blind4Basics Avatar

    Hi,

    the random tests should be in a distinct test.it block from the fixed tests.

    Cheers

  • Nazar3234 Avatar

    WOW ! TOP !

  • mortonfox Avatar
    Log
    233334706233334707233334708233334709233334710233334711233334712233334713233334714233334715233334716233334717233334718233334719233334720233334721233334722233334723 233334706
    233334706 should equal 2
    

    Reference solution erroneously produces single-digit answers, but only some of the time.

  • JohanWiltink Avatar

    Nice! ( Pity I don't do Python, but I may just forfeit and translate. I'd better do that after Beta though. )

    The description could use an example - I think "string of natural consecutive numbers" is unambiguous, but an example would set my mind at ease I've correctly understood the input format.