The Red/Yellow Sequence

Published by Matt in

Write a function that takes a number n and a string s as arguments and returns the nth term of the Red/Yellow sequence. s will ask the function what to return, all, red or yellow.

alt text

Examples

ry_seq(2, "all") ➞ 5

ry_seq(3, "yellow") ➞ 8

ry_seq(28, "red") ➞ 55

ry_seq(1, "blue") ➞ false

Notes

  • If s is not "all", "yellow" or "red", return false.
  • If n is 0, return 0.
  • n is always a positive integer.
Watch a quick demo on how Edabit works.