Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import System.Environment
- ehPalindromo:: [Int] -> Bool
- ehPalindromo [] = True
- ehPalindromo a | a == reverse a = True
- |otherwise = False
- main = print $ ehPalindromo [1,0,2,1]
- import System.Environment
- qPerfect:: Int -> [Int]
- qPerfect 0 = [0]
- qPerfect n = n^2 : qPerfect (n-1)
- main = print $ qPerfect 5
- import System.Environment
- zipLists:: [a] -> [b] -> [c] -> [(a,b,c)]
- zipLists (x:xs) (y:ys) (z:zs) = (x,y,z):zipLists xs ys zs
- zipLists _ _ _ = []
- main = print $ zipLists [1,2,3] ['%','$','c'] ['f','g','3']
- import Data.Char
- import Text.Printf
- sumHex :: [Char] -> Int
- sumHex (x:xs) = ord x + sumHex xs
- sumHex [] = 0
- main = do
- putStrLn $ printf "Soma em hexadecimal: 0x%08x" $ sumHex ['a','b','c']
- import Data.Char
- import Text.Printf
- dobraTripla :: [Int] -> [Int]
- dobraTripla (x:xs) = | mod (length (x:xs)) 2 == 0 =
- dobraTripla[x^3 | mod (length (x:xs)) 2 /= 0]
- dobraTripla [] = [0]
- main :: IO()
- main = do
- putStrLn (show ( dobraTripla[1,2,3,4,5,6]))
- --------------------------------------------------------------------------------------------------------------------------------
- Lista 2 - 2013.1 - Q.2
- fatorial :: Int -> Int
- fatorial 0 = 1
- fatorial n = n * fatorial (n-1)
- add :: Int -> Int
- add a = a+1
- annexer :: (b->c) -> [a-> b] -> [a->c]
- annexer f [] = []
- annexer f (x:xs) = (f.x) : annexer f xs
- test [] val = []
- test (v:vs) val = (map v val):test vs val
- main :: IO()
- main = do
- print $ test [fatorial,add,add] [5]
- --------------------------------------------------------------------------------------------------------------------------------
- setFilters :: (a->b->Bool) -> [a] -> [(b->Bool)]
- setFilters a (x:xs) = a x : map a xs
- specificFilter :: [(a->Bool)] -> [a] -> [a]
- specificFilter l [] = []
- specificFilter [] l = []
- specificFilter (x:xs) (z:zs) | (x.z) == True =
- x ++ specificFilter xs zs
- otherwise = specificFilter xs zs
- setMaps :: (a->b->c) -> [a] -> [(b->c)]
- setMaps a (x:xs) = a x : map a xs
- specificMap :: [(a->b)] -> [a] -> [b]
- specificMap l [] = []
- specificMap [] l = []
- specificMap (f:fs) (x:xs) = map f x ++ specificaMap fs xs
- specificApply :: [(b->Bool)] -> [(a->b)] -> [a] -> [b]
- specificApply
- ---------------------------------------------------------------------------------------------------------------------------------
- -- | Main entry point to the application.
- module Main where
- gerarListaCombinacoes :: Int -> Int -> [[Int]]
- gerarListaCombinacoes n 0 = [[]]
- gerarListaCombinacoes n k | n < k = [[]]
- |otherwise = [(x:xs) | x <- [0..n-1], xs <- (gerarListaCombinacoes n (k-1))]
- main :: IO()
- main = do
- print $ gerarListaCombinacoes 4 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement