bool m3 = !(i % 3);
bool m5 = !(i % 5);
if (m3) printf("Fizz");
if (m5) printf("Buzz");
if (m3 || m5) printf("\n");
You can turn in your visitor badge at the front desk, and they'll call you an Uber.I'll call my own Uber, thanks
With C, any claim one makes about repeatability is always wrong at some point depending on the version compliance.
I like C, but Haskell is a happy optimistic syntax... Julia is probably the language I'd wager becoming more relevant as Moore's laws corpse begins to stink. =3
n `mod` 3 == 0 && n `mod` 5 == 0
And you have if (m3 || m5)
I really don't see what point you're trying to make here...they saying its unnecessary because if you go in order you first print "fizz", then print "buzz" which will always print "fizz buzz" for the equivalent of " mod 15" you don't need a special string that like.
the "if (m3 || m5)" is just printing a newline because under that condition you printed something earlier.
I've always liked this solutiin, which avoids that: https://archive.is/KJ39B
fizzbuzz i =
fromMaybe (show i) . mconcat $
[ "fizz" <$ guard (i `rem` 3 == 0)
, "buzz" <$ guard (i `rem` 5 == 0)
]
main =
for_ [1..100] $
putStrLn . fizzbuzz
This allows you to add special prints by adding just the one line of code, changing nothing else.Phrasing the question in a way that doesn't leave room for that insight is also a pretty big goof.
As for AI, yes, FizzBuzz is trivial for any model because it's so well-represented in the training data. The common benchmarks involve things like "Render a physically-correct bouncing ball inside a rotating hexagon," or something else that is too complex to simply regurgitate.
The article also features examples of point-free style, another unfortunate trend for readability.
As long as you use operators sparingly, don’t abuse partial application and prefer explicit lambdas to composition, Haskell is fairly readable. The issue is that approximately no Haskeller writes Haskell this way.
(For example, (\x -> x ++ y) and (\y -> x ++ y) look pretty similar to me at first glance, but (++y) and (x++) are immediately distinguishable.)
Of course, this is reliant on knowing the operators but that seems like a mostly orthogonal issue to me: You still need to know the operator in the lambda expression. That said, the niceness of sections gives people yet another reason to introduce operators for their stuff when arguably they already are too prevalent.
It is also an operator, meaning it can be used with infix notation, as in (x : xs). Haskell has something called operator sections, where if one supplies only one of the arguments to an operator it will return a function expecting the other argument. In other words
(x:) == \xs -> (x:xs)
and (:xs) == \x -> (x:xs)
This can be used as in this article, to create a function that prepends x to any list. Another common example is (1+) which increments any number it is given, or (:[]) which turns any value into a one-element list.It can also be used much more cleverly -- especially considering that any two-argument function can be turned into an operator with backticks -- but then (in my opinion) readability starts to suffer.