Hey there, you've happened upon Code Your Way: Quick Challenges in Every Language! Every week, we throw down a new programming challenge that you can take on in any language you like. It doesn't matter if you're a coding ninja or a newbie, these challenges are perfect for taking a break, sharpening your skills, pushing yourself, and learning new tricks. So, grab your go-to coding tools and let's dive in.
Today’s challenge is the BadaBing!
Write a program that prints numbers from 1 to 100, but for multiples of three, print "Bada" instead of the number and for multiples of five, print "Bing." For numbers that are multiples of both three and five, print "BadaBing."
Your goal is to complete this challenge in the most efficient way possible. You may want to time yourself. ⏰ 🏃🏻♂️ See you in the comments!
Top comments (2)
Golfed it! 63 bytes.
Surprisingly for me, golfing made the code more efficient! Takes about 3ms, sometimes 2.5, which is a big improvement from the 4ms for my non-golfed version.
for i in range(1, 101):
if i % 3 == 0 and i % 5 == 0:
print("BadaBing")
elif i % 3 == 0:
print("Bada")
elif i % 5 == 0:
print("Bing")
else:
print(i)