Ad
  • Default User Avatar

    This is definitely the best solution I've seen for finding the unknown out of several possible ones.

  • Custom User Avatar

    Almost. If itemCount could be zero, then that fails. Use

    return (itemCount + itemsPerPage - 1) % ItemsPerPage + 1;
    

    I don't remember if zero is allowed in the statement, but it should just be a habit in Java, C and C++ to avoid negative arguments to %.

  • Custom User Avatar

    Liked your way of mixing characters with ints.

  • Custom User Avatar

    duplicate issue below

  • Default User Avatar

    A plus sign before (possibly negative) rand.nextInt() doesn't make it positive. At least not in Java.

  • Custom User Avatar

    Thanks, sorry for the delay.

  • Default User Avatar
  • Custom User Avatar

    Perfect. Not used any Math.pow() and the number of divisions is minimized

  • Default User Avatar

    Input: ORD, K^G, Q^E, DAD, T^B, A^L, B<F, S^I, AKA, AIA, JMJ, PFG, MGM

    Output:BEAHJFOKLTS

    It's not even of length 20.

  • Default User Avatar

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

  • Custom User Avatar

    Hi! Thanks for your feedback! Actualy I'm not really surprised. I spent a lot of effort on this kata. But every time there was an edge case which ruined my another attempt. May be the test cases should be improved to invalidate solutions such as mine.

  • Default User Avatar

    Hi. Unfortunately, your solution is incomplete. Consider this input:

    {88, 90, 89, 87}.

    Your program cannot find a solution, while it exists, e.g.:

    {88, 78, 77, 76, 86, 96, 95, 94, 93, 92, 91, 90, 80, 81, 82, 83, 84, 85, 75, 65, 66, 67, 68, 69, 79, 89, 99, 98, 97, 87}.

    Moreover, on this input:

    {88, 91, 89, 83}

    it returns a path of length 34:

    {88, 87, 86, 85, 84, 74, 73, 72, 71, 81, 91, 90, 80, 70, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 79, 89, 99, 98, 97, 96, 95, 94, 93, 83},

    while there is a path of length 32:

    {88, 78, 77, 76, 75, 74, 73, 72, 82, 92, 91, 81, 71, 61, 62, 63, 64, 65, 66, 67, 68, 69, 79, 89, 99, 98, 97, 87, 86, 85, 84, 83}.

  • Default User Avatar

    Hi. Unfortunately, your solution is incomplete. Consider this input:

    {30, 1, 28, 0}.

    Your program cannot find a solution, while it exists, e.g.:

    {30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 29, 19, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 12, 13, 14, 15, 16, 17, 18, 28, 27, 26, 25, 24, 23, 22, 21, 20, 10, 0}.

    Moreover, on this input:

    {56, 30, 21, 41}

    it returns a path of length 15:

    {56, 55, 54, 53, 52, 51, 50, 40, 30, 31, 21, 22, 32, 42, 41},

    while there is a path of length 13:

    {56, 55, 54, 53, 52, 51, 50, 40, 30, 20, 21, 31, 41}.

  • Default User Avatar

    Hi. Unfortunately, your solution is incomplete. Consider this input:

    {88, 29, 98, 58}.

    Your program cannot find a solution, while it exists, e.g.:

    {88, 78, 68, 67, 57, 47, 48, 49, 39, 29, 28, 38, 37, 36, 46, 56, 66, 76, 77, 87, 97, 98, 99, 89, 79, 69, 59, 58}.

    Moreover, on this input:

    {4, 19, 21, 6}

    it returns a path of length 39:

    {4, 3, 13, 12, 11, 10, 20, 30, 40, 41, 42, 43, 44, 45, 46, 36, 37, 27, 28, 29, 19, 18, 17, 16, 26, 25, 35, 34, 33, 32, 31, 21, 22, 23, 24, 14, 15, 5, 6},

    while there is a path of length 35:

    {4, 3, 2, 1, 0, 10, 20, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 29, 19, 18, 28, 27, 26, 25, 24, 23, 22, 21, 11, 12, 13, 14, 15, 5, 6}.

  • Default User Avatar

    Hi. Unfortunately, your solution is incomplete. Consider this input:

    {0, 2, 13, 1}.

    Your program cannot find a solution, while it exists, e.g.:

    {0, 10, 20, 30, 31, 32, 33, 34, 24, 14, 4, 3, 2, 12, 13, 23, 22, 21, 11, 1}.

    Moreover, on this input:

    {53, 49, 38, 69}

    it returns a path of length 26:

    {53, 43, 44, 45, 46, 47, 48, 49, 39, 38, 37, 36, 35, 34, 33, 32, 42, 52, 62, 63, 64, 65, 66, 67, 68, 69},

    while there is a path of length 20:

    {53, 43, 33, 23, 24, 25, 26, 27, 28, 29, 39, 49, 48, 38, 37, 47, 57, 67, 68, 69}.

  • Loading more items...