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 really liked the challenge, however as a person who learned to program from Ruby, may I suggest to expand on the instruction or the tests, it took me a couple of tries to understand was it was that the challange wanted from the user. Other than than that, great challenge. Looking forward for more.
Agreed. Codewars uses Ruby 2.1.6, and this issue is not fixed until 2.2
The random tests fail because although
-3
should return false, Ruby 2.1.6sees it as
-3.abs.prime?
, where "self" is just3
.I filed a suggestion on this kata... IDK how much the author can do about this.
Which version of Ruby do you have locally? My Ruby 2.0.0 return
false
for negative numbers.Large numbers would work with my own tests but not the tests run on submission. Issue seems to have been resolved now I think.
I think I've fixed it. The same error was also in the CoffeeScript translation. Long story short: don't use
ceil
or.to_f
on numbers that exceed the safe range of2^53 - 1
of IEEE 754 double values.The ruby test uses floating point operations on large numbers, which does not yield the correct result.
I've got it. Going to file an issue, but I also try to resolve it.
i get this too
Sorry, I have no experience with Ruby, and it is indeed weird that the solution produces wrong results.
Could it be some limitation of large integers in Ruby?
Hopefully the author of the Ruby translation could give us an answer :)
I agree. I don't see why the regulard Bignum calculations aren't "correct".
23908490234823904833 should be 23908490234823904835 not 23908490234823905280
I think that the ruby submission tests for big numbers are broken.
Works with big numbers
n: 9324082039
Test Passed: Value == 9324082040
n: 129043509843590
Test Passed: Value == 129043509843590
n: 23908490234823904833
Expected: 23908490234823905280, instead got: 23908490234823904835
n: 9012384091234898738954729342
Expected: 9012384091234899173918638080, instead got: 9012384091234898738954729345
This didn't work for me because many of the tests are random and Ruby's stdlib Prime will return true for negative numbers when the absolute value is prime, but the test is not expecting it.