This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Takes an array of integers, and adds pairs of numbers to create a new | |
-- array. For example, [1,2,3,4] changes to [(1+2), (2+3), (3+4)], resulting | |
-- in [3,5,7] | |
sumOfPairs :: [Integer] -> [Integer] | |
sumOfPairs [] = [] | |
sumOfPairs (x:[]) = [] | |
sumOfPairs (x:y:ys) = (x+y) : sumOfPairs (y:ys) | |
-- Given a row of Pascal's triangle, returns the next row |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Index based list operations using folds | |
-- | |
-- Author: Umair Saeed | |
-- Date: 05/17/2015 | |
-- | |
-- insert at an index, implemented via foldr | |
insertAt :: a -> [a] -> Int -> [a] | |
insertAt x ys n = foldr insertHelper [] $ zip [0..] ys | |
where |
NewerOlder