import Data.Array
tetranacci ::Integer->Integer
tetranacci n =(vectorTetra n)! n
vectorTetra ::Integer-> Array IntegerInteger
vectorTetra n = v where
v = array (0,n)[(i,f i)| i <-[0..n]]
f 0=0
f 1=1
f 2=1
f 3=2
f n = v!(n-1)+ v!(n-2)+ v!(n-3)+ v!(n-4)
import Data.Array
tetranacci :: Integer -> Integer
tetranacci n = (vectorTetra n) ! n
vectorTetra :: Integer -> Array Integer Integer
vectorTetra n = v where
v = array (0,n) [(i,f i) | i <- [0..n]]
f 0 = 0
f 1 = 1
f 2 = 1
f 3 = 2
f n = v!(n-1) + v!(n-2) + v!(n-3) + v!(n-4)
Es la traducción literal del enunciado, aunque no es muy eficiente.
import Graphics.Gnuplot.Simple
tetranacci ::Int->Integer
tetranacci 0=0
tetranacci 1=1
tetranacci 2=1
tetranacci 3=2
tetranacci n = tetranacci (n-1)+ tetranacci (n-2)+ tetranacci (n-3)+ tetranacci (n-4)
listaTetranacci =[tetranacci x | x <-[1..]]
graficaTetranacci ::Int->IO()
graficaTetranacci n =
plotList
[Key Nothing, Title "graficaTetranacci"](take n (listaTetranacci))
Es la traducción literal del enunciado, aunque no es muy eficiente.
import Graphics.Gnuplot.Simple
tetranacci :: Int -> Integer
tetranacci 0 = 0
tetranacci 1 = 1
tetranacci 2 = 1
tetranacci 3 = 2
tetranacci n = tetranacci (n-1) + tetranacci (n-2) + tetranacci (n-3) + tetranacci (n-4)
listaTetranacci = [tetranacci x | x <- [1..]]
graficaTetranacci :: Int -> IO ()
graficaTetranacci n =
plotList
[Key Nothing, Title "graficaTetranacci"]
(take n (listaTetranacci))
import Data.Array (listArray, (!))import Graphics.Gnuplot.Simple (plotList, Attribute (Key, Title))
tetranacci ::Int->Integer
tetranacci n = v ! n
where v = listArray (0,n)([0,1,1,2,4]++[2*v!(i-1)-v!(i-5)| i <-[5..n]])
graficaTetranacci ::Int->IO()
graficaTetranacci n =
plotList
[Key Nothing, Title "Tasa de crecimiento de los numeros tetranacci"](zipWith(/)(tail tetr) tetr)where tetr ::[Double]
tetr =map(fromIntegral . tetranacci)[1..n]
import Data.Array (listArray, (!))
import Graphics.Gnuplot.Simple (plotList, Attribute (Key, Title))
tetranacci :: Int -> Integer
tetranacci n = v ! n
where v = listArray (0,n) ([0,1,1,2,4]
++ [2*v!(i-1)-v!(i-5) | i <- [5..n]])
graficaTetranacci :: Int -> IO ()
graficaTetranacci n =
plotList
[Key Nothing, Title "Tasa de crecimiento de los numeros tetranacci"]
(zipWith (/) (tail tetr) tetr)
where tetr :: [Double]
tetr = map (fromIntegral . tetranacci) [1..n]
3 soluciones de “Números tetranacci”