Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(6-numeros-primos/crystal): baby first prime number checker #392

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)