|
|
|
|
|
|
|
|
printInt (alternatingSum 100) |
|
|
printInt (alternatingSum 100) |
|
|
|
|
|
|
|
|
// Now we can factor out the commonality and re-write these functions like so: |
|
|
// Now we can factor out the commonality and re-write these functions like so: |
|
|
|
|
|
|
|
|
let iterAct ini act n = |
|
|
let iterAct ini act n = |
|
|
[1..n] |> List.fold act ini |
|
|
[1..n] |> List.fold act ini |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let sumOfOdds2 = iterAct 0 (fun x y -> if y % 2 = 0 then x else x + y) |
|
|
let sumOfOdds2 = iterAct 0 (fun x y -> if y % 2 = 0 then x else x + y) |
|
|
printInt (sumOfOdds2 10) |
|
|
printInt (sumOfOdds2 10) |
|
|
|
|
|
|