WARNING: Awesome code follows
I just read there is a more accurate way to calculate a dog's age in human years than simply multiplying by 7 (which does produce a lot of oddities, especially when it comes to dogs giving birth at "7" years old lol). The progression through the first, second and then subsequent years are handled in a manner that is much closer to how dogs typically age compared to humans.
Here are #lisp and #python functions demonstrating the new calculations. Feel free to use them as you wish. Especially if you have one or more dogs.
Feel free to improve or comment on the code in the comments or elsewhere. I always post these kinds of functions for conversation and community, I'm just learning python, so don't bark too loudly.
The formats are:
(dogs-age years months)
and
dogs_age(years, months)
There is no error checking, so use zeros when necessary.
Don't be strangers. Shake a paw!
(defun dogs-age (years months)
"Calculate the human age equivalent of a dog given its age in years and months."
(let ((human-age 0))
(cond
((< years 1)
(setq human-age (* (/ months 12.0) 15)))
((= years 1)
(setq human-age (+ 15 (* (/ months 12.0) 9))))
((>= years 2)
(setq human-age (+ 15 9
(* (- years 2) 5)
(* (/ months 12.0) 5)))))
human-age))
def dogs_age(years, months):
"""
Calculate the human age equivalent of a dog given its age in years and months.
"""
if years < 1:
human_age = months * (15 / 12)
elif years == 1:
human_age = 15 + months * (9 / 12)
else:
human_age = 15 + 9 + (years - 2) * 5 + months * (5 / 12)
return human_age
Hey, @praetor you might be interestd in this, even if it isn't about cats. If you change the subsequent years from 5 to 4, it'll work for cats just the same, apparently. :ablobdj: