Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
import Data.Char
--1
enumFromToo :: Int -> Int -> [Int]
enumFromToo a b = if a == b
then [a]
else a:enumFromToo (a+1) b
--
--2
enumFromThenToo :: Int -> Int -> Int -> [Int]
enumFromThenToo x y z
|x<y = aux1 x (y-x) z
|x>y = aux2 x (y-x) z
|otherwise = [x]
where
aux1 a b c= if a<=c
then a:aux1 (a+b) b c
else []
aux2 a b c= if a>=c
then a:aux2 (a+b) b c
else []
--
--3
somalista :: [a] -> [a] -> [a]
somalista [] [] = []
somalista [] l = l
somalista (h:t) (p:f)= h:somalista t (p:f)
--4
lastt :: [a] -> a
lastt [h] = h
lastt (h:t) = lastt t
--5
initt :: [a] -> [a]
initt [_] = []
initt (h:t) = h:initt t
--6
pos :: [a]-> Int -> a
pos (h:t) i
| i==0 = h
| i>=0 = pos t (i-1)
--
--7
rev :: [a] -> [a]
rev [] = []
rev (h:t) = (rev t) ++ [h]
--8
takk :: Int -> [a] -> [a]
takk i (h:t)
| i==1 = [h]
| i>=1 = h:takk (i-1) t
| otherwise = undefined
--9
drAWP :: Int -> [a] -> [a]
drAWP i (h:t) = if i==0 then (h:t)
else drAWP (i-1) t
--
--10
zippy :: [a]-> [b] -> [(a,b)]
zippy _ [] = []
zippy [] _ = []
zippy (h:t) (p:f) = (h,p):zippy t f
--11
watson :: Eq a => a-> [a] -> Bool
watson i [] = False
watson i (h:[]) = i==h || False
watson i (h:t) = i == h || watson i t
--12
repeater :: Int -> a -> [a]
repeater i a = if i==0 then [] else a:repeater (i-1) a
--13
interMilan :: a -> [a] -> [a]
interMilan a [] = [a]
interMilan a (h:[]) = h:a:[]
interMilan a (h:t) = h:a:interMilan a t
--14
groupie :: Eq a => [a] -> [[a]]
groupie [] = [[]]
groupie [h] = [[h]]
groupie (h:t) = (h:samesies h t) : groupie (resto h t)
where
samesies a (h:t) =
if a == h
then h:samesies a t
else []
resto a (h:t) =
if a==h
then resto a t
else h:t
--
--15
concat' :: Eq a => [[a]] -> [a]
concat' [[]] = []
concat' ([]:t) = concat t
concat' ((h:t):f) = h:concat'(t:f)
--16
inits':: [a] -> [[a]]
inits' [] = []
inits' (h:t) = reverse(aux (reverse (h:t)))
where
aux [] = [[]]
aux [x] = [[x],[]]
aux (h:t) = ((h:t):aux t)
--
--17
tails:: [a] ->[[a]]
tails [] = [[]]
tails [x] = [[x],[]]
tails (h:t) = ((h:t):tails t)
--18
isPrefOf :: Eq a => [a] -> [a] -> Bool
isPrefOf [] [] = True
isPrefOf _ [] = False
isPrefOf [] _ = True
isPrefOf (h:t) (p:f) = if h == p
then isPrefOf t f
else False
--{-
--19
isSufOf:: Eq a => [a] -> [a] -> Bool
isSufOf [] [] = True
isSufOf _ [] = False
isSufOf [] _ = True
isSufOf l h = check (reverse l) (reverse h)
where
check [] [] = True
check _ [] = False
check [] _ = True
check (h:t) (p:f) = if h == p
then check t f
else False
--}
--20
isSSOf::Eq a => [a] -> [a] -> Bool
isSSOf [] [] = True
isSSOf l [] = False
isSSOf [] l = True
isSSOf (h:t) (p:f) = if h==p
then isSSOf t f
else isSSOf (h:t) f
--
--21
selemI::Eq a => a -> [a] -> [Int]
selemI x [] = []
selemI x (h:t) = contagem x (h:t) 0
where
contagem x [] c = []
contagem x (h:t) c = if x==h then c:contagem x t (c+1) else contagem x t (c+1)
--
--22
madeira :: Eq a => [a] -> [a]
madeira [] = []
madeira (x:xs)
| elem x xs = x:madeira (delAll x xs)
| otherwise = x : madeira xs
where
delAll _ [] = []
delAll x (h:t) =
if x==h then delAll x t
else h:(delAll x t)
{-
Versão anterior que só funciona para números.
madeira :: Ord a => [a] -> [a]
madeira l = madeira (qs l)
where
madeira [] = []
madeira [x] = [x]
madeira (h1:h2:t) = if h1==h2 then madeira (h2:t) else h1:(madeira(h2:t))
qs::Ord a => [a] -> [a]
qs [] = []
qs (h:t)= let (a,b) = part h t in (qs a)++[h]++(qs b)
part x [] = ([],[])
part x (h:t) = let (a,b)= part x t in
if h<x then(h:a,b) else (a, h:b)-}
--
--23
dell::Eq a => a -> [a] ->[a]
dell _ [] = []
dell x (h:t) =
if x==h then t
else h:(dell x t)
--24
slashy:: Eq a=> [a] -> [a] -> [a]
slashy [] [] = []
slashy l [] = l
slashy [] _ = []
slashy (h:t) (p:f) =
if p==h then slashy t f
else comb (t) (p:f) h (f)
where
comb :: Eq a => [a] -> [a] -> a -> [a] -> [a]
comb l1 l2 x [] = x:slashy l1 l2
comb l1 l2 x (p:f) =
if x==p then slashy l1 (delAll p (l2))
else comb l1 l2 x f
delAll _ [] = []
delAll x (h:t) =
if x==h then delAll x t
else h:(delAll x t)
--25
union' :: Eq a => [a] -> [a] -> [a]
union' [] [] = []
union' [] l = l
union' l [] = l
union' (h:t) (p:f)
|elem p (h:t) = union' (h:t) f
|otherwise = (union' (h:t) f)++[p]
type Mset a = [(a,Int)]
--26
isect :: Eq a => [a] -> [a] -> [a]
isect _ [] = []
isect [] _ = []
isect (h:t) (p:f)
|elem h (p:f) = h:isect t (p:f)
|otherwise = isect t (p:f)
--27
insert' :: Ord a => a -> [a] -> [a]
insert' a [] = [a]
insert' a (h:t) =
if a > h then h:insert' a t
else a:h:t
--28
maxi :: Ord a => [a] -> a
maxi [h] = h
maxi (h1:h2:t)
|h1>h2 = maxi(h1:t)
|otherwise = maxi(h2:t)
--29
minnie :: Ord a => [a] -> a
minnie [h] = h
minnie (h1:h2:t)
|h1<h2 = minnie(h1:t)
|otherwise = minnie(h2:t)
--30
sum' :: Num a => [a] -> a
sum' [x]=x
sum' (h:t) = h+sum'(t)
--31
prod' :: Num a => [a] -> a
prod' [x]=x
prod' (h:t) = h*prod' t
--32
hand :: [Bool]->Bool
hand [] = True
hand (h1:t) = h1 && hand t
--33
ore :: [Bool]->Bool
ore [] = False
ore (h:t) = h || ore t
--34
unword :: [String] -> String
unword [] = []
unword (h:t) = h ++ " " ++ (unword t)
--35
unline :: [String] -> String
unline [] = []
unline (h:t) = h ++ ['n'] ++ (unline t)
--36
pM :: Ord a => [a] -> Int
pM (h:t) = contagem (mai(h:t)) (h:t) 0
where
mai [h] = h
mai(h1:h2:t) = if h1 < h2 then mai(h2:t) else mai(h1:t)
contagem x (h:t) c =
if x==h
then c
else contagem x t (c+1)
--37
reprep :: Eq a => [a] -> Bool
reprep [] = False
reprep (h:t)
|elem h t = True
|otherwise = reprep t
--38
alga :: String -> String
alga [] = []
alga (h:t) = if isDigit h then h:alga t else alga t
--39
pozimp :: [a]->[a]
pozimp [_] = []
pozimp (h:t) = aux 0 (h:t)
where
aux c [] = []
aux c (h:t) =
if mod c 2 == 0
then aux (c+1) (t)
else h:(aux (c+1) (t))
--40
pozpar :: [a]->[a]
pozpar [a] = []
pozpar (h:t) = aux 0 (h:t)
where
aux c [] = []
aux c (h:t) =
if mod c 2 /= 0
then aux (c+1) (t)
else h:(aux (c+1) (t))
--41
isSorte :: Ord a => [a] -> Bool
isSorte [a] = True
isSorte (h1:h2:t) = h2 > h1 && isSorte (h2:t)
--42
aiSorte :: Ord a => [a] -> [a]
aiSorte [a] = [a]
aiSorte (h:t)= insert' h (aiSorte t)
--43
menordic :: String -> String -> Bool
menordic [] [] = True
menordic [] l = False
menordic (h:t) (p:f)
|isAlpha h && isAlpha p && (ord h)<(ord p) = True
|isAlpha h && isAlpha p && (ord h)==(ord p) = menordic t f
|isAlpha h && isAlpha p && (ord h)>(ord p) = False
--44
elemMset' :: Eq a => a -> Mset a -> Bool
elemMset' x [] = False
elemMset' x ((a,b):t) = x == a || elemMset' x t
--45
lengthMset' :: Mset a -> Int
lengthMset' [(a,b)] = b
lengthMset' ((a,b):t) = b + lengthMset' t
--46
convset :: Mset a -> [a]
convset [] = []
convset ((a,0):t) = convset t
convset ((a,b):t)= a:convset ((a,b-1):t)
--47
inset :: Eq a => a -> Mset a -> Mset a
inset x [] = [(x,1)]
inset x ((a,b):t) =
if x==a then ((a,b+1):t) else (a,b):(inset x t)
--48
{-(Assumindo que remset x (lista)
vai remover apenas uma instância do elemento x na lista e não todas)-}
remset :: Eq a => a -> Mset a -> Mset a
remset x [] = []
remset x ((a,b):t)
| x==a && (b-1)==0 = t
| x==a = ((a,b-1):t)
|otherwise = (a,b):(remset x t)
{-(Assumindo que remset x (lista)
vai remover todas as instâncias de x na lista)-}
remset2 :: Eq a => a -> Mset a -> Mset a
remset2 x [] = []
remset2 x ((a,b):t)
| x==a = t
|otherwise = (a,b):(remset2 x t)
--49
buildset :: Ord a => [a] -> [(a,Int)]
buildset [] = []
buildset (h:t) = ((h,contar h (h:t)):buildset (delall h t))
where
contar _ [] = 0
contar x (h:t) =
if x==h then 1+ contar x t
else contar x t
delall _ [] = []
delall x (h:t)=
if x==h then delall x t
else h:delall x t
--50
sumpar :: [Int] -> Int
sumpar [h] = h
sumpar (h:t) =
if mod h 2 == 0 then h+sumpar t
else sumpar t
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team