Last active
December 19, 2016 20:59
-
-
Save Titinx/1e04bf4c9f245ed7ae9426c08baf53a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
primes :: Int -> [Int] | |
-- primes, que dado un entero n devuelve una lista con los n primeros primos. | |
primes x = take x (filter (isPrimo) [1..]) | |
-- delegaciones | |
nextDiv :: Int -> Int -> Int | |
-- devuelve el siguiente divisor de x a partir de y | |
nextDiv x y | |
| x == 1 = 1 | |
| x == divisor || resto == 0 = divisor | |
| otherwise = nextDiv x divisor | |
where divisor = y + 1 | |
resto = (mod x divisor) | |
isPrimo :: Int -> Bool | |
isPrimo x = nextDiv x 1 == x | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment