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.
Let's say you have to find if there is a prime gap of 30 between 1000000 and 1000040, you have calculated all the prime numbers until 1000040 instead of only checking which of those 40 numbers were primes, I don't think that's ok.
Hint: you need to multiply two numbers to get a number. Let's say you're checking if
2 * 13 = 26
is prime: By the you get to "13 is a divisor by 26", you'd already have checked "2 is a divisor by 26" ;-)Half
is too much, you need a better estimate ;-)Checking for primality is expensive (in time), so why are you calculating all primes between 1 (that's not a prime number btw) and
n
?For string that could be in multiple lines you need
\A
/\Z
instead to match the entire string:https://stackoverflow.com/questions/4250062/what-is-the-difference-between-and-a-and-z-in-regex
That's what same multiplicity means, your code only checks if any value of
a2
is the square of all values ofa1
.Use this to print your arrays:
Your code doesn't address the "same multiplicity" condition.