Ad
  • Custom User Avatar

    You need something better than O(n²).

  • Custom User Avatar

    Hi, and welcome.

    First of all, remember to indicate the language you are using when asking for help, more than 50 languages are available on CodeWars. After visiting your profile, I have assumed you have been using JavaScript.

    Also, it's a good idea to include all the relevant part of the error logs you receive. I've just tried out your code on attempt tests, and I get this:

    <--- JS stacktrace --->
    
    FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
    

    Many times, this means your code gets lost in an infinite loop and you keep pushing stuff into an array until getting out of memory and the code crashes. I advice you to have a cautious look at the following help page to debug your solution: https://docs.codewars.com/training/troubleshooting/

    If you are a beginner, I would advice you to improve your skills on more basic tasks from the 8 or 7 kyu level. Some 6 kyu katas are pretty basic, but it is not the case of this one.

  • Default User Avatar

    all single digits are narcisitic because anything to the first power is equal to itself or
    x^1 = x

    7 is narcisitic because of the following.
    7 has one digit so I sum that one digit raised to the first power

    start = 7  
    sum = 7^1  
    print (start == sum)
    -- true
    

    for comparison

    start = 20
    sum = (2^2 + 0^2)
    print (start == sum)
    -- false
    
  • Custom User Avatar

    Use Pythontutor to visualize what your code is doing. Your code fails the second sample test.

  • Custom User Avatar

    You must return the result, not print it.

  • Default User Avatar

    Why do you ask? The values passed in are strings of space-delineated integers. Just look at this sample test:

    assert.equal(goodVsEvil('1 1 1 1 1 1', '1 1 1 1 1 1 1'), 'Battle Result: Evil eradicates all trace of Good');