Please write a function or program that consecutively prints every positive integer, except that if a number contains or is divisible by 3, print "egg" instead of the number, if a number is divisible by 5, print "bug" instead of the number, and if both of these conditions hold, print "eggbug" instead of the number.
Example implementation in Swift, rebug to add your own example!
func eggbug(number: Int) -> String {
let numberString = String(number)
let isEgg = (number % 3 == 0) || numberString.contains("3")
let isBug = (number % 5 == 0)
if (isEgg && isBug) {
return "eggbug"
} else if (isEgg) {
return "egg"
} else if (isBug) {
return "bug"
} else {
return numberString
}
}
// do not run without setting an upper bound!
// or do, I'm not your mom
for i in 1... {
print(eggbug(number: i))
}
