Can you beat our solutions for the raindrops exercise?

Cleanest, fastest so far (aside from using an if tree with literal values).

function raindrops(n)
    (f3 = n % 3 == 0) && (s = "Pling")
    (f5 = n % 5 == 0) && (s = f3 ? "PlingPlang" : "Plang")
    (f7 = n % 7 == 0) && (s = f3 | f5 ? string(s, "Plong") : "Plong")
    return f3 | f5 | f7 ? s : string(n)
end

Thank you @malacroi and @MatFi for your creative solutions!

4 Likes