Last active
February 29, 2016 22:25
-
-
Save pgburt/aea4e58db6b311e91a9b to your computer and use it in GitHub Desktop.
Now reading from the payload file
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
package main | |
import ( | |
"fmt" | |
"math" | |
"math/big" | |
"github.com/iron-io/iron_go/worker" | |
) | |
func CalcNumerator(num int) int64 { | |
odd := math.Mod(float64(num), 2) | |
if (odd == 1) { | |
return -1 | |
} | |
return 1 // otherwise, it's even | |
} | |
type RangeToCalc struct { | |
Begin int | |
End int | |
} | |
func main() { | |
sum := big.NewRat(0, 1) | |
worker.ParseFlags() | |
r := &RangeToCalc{} | |
worker.PayloadFromJSON(r) | |
for i := r.Begin; i <= r.End; i++ { | |
leibnizNum := CalcNumerator(i) | |
leibnizDen := int64(2 * i + 1) | |
leibnizRat := big.NewRat(leibnizNum, leibnizDen) | |
sum.Add(sum, leibnizRat) | |
// fmt.Println("run number is: ", n) | |
// fmt.Println("sum is: ", sum) | |
} | |
fmt.Println("Final sum is: ", sum) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment