#
#
⇲ Add the odd numbers between
sum [1,3..30]
225
:{
addOdd
:}
sum [1..21]
231
Create a list of square numbers
[(^2) x | x <- [1..10]]
[1,4,9,16,25,36,49,64,81,100]
or
map (^2) [1..10]
[1,4,9,16,25,36,49,64,81,100]
Sum the first ten square numbers
sum [(^2) x | x <- [1..10]]
385
triangular n = sum [1..n]
map triangular [1..10]
[1,3,6,10,15,21,28,36,45,55]
@@html:<span class=”fraktur”><script src=”https://gist.github.com/lattenwald/bc97a668641df7e77ef0.js”>@@ @@html:</script></span>@@
triangleNumsAlt = map (\i -> i * (i+1) `div` 2) [1..]
take 10 triangleNumsAlt
[1,3,6,10,15,21,28,36,45,55]
:{
triangleNums = map fst triangleNums'
where
triangleNums' = (1, 2) : map (\(n, i) -> (n+i, i+1)) triangleNums'
:}
take 10 triangleNums
[1,3,6,10,15,21,28,36,45,55]