Haskell Noob

Tuesday, May 31, 2011

Sum of a list when boundry is given

sigma::Int->Int->Int
sigma x y = foldr(+) 0 (map (^2) [x..y])
Posted by sudantha at 10:53 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Reverse a list using recursion and inbuilt libraries

reversep::[a]->[a]
reversep []=[]
reversep( x:xs) = reverse xs ++ [x]
Posted by sudantha at 9:35 AM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Monday, May 30, 2011

Reverse a List

rev::[Int]->[Int]
rev (x:xs) = reverse (x:xs)
Posted by sudantha at 12:54 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Factorial using recursion

fact::Int->Int
fact 0 =1
fact x | x >0 = x * fact (x-1)

Posted by sudantha at 12:51 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Length of a list using length function

--Q4
lgn::[Int]->Int
lgn [] =0
lgn xs = length xs

Posted by sudantha at 12:27 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

nth Element of a List

kElem::[Int]->Int->Int
kElem (x:xs) n = xs !! n-x
Posted by sudantha at 12:17 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

Last Element -1 of a List

nElm::[Int]->Int
nElm [x]=x
nElm (x:xs) = reverse xs !! 1
Posted by sudantha at 12:12 PM No comments:
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Older Posts Home
Subscribe to: Comments (Atom)

Followers

Blog Archive

  • ▼  2011 (10)
    • ▼  May (10)
      • Sum of a list when boundry is given
      • Reverse a list using recursion and inbuilt libraries
      • Reverse a List
      • Factorial using recursion
      • Length of a list using length function
      • nth Element of a List
      • Last Element -1 of a List
      • Last Element of a List [Recursion ]
      • Average of three integers
      • Average of a List

About Me

sudantha
View my complete profile
Simple theme. Powered by Blogger.