Skip to content

Instantly share code, notes, and snippets.

@pgburt
Last active February 29, 2016 22:25
Show Gist options
  • Save pgburt/aea4e58db6b311e91a9b to your computer and use it in GitHub Desktop.
Save pgburt/aea4e58db6b311e91a9b to your computer and use it in GitHub Desktop.
Now reading from the payload file
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