mut_recurs.go 542 B

123456789101112131415161718192021222324252627
  1. // mut_recurs.go
  2. package main
  3. import (
  4. "fmt"
  5. )
  6. func main() {
  7. fmt.Printf("%d is even: is %t\n", 16, even(16)) // 16 is even: is true
  8. fmt.Printf("%d is odd: is %t\n", 17, odd(17)) // 17 is odd: is true
  9. fmt.Printf("%d is odd: is %t\n", 18, odd(18)) // 18 is odd: is false
  10. }
  11. func even(nr int) bool {
  12. if nr == 0 {return true}
  13. return odd(RevSign(nr)-1)
  14. }
  15. func odd(nr int) bool {
  16. if nr == 0 {return false}
  17. return even(RevSign(nr)-1)
  18. }
  19. func RevSign(nr int) int {
  20. if nr < 0 {return -nr}
  21. return nr
  22. }