These are chat archives for Codewars/codewars.com/kata-solving-help

27th
Aug 2016
Natacha Beck
@natacha-beck
Aug 27 2016 05:51
Hmmm I really don´t get this one :
This message was deleted
This message was deleted
RAUL B. CONDOY
@raulbc777
Aug 27 2016 05:52
@natacha-beck you're not going to believe it
Natacha Beck
@natacha-beck
Aug 27 2016 05:52
what ?
RAUL B. CONDOY
@raulbc777
Aug 27 2016 05:52
the result of this kata
Natacha Beck
@natacha-beck
Aug 27 2016 05:53
!
Seriously I stuck
This message was deleted
RAUL B. CONDOY
@raulbc777
Aug 27 2016 05:53
When I did it I laughed :smile:
Natacha Beck
@natacha-beck
Aug 27 2016 05:54
``````def am_I_Wilson(p)
my_fact = fact(p-1) + 1
my_div  = p*p.to_f
res     = my_fact / my_div
res == res.ceil rescue true
end

def fact(n)
n == 0 ? 1 : n * fact(n-1)
end``````
For the moment I cry :(
RAUL B. CONDOY
@raulbc777
Aug 27 2016 05:55
I solved in Python I think
Natacha Beck
@natacha-beck
Aug 27 2016 05:55
I´m stuck with big number
My logic seems to be not so bad
RAUL B. CONDOY
@raulbc777
Aug 27 2016 05:58
Let me remember the Wilson primes are the ones that
``(fact(p - 1) + 1 ) % p**2 == 0``
Natacha Beck
@natacha-beck
Aug 27 2016 06:11
``````import math

def am_i_wilson(n):
if n <= 0:
return False
else:
return (math.factorial(n - 1) + 1 ) % n**2 == 0``````
failed
:(
RAUL B. CONDOY
@raulbc777
Aug 27 2016 06:18
The point is that you don't have a primality test in your code.
You may use Miller-Rabin test or the one that you prefer. In Ruby with `require 'prime'` you have the it in `isprime()`
Natacha Beck
@natacha-beck
Aug 27 2016 06:28
Grhhhhhh!!!!! Thanks a lot got it in ruby
!!
RAUL B. CONDOY
@raulbc777
Aug 27 2016 06:28
:+1:
Natacha Beck
@natacha-beck
Aug 27 2016 06:28
a 8 kyu seriously... it's easy but I passed too much time on it
thanks for the hint
RAUL B. CONDOY
@raulbc777
Aug 27 2016 06:29
But you didn't realize about the result?
Natacha Beck
@natacha-beck
Aug 27 2016 06:29
``````def am_I_Wilson(p)
[5, 13, 563].include? p
end``````
!!!
It's a joke ?
RAUL B. CONDOY
@raulbc777
Aug 27 2016 06:30
There are only 3 Wilson Primes!!
Natacha Beck
@natacha-beck
Aug 27 2016 06:30
Clever and best practice in ruby !
Moahha
RAUL B. CONDOY
@raulbc777
Aug 27 2016 06:32
Some users investigated at https://oeis.org/A007540 and got the result
Natacha Beck
@natacha-beck
Aug 27 2016 06:33
ok I need a break after this kind of kata...! Thanks Raul for the help and for the reference