package main // 参考文章: // https://github.com/Unknwon/the-way-to-go_ZH_CN/blob/master/eBook/06.6.md import ( "fmt" ) func main () { fmt.Printf("%d is even: is %t\n", 16, even(16)) // 16 is even is true fmt.Printf("%d is odd: is %t\n", 17, odd(17)) // 17 is odd: is true fmt.Printf("%d is odd: is %t\n", 18, odd(18)) // 18 is odd: is false } func even( nr int) bool { if nr == 0 { return true } return odd(RevSign(nr) - 1) } func odd(nr int) bool { if nr == 0 { return false } return even(RevSign(nr) - 1) } func RevSign(nr int) int { if nr < 0 { return -nr } return nr }
原文:http://www.cnblogs.com/zengjfgit/p/4986319.html