Richard Bucker

A Formula for the Number of Days in Each Month

Posted at — Dec 17, 2014
Here is the function in go:

package main

import (
"fmt"
"math"
)

// ref: http://cmcenroe.me/2014/12/05/days-in-month-formula.html
func f(x float64) float64 {
return 28 + math.Mod((x+math.Floor(x/8)), 2) + math.Mod(2, x) + 2*math.Floor(1/x)
}
func main() {
fmt.Println("Hello, playground")
for i := 1; i < 13; i++ {
fmt.Println(i, f(float64(i)))
}
}


The code is here if you want to run it now.