DEV Community

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

Posted on

2

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)

Warp.dev image

Warp is the #1 coding agent.

Warp outperforms every other coding agent on the market, and gives you full control over which model you use. Get started now for free, or upgrade and unlock 2.5x AI credits on Warp's paid plans.

Download Warp

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay