From 36e8ed97bfcee46d7a151db85eb5f988ade96712 Mon Sep 17 00:00:00 2001 From: Panto! Date: Fri, 6 Oct 2023 13:06:19 -0300 Subject: [PATCH] feat(6-numeros-primos): a bit more optimized version (i think) --- .../crystal/pantotone/main-v2.cr | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 challenges/6-numeros-primos/crystal/pantotone/main-v2.cr diff --git a/challenges/6-numeros-primos/crystal/pantotone/main-v2.cr b/challenges/6-numeros-primos/crystal/pantotone/main-v2.cr new file mode 100644 index 00000000..4bbb1196 --- /dev/null +++ b/challenges/6-numeros-primos/crystal/pantotone/main-v2.cr @@ -0,0 +1,16 @@ +number : Int32 = ARGV[0].to_i + +def isPrime(number : Int32) + return false if number < 2 + return true if number == 2 + + divisor : Int32 = 1 + unless divisor > Math.isqrt(number) + divisor += 1 + return false if number % divisor == 0 + end + + return true +end + +puts isPrime(number) \ No newline at end of file