Which Generation Are You?

Published by BijogFc24 in

Try finding your ancestors and offspring with code.

Create a function that takes a number x and a character y ("m" for male, "f" for female), and returns the name of an ancestor (m/f) or descendant (m/f).

  • If the number is negative, return the related ancestor.
  • If positive, return the related descendant.
  • You are generation 0. In the case of 0 (male or female), return "me!".

Examples

generation(2, "f") ➞ "granddaughter"

generation(-3, "m") ➞ "great grandfather"

generation(1, "f") ➞ "daughter"

Notes

Check the Resources tab for helpful hints.

GenerationMaleFemale
-3great grandfathergreat grandmother
-2grandfathergrandmother
-1fathermother
0me!me!
1sondaughter
2grandsongranddaughter
3great grandsongreat granddaughter
Watch a quick demo on how Edabit works.