add ghc haskell and go version for e2

This commit is contained in:
Dan Ballard 2014-08-20 23:10:58 -07:00
parent 9e2179f2d8
commit bb6dc490ca
2 changed files with 20 additions and 0 deletions

5
e2/e2.ghc.hs Normal file
View File

@ -0,0 +1,5 @@
fibsum prev curr acc max | curr > max = acc
| rem curr 2 == 0 = fibsum curr (prev + curr) (acc + curr) max
| otherwise = fibsum curr (prev + curr) acc max
main = print (fibsum 1 1 0 4000000)

15
e2/e2.go Normal file
View File

@ -0,0 +1,15 @@
package main
import (
"fmt"
)
func main() {
sum := 0
for prev, curr := 1, 1; curr <= 4000000; prev, curr = curr, prev+curr {
if curr%2 == 0 {
sum += curr
}
}
fmt.Println(sum)
}