Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Media 3 numeros

x :: Float
y :: Float
z :: Float
x=13.0
y=23.9
z=32.8

main = print $ (x+y+z)/3

Compile and Execute Haskell Online

num::Int
nu::Int
nu=4
num=2
main=print(num+nu)

lab1

{- Lab 1
   Authors: Pouya Faramarzi
   Lab group:
 -}
---------------------------------------------
power :: Integer -> Integer -> Integer
power n k
                | k < 0 = error "power: negative argument"
power n 0   =   1
power n k   =   n * power n (k-1)

-- A -------------------------
-- stepsPower n k gives the number of steps that
-- power n k takes to compute

stepsPower :: Integer -> Integer -> Integer
stepsPower n k = (k + 1)


-- B -------------------------
-- power1
power1 :: Integer -> Integer -> Integer
power1 n k     
                | k < 0 = error "power: negative argument"
power1 n 0      = 1
power1 n k      = product [n | n <- [n..k]]
                

{-
let powerList = []
power1 n k 
                | k < 0 = error "power: negative argument"
power1 n 0  =   1 : powerList
                product powerList
power1 n k  =
                n : powerList
                power1 n (k-1)
-}

-- C -------------------------
-- power2

--power2 = undefined

-- D -------------------------
{- 

<Describe your test cases here>

 -}

-- comparePower1
--comparePower1 = undefined

-- comparePower2
--comparePower2 = undefined

-- Test functions: 

Compile and Execute Haskell Online

main = putStrLn "hello world"

esCero :: Int -> Bool
esCero x | x/=0 = False

esPositivo :: Int -> Bool
esPositivo x | x>0 = True

paratodo :: [Bool] -> Bool
paratodo [] = False
paratodo (x:xs) | x == True = True && paratodo xs
   | x == False = False && paratodo xs


sumatoria :: [Int] -> Int
sumatoria [] = 0 
sumatoria (x:xs) = x + sumatoria xs

productoria :: [Int] -> Int
productoria [] = 0
productoria (x:xs) = x*productoria xs

factorial :: Int -> Int
factorial 0 = 1 
factorial x = x*factorial x-1

promedio :: [Int] -> Int
promedio [] = 0
promedio (x:xs) = x+promedio xs/

Compile and Execute Haskell Online


soma:: Fractional a => [a] -> a
soma lista | length lista == 1 = head lista 
           | length lista /= 1 = soma(tail lista) + head lista





potencia :: (Float, Int) -> Float
potencia (x, 0) = 1
potencia (x, n) = x * potencia(x, n-1)

       
fact:: Int -> Int
fact 0 = 1
fact n = n * fact(n - 1)

fibo:: Int -> Int
fibo 0 = 0
fibo 1 = 1
fibo 2 = 1
fibo n = fibo(n - 1) + fibo(n - 2)

euler1:: Int -> Float
euler1 0 = 1
euler1 n = 1 / fromIntegral(fact(n)) + euler1(n-1)

euler2:: Int -> Float
euler2 n = potencia( 1 + 1/ fromIntegral(n) , n)




raizEquacaoQuadratica :: (Float, Float, Float) -> (Float, Float)  
raizEquacaoQuadratica (a,b,c) = (x1, x2) where 
   x1 = e + sqrt d / (2 * a) 
   x2 = e - sqrt d / (2 * a) 
   d = b * b - 4 * a * c  
   e = - b / (2 * a)  


main = do 
    let  vetorEntrada = [1, 2, 3, 4, 5, 6, 7, 8]
    
    let somaNativo = sum vetorEntrada
    let media = somaNativo / fromIntegral(length vetorEntrada)
    
    print("Soma do vetor: (Nativa)")
    print(somaNativo)
    print(" ")
    print(" ")
    
    print("Soma do vetor: (Proprietaria)")
    print(soma vetorEntrada)
    print(" ")
    print(" ")
    
    
    print("Media do vetor:")
    print(media)
    print(" ")
    print(" ")
    
    
    print("Maximo do vetor: (Nativa)")
    print( maximum  vetorEntrada)
    print(" ")
    print(" ")
    
    print("Maximo do vetor: (Proprietaria)")
    print( maximum  vetorEntrada)
    print(" ")
    print(" ")
    
    print("Minimo do vetor: ")
    print( minimum  vetorEntrada)
    print(" ")
    print(" ")
    print(" ")
    print(" ")
    
    print("------Codigos recursivos-------")
    print("Fatorial de 5")
    print( fact 5)
    print(" ")
    print(" ")
    
    print("Fibonacci indice 6")
    print( fibo 6)
    print(" ")
    print(" ")
    
    print("Calculo do numero de Euler por serie de Taylor")
    print( euler1 10)
    print(" ")
    print(" ")
    
    print("Calculo do numero de Euler pela definicao")
    print( euler2 1000)
    print(" ")
    print(" ")
    
    print("Potencia de 4 elevado a 3")
    print( potencia(4, 3))
    print(" ")
    print(" ")
    
    print(" ")
    print(" ")
    print(" ")
    print(" ")
    print("------Outros-------")
    print ("Raizes da equacao x^2 - 8x + 6")
    print(raizEquacaoQuadratica(1,-8,6))
    
    
    
    
    

aaaa

main = putStrLn "hello world"

https://github.com/JoaozinhoCC/PLP_Haskell.git

module Util where 
import Data.Map (Map, (!))
import qualified Data.Map as Map
import System.Random
import Data.Char

{-Caracter que representa partes das bases inimigas -}
base :: Char
base = '⊡'

{-Caracter que representa Terreno-}
terreno :: Char
terreno = '_'

{-Tiro Perdido-}
wShot :: Char
wShot = 'X'

{-Tiro em Base Inimiga-}
sShot :: Char
sShot = '☠'

{- --------------------------------------------
   Funções de número aleatório
   ---------------------------------------------}


{-Gera um número aleatório até 10-}
myRandom :: IO Int
myRandom = randomRIO (fromInteger(1),fromInteger(10))

myRandom' :: Int -> IO Int
myRandom' max = randomRIO (fromInteger(0),max)

{-Gera um número aleatório par até 10-}
evenRandom :: IO Int
evenRandom = do
	x <- myRandom
	if (even x)
		then return x
		else evenRandom

{-Gera um número aleatório ímpar até 10-}
oddRandom :: IO Int
oddRandom = do
	x <- myRandom
	if (odd x)
		then return x
		else oddRandom
		
{-Nomes das bases-}
baseNome :: Int -> String
baseNome 0 = "CT (tamanho: 1)."
baseNome 1 = "IAPA (tamanho: 2)."
baseNome 2 = "BMT (tamanho: 3)."
baseNome 3 = "BPC (tamanho: 4)."

{-Tamanho da base, em relação ao id do baseNome-}
baseSize :: Int -> Int
baseSize = (+1)

{-Orientação da base no tabuleiro-}
vertical :: Char
vertical = 'v'

showPosicao :: Int -> String
showPosicao n | n == 0 = show(terreno)
				| ((n == 1) || (n == 2) || (n == 3) || (n == 4))  = show(base)
				| n == -1 = show(wShot)
| n ==7 = show(sShot)

Compile and Execute Haskell Online

main = print [[x,y,z] | x<-[1..10],y<-[1..10],z<-[1..10],x*x+y*y==z*z,x>y]

Hello,World!

main = putStrLn "hello world"

Lola

main = putStrLn "hello wo"

sorted :: (Ord a) => [a] -> Bool
sorted [] = True
sorted [x] = True
sorted (x:xs:xss) = x<=xs && sorted (xs:xss) 

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.