DEV Community

Cover image for Code Your Way: BadaBing!
dev.to staff for The DEV Team

Posted on

Code Your Way: BadaBing!

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)

Collapse
 
siddharthshyniben profile image
Siddharth

Golfed it! 63 bytes.

for(i=0;++i<101;console.log(i%5?f||i:f+'Bing.'))f=i%3?'':'Bada'
Enter fullscreen mode Exit fullscreen mode

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.

Collapse
 
namenotavilable profile image
Adam Markiewicz

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)