# Generación de progresiones geométricas

Definir la función

` geometrica :: Int -> Int -> Int -> [Int]`

tal que (geometrica a b c) es la lista de los términos de la progresión geométrica cuyo primer término es a, su segundo término es b (que se supone que es múltiplo de a) y los términos son menores o iguales que c. Por ejemplo,

``` geometrica 1 3 27 == [1,3,9,27] geometrica 2 6 100 == [2,6,18,54] geometrica 3 12 57 == [3,12,48] geometrica 4 20 253 == [4,20,100] geometrica 5 25 625 == [5,25,125,625] geometrica 6 42 42 == [6,42]```

#### Soluciones

```-- 1ª definición geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = takeWhile (<=c) (iterate (*r) a) where r = b `div` a   -- 2ª definición geometrica2 :: Int -> Int -> Int -> [Int] geometrica2 a b c = aux a b where aux a b | a > c = [] | otherwise = a : aux b (b * r) r = b `div` a```
Inicial

## 8 soluciones de “Generación de progresiones geométricas”

1. angruicam1
```import Data.List (unfoldr)   geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = takeWhile (<= c) (unfoldr (x -> Just (x,x*y)) a) where y = div b a```
2. alerodrod5
```geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = a : takeWhile (<= c) (iterate f b) where f d = d * (b `div` a)```
3. albcarcas1
```geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = takeWhile (<=c) [a*d^n | n <- [0..]] where d = div b a```
4. agumaragu1
```geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = takeWhile (<= c) \$ iterate (* (div b a)) a```
5. antgongar

Con unfoldr sin takeWhile

```import Data.List (unfoldr)   geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = unfoldr aux a where aux x | x > c = Nothing | otherwise = Just (x,x*r) r = b `div` a```
```  geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = takeWhile (<= c)(iterate f a) where f a = e*a e = div b a```
```geometrica :: Int -> Int -> Int -> [Int] geometrica a b c = a: takeWhile (<=c) (iterate (*h) b) where h=div b a```
```  (%i1) geometrica(x,y,n) := if(x>n) then [] else append([x], geometrica(y,y*(y/x),n));   (%i2) geometrica(4,20,253); (%o2) [4,20,100]   (%i3) geometrica(2,6,100); (%o3) [2,6,18,54]   (%i4) geometrica(5,25,625); (%o4) [5,25,125,625]```