Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Very nice. I was on my way down this path but got a bit lost in the math so I abandoned it. Should have stuck with it, very satisfying solution.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Your solution is not displayed completely. Please, train this kata again and include the other foo's into scramble()
Yes, this one is
O(n^2)
. With a small change it can becomeO(n*sqrt(n))
: https://www.codewars.com/kata/reviews/55aa0d71c1eba8a65a000132/groups/5ab759b615c5933796000dff And I think there should be even better solutions possible.Do you mean the most optimized solution can be O(n*sqrt(n)) ? Cuz the one above is not I believe. You have n numbers and for each one you do n/2 steps, so its O(n^2) worst case scenario right ?
It's easily
O(n*sqrt(n))
. With precomputing a list of primes it's probably even better.Just a minor optimization upgrade ( even though its still O(n^2)).. you only have to check numbers until n/2 since numbers between n/2 and n can't be divisors of n.
Good one, same as mine but maybe clear.
Unfortunately, there's no clever way of doing this, it has to be O(n^2), because they way f(sum of squared divisors of number inluding itself) behaves is very erratic and unpredictable.
You can maybe skip prime numbers since they will always give a false result, but not enough to get it below O(n^2).
So why do you map the characters in the first string, which can potentially be very big, than doing it on the 2nd one ? It helps with performance in average cases.
str2 will aways be shorter than str1 otherwise the function returns false
e.g
str1 has 1million characters
str2 has 5 characters
str2 can be made out from the first 10 characters of str1
you have just saved a lot of space if you also keep track of when keys in the map reach 0.
Check my solution for how to get max performance for this.
This comment is hidden because it contains spoiler information about the solution
Hey,
I struggled a bit with the math part of this part. Maybe you could explain a couple of things.
The whole Math.atan2(y,x) gives me a headache. What are the potential values of this and on what part of the circle is the 0 ?
what does the conversion (1-Math.atan2(y,x) / Math.PI) * 180 do exactly ? What will be the new range of your angle?
Where does the 18 come from when searching for the slice of the circle the angle falls on ?
Cheers, very clean solution.
This comment is hidden because it contains spoiler information about the solution