7 kyu
Sexy Primes <3
790 of 1,766Alpri Else
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
It really doesn't matter what level you're at — working with prime numbers is always both fun and challenging.
Thanks for the sexy challenge! 🙌🔢💖
This comment has been hidden.
That's what we call bad testing...
Javascript fork
chai
instead of the deprecated Codewars test framework, enabled JS Node v18for(var i = 2;i < Math.sqrt(n); i++)
changed tofor(var i = 2; i*i <= n; i++)
for accurate primality testingThis comment has been hidden.
Approved.
This comment has been hidden.
Duplicate issue (I'll try to fix this)
This comment has been hidden.
Fixed.
python new test framework is required. updated in this fork
Approved
This comment has been hidden.
Neither 22, 16, 21, 27, 256, 262, 18, 12, 15 nor 9 are prime numbers. Not a kata issue.
Now it became clear. I'm sorry, English is not my native language. Just translation difficulties. I was wrong, I'm sorry
No problem.
JS Node 18. should be enabled
enabled
C# :
Initial code should remove two redundant imports
using System.Collections.Generic; using System.Linq;
No random tests
This comment has been hidden.
Ruby 3.0 should be enabled.
This comment has been hidden.
This comment has been hidden.
Author C# version is just horrible (it doesn't even require primality check). It should be completely rewritten.
Also, all language versions need fixed test that requires primality tests.
Still missing test for non-prime numbers. See my solution.
This comment has been hidden.
Ruby translation submitted, thanks for your kata :)
Hey there. My unsubmitted solution works for every test except a single (1/111) random one. The test expects false, but instead gets a true. It happens every time I attempt to submit.
If there's some edge case I'm missing, what might that be?
You can use
console.log
to print the arguments to your function. That way, you can find out what the input was when your function failed. My guess is that your program thinks 1 is a prime.This comment has been hidden.
[21, 27] is not a sexy prime pair because neither is prime... 21 is divisible by 3 and 7...27 is divisible by 3, 9, and 7
[16, 22] is not a sexy prime pair because, again, neither is prime...16 is divisible by 2, 4, and 8...22 is divisible by 2 and 11
Hence, your function should indeed return false because they are not prime. As the description says: "Sexy primes are pairs of TWO PRIMES that are 6 apart".
I cringed a little at my lack of comprehension there. Cheers man, thanks for the good Kata.
Tests should be randomized in order of pass or fail or else hardcoded solutions are still very possible! :)
I reorganized both the python and javascript solutions such that the true_tests and false_tests arrays are combined and shuffled before testing to mitigate hardcoded solutions. This should have fixed the issue.
Marking as resolved.
Some test outputs are invalid (21,27 and 16,22 in my case) though the program expects "true" output.
After reviewing the answers I can say, with a high degree of certainty, that sexy_primes(21,27) and sexy_primes(16,22) returns false ie. there is a method in the test casses (which we will call method_x for now) which determines whether or not your answer is correct by doing "Test.assert_equals(sexy_primes(x,y), method_x(x,y))". When testing method_x(21,27) and method_x(16,22), the method returned False for both the Javascript and Python languages.
The random tests for javascript are not working correctly. I've run my own test cases using the same parameters in the "failed" tests, and come up with the correct answer every time.
math.abs missed?
Nope – the test is incorrectly setup. It is calling a function
sex_prime
but it should besexy_prime
!Apologies, the individual who translated the Kata into Javascript introduced the problem, and it slipped by when I reviewed it. The issue should now be resolved.
Hi I translated the kata to Javascript :) Feel free to check it and if you are satisfied then please approve the translation.
This comment has been hidden.
This comment has been hidden.
Apologies, the randomized testing I implemented accidentally called the wrong function.
Should be fixed now. Thanks for pointing it out!
Marking as resolved.
Very few tests. You sould add at leats 100 random tests. Nevertheless upvoted because you are working hard.
And return
False
for all(most all) of them? Given that the user has only written four katas so far, you probably want to help him with those tests.I believe in a good balance of encouraging new users and raising the demanding level (because it's his fourth kata). You demanded that for me in my first kata and I'm grateful for that. (And still I have many things to learn). So, Alpri. Bkaes is right. I'm keen on helping you if you want. :-). Continue with your good work!!
I added quite a few more tests as you guys suggested. (100 more randomly generated pairs w/ randint, ~30 more sexy pairs which are tested in a randomized order)
Thanks for the encouragement and suggestions guys!
Your tests use
is_prime
function without defining it. This invalidates any solution which doesn't have anis_prim
e function.Sorry about that, should be fixed now.