6 kyu

Avoid trillion years of calculations !!

122 of 129raulbc777
Description
Loading description...
Performance
Algorithms
Mathematics
Machine Learning
  • Please sign in or sign up to leave a comment.
  • RealKenshiro Avatar

    Excellent one!

  • adazhu2802 Avatar

    I have two questions about permutation task as following:

    1. In test case, [10] should return 0. However, 0! and 1! are 1 in math.
    2. In test case, [1,...,13] should return 67xxxxxxx . However, 13! is 6227020800 in math.

    So is it permutation task different to the math formular? is it the new definition by kata? If this permutation definted by kata, please let me know how [1,....,13] in test case got 67xxxxxxx. I don't need code but fomular please. Thanks.

    • raulbc777 Avatar

      Hi, @adazhu2802. You have to experiment with the code for different lengths of iterables, arrays or strings, and then, try to figure out the pattern of these results. If you introduce an iterable of length 1, the counter will be 0. That's an important hint to know that the value of the counter isn't simple as factorial(length). Have a good day!

  • adazhu2802 Avatar

    I am new here. Please let me know how to submit my solution. Many thanks!

    • dinglemouse Avatar

      Press the (bottom-right) button labelled Attempt to run the Kata test cases.

      If your solution passes, the button label will change to Submit Final.

      Press it.

  • adazhu2802 Avatar

    This comment has been hidden.

  • Voile Avatar

    This comment has been hidden.

  • ZED.CWT Avatar

    Passed all tests before 30 to 50 cases, then failed all tests after.

     Testing for iterable: iayciemrkxpuzihjretxqhcptrrkfxlvswlpnodjnwajgmbslg------------>  counter:31035053229546175414930574765053879335254564565067479107390930944
    31035053229546199656252032972759319953190362094566672920420940312L should equal 31035053229546175414930574765053879335254564565067479107390930944L
     Testing for iterable: [87, 83, 12, 90, 18, 118, 50, 125, 95, 133, 41, 70, 11, 106, 104, 23, 32, 5, 27, 53, 144, 54, 52, 24, 88, 85, 16, 33, 134, 135]------------>  counter:274410818470141979392411550351360
    274410818470142134209703780940312L should equal 274410818470141979392411550351360L
    
    ...
    ...
    
     Testing for iterable: [496, 36, 47, 319, 214, 461, 404, 410, 424, 437, 196, 199, 125, 306, 372, 280, 517, 324, 132, 204, 531, 512, 284, 399, 207, 118, 158, 264, 185, 343, 91, 93, 331, 43, 335, 112, 356, 547, 394, 135, 477, 49, 179, 401, 511, 307, 130, 532, 312, 183, 352, 149, 51, 460, 127, 291, 459, 299, 290, 143, 111, 305, 246, 92, 266, 42, 533, 542, 400, 374, 106, 490, 342, 421, 363, 282, 154, 63, 83, 539, 124, 23, 74, 22, 478, 100, 228, 402, 332, 380, 314, 538, 520, 325, 425, 60, 482, 87, 535, 186, 194, 311, 488, 78, 486, 470, 491, 259, 24, 417]------------>  counter:16028178396288989057245308390927932465331623439654827235469952068851902112396223421767896724456884403833923460385593556416659605999580930976124053379571847909205421911042378694656
    16028178396289014701258409855092678943673045433708423928570406360980746444276798572896043427681153914716768010060384387640448280252480370395985821340917452556442336528920420940312L should equal 16028178396288989057245308390927932465331623439654827235469952068851902112396223421767896724456884403833923460385593556416659605999580930976124053379571847909205421911042378694656L
    

    Passed all up to 10 elements cases so i guess i got the correct pattern, which is weird that results are slightly different because it's just integer calculation. So what could the problem be....

    • raulbc777 Avatar

      Thanks ZED.CWT for your fast feedback. I found a division in my formula for the pattern. That's my mistake for the low precision that I have. I'll see if I can get the pattern in another way. If not I will drop the length of the iterables.

    • raulbc777 Avatar

      I'll unpublish it for a while for a better precision.

    • raulbc777 Avatar

      Could you try again in Python 2? I have another solution with sums and products only. After this I'll prepare it for Python 3

    • ZED.CWT Avatar

      Seems good to me o_O

      Question marked resolved by ZED.CWT 7 years ago