Ad
  • Custom User Avatar
  • Custom User Avatar
  • Custom User Avatar

    I think it would even be approved 8, nowadays... XD

  • Custom User Avatar

    In JS, you may want to use BigInt for intermediate calculations. Also, calculating big powers knowing the result should be a mod by can be very expensive.

  • Default User Avatar

    yes, there is a more efficient algorithm. you should not be picking numbers randomly.

  • Custom User Avatar

    I then refine my guess to pick a random number between 1 and 500.

    Wrong. There should be no randomness involved in your algorithm. Otherwise, you're right: you may need more than 10 guesses.

    After the first guess, why do you need to pick a random number? Why did you pick 500 initially?

  • Default User Avatar

    your method is not efficient, how would you solve the problem in real life ? your getRandomArbitrary() function is problematic, you should have a rationalised algorithm that doesnt involve chance.

    also, side node: JavaScript is not Python. everytime you write stuff like variable = 1000 without a prior declaration of variable with let, const or var, you are not creating a local variable, you are creating global variables that will stay in memory for the entire duration of the program. it's considered very bad practice and can be the source of many bugs, as global variables will keep their values between function calls. (disregard this if you are doing it intentionally ^^)

  • Default User Avatar

    the formula is right there in the question.

  • Custom User Avatar

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

  • Default User Avatar

    I've typed out in Python (so basically, pseudocode if you don't use Python) the "translation" of the given mathematical formula:

    n = 2
    total = 0
    
    for i in range(0,n+1):
    	for j in range(0,i+1):
    		a_ij = 2*j + i + 1
    		total += a_ij
    
    print(total) # returns 22 with n=2, 50 with n=3
    

    note that in Python the upper limit of the range() is not inclusive, so in your language you might need to write from 0 -> n or 0 -> n+1 accordingly.

    You can implement this in your language to see that the numbers are correct, but obviously it won't work for large n - hence why the kata has tests with n = 10**6 ;)

    edit-spoilered now that user has read comment

  • Custom User Avatar

    The biggest factor in assessing the rank is the average ranking vote of beta testers. If more people would participate, more votes would be taken into account.

  • Default User Avatar

    I agree. This is more challenging than the average 7ku. I think it should be a 6. I've noticed what appears to be an overly reductive trend in rankings, where a kata's rank is calculated using something like Math.max(...subproblemRank). This fails to take into account the number of subproblems, the volume of code required, the relative amount of time spent on the problem, and the interactions between subproblems that adds an additional layer of challenge.

  • Custom User Avatar

    The last 7kyu I solved asked me to find the shortest word in a sentence. This seems significantly more difficult.

  • Custom User Avatar

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

  • Default User Avatar
  • Loading more items...