Skip to content

Instantly share code, notes, and snippets.

@Titinx
Last active December 19, 2016 20:59
Show Gist options
  • Save Titinx/1e04bf4c9f245ed7ae9426c08baf53a8 to your computer and use it in GitHub Desktop.
Save Titinx/1e04bf4c9f245ed7ae9426c08baf53a8 to your computer and use it in GitHub Desktop.
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