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.
I will get an error expected:<1.57[]> but was:<1.57[
]>
What is the problem here?
This comment is hidden because it contains spoiler information about the solution
@FArekkusu, I know the algorithm is correct, I just wanted to show which iterations are unnecessary without giving any hints. And by explaining me the exact mechanical process the user must've a thought: why am I repeating things and doing uncessary work, which is often missed when algorithm is not thought with sufficient amount of patience.
Why exactly up to
num/2
? It's also too much. Let's take a biggenr umber, for example 101. Do you really need to check up to101 % 50
? Hint: no, you don't.so the problem is solved .thank you.
The algorithm is correct. The only problem is that it does a lot more work than required, as hinted in the @hobovsky's comment.
Do you really nee to check
17 % 16?
okey, first 17 is greater than 1 so "else" will run.Then in the for loop, respectively the number of 2,3,4,5,6....16 will be '%' into 'num'.None of these numbers can % == 0 because 17%2= 1, 17%3=2 , ...17 % 16= 1 .so else will run.finally else is return True.so 17 is prime.
how will you verify whether 17 is a prime number?
(tell me the exact mechanical process)
This comment is hidden because it contains spoiler information about the solution