Skip to content

Commit

Permalink
Merge pull request #392 from Pantotone/challenges/6-numeros-primos/cr…
Browse files Browse the repository at this point in the history
…ystal/pantotone

feat(6-numeros-primos/crystal): baby first prime number checker
  • Loading branch information
lanjoni authored Oct 10, 2023
2 parents 8559be2 + 36e8ed9 commit d939734
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions challenges/6-numeros-primos/crystal/pantotone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Submissão de Exercicio

**Exercicio:** 6 - Números Primos

**Nickname:** Pantotone

**Nível Técnico:** Estudante

**Empresa:** Freelancer

**Twitter**: https://twitter.com/pantotone

**Dificuldade de Resolução:** - Média

**Comentários:** Mexendo com código faz anos, e nunca fiz um checker pra números primos..

**Como rodar o desafio**:

Use o comando abaixo:
```bash
crystal main.cr <input>
```
16 changes: 16 additions & 0 deletions challenges/6-numeros-primos/crystal/pantotone/main-v2.cr
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions challenges/6-numeros-primos/crystal/pantotone/main.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
number : Int32 = ARGV[0].to_i

def isPrime(number : Int32)
return false if number < 2

divisors = (2..number).select do |divisor|
number % divisor == 0
end

return divisors.size == 1
end

puts isPrime(number)

0 comments on commit d939734

Please sign in to comment.