Ad
  • Default User Avatar

    There might, if I knew the language I might fix it.

  • Custom User Avatar

    I made a similar algorithm to yours and got the same error. The problem was that when I modulo 101^exp, I got the result of 1, which was used as the exponent for the next number.

    This problem happens whenever base^exp ends with .....0x. So modulo cuts the number to the ending digit x, which makes the next steps for that case into 2^(2^1)=2^2-1. Whereas 2^(2^101)=2^(long number which ends with....52) = long number which ends with 6.

    Try changing the algorithm to do something slightly different for these cases.

  • Custom User Avatar

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

  • Custom User Avatar

    you are absolutely right. Thanks, man!

  • Custom User Avatar

    The true : false bit at the end is unnessary. The && will return the result you need.

  • Custom User Avatar

    Kata are better when they are about the 'what' rather than the 'how'

    assert_equals(swap([a,b]),[b,a])) would be reasonable and easy to test.

    The extra constraint you have here about not using a temporary variable, perhaps make for a nice puzzle, but not so good for a kata.

    A technique that some kata use for testing the method used is to apply some space or time limits.
    Most often used to test for algorithmic efficiency by testing against large data sets and using the execution time limit as a pseudo test.

    In this case you might want to somehow invoke a space limit by having a and b both being gigabytes in size so that the VM running the test has no room left to allocate space for the temporary variable, but since it would end up just being a tiny reference, that's probably not going to work.

  • Custom User Avatar

    Hi there!

    So I changed the description, no need to store the variables in an array, just return them
    and added some more tests but the kata will still pass if a temporary variable is introduced.
    Do you have any pointers on how to test that?

    Thanks for your help, feel like this is getting closer to what I originally wanted to
    publish!

  • Custom User Avatar

    Yes, this is my first one and I am definitely seeing that!
    Will try to refactor it today and add more tests that specifically check that
    the values the variables are pointing at have actually been changed rather
    than just changing the order :)

  • Custom User Avatar

    Great!
    I'll check back a bit later to see how you're getting on.
    It sometimes takes a while to craft a good kata.

  • Custom User Avatar

    The description talks about swapping but there is no swapping involved.

    The description says not to use a tempoaray placeholder, but there is no test for this condition.

    There is no test that the values of the variables are changed after running the function.

    Why is there an array being returned? What's that got to do with swapping?

  • Custom User Avatar

    Yes, working on it! I'm also changing the description a bit to make sure that the goal of the kata is understood.

  • Custom User Avatar

    Needs more tests.

  • Custom User Avatar

    haha, I guess you know how much I need to refresh my maths knowledge, thanks :)

  • Custom User Avatar

    4⁰ == 1.

  • Custom User Avatar

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

  • Loading more items...