Re:Fizz Buzz in Tensorflow (2016)
by kahlonel on Monday February 12, 2018 @01:04PM
(#16360468)
Here is a C version of fizzbuzz if anyone has an interview tomorrow:
[ Parent
| on HN ]
This is the shortest non-clever version I can come up with:
#include <stdio.h>
int main(void)
{
int i;
for (i = 1; i <= 100; i++) {
if ((i % 3) == 0) {
printf("Fizz");
}
if ((i % 5) == 0) {
printf("Buzz");
}
if ((i % 3) && (i % 5)) {
printf("%d", i);
}
puts("");
}
return 0;
}
Re:Fizz Buzz in Tensorflow (2016)
by geraldbauer on Monday February 12, 2018 @04:28PM
(#16362398)
Here's the short ruby version from code golfing in 54 bytes:
def fizzbuzz (1..100).map{|n|["%sBuzz"%x=["Fizz"][n%3]][n%5]||x||n} end
puts fizzbuzz.join
Re:Fizz Buzz in Tensorflow (2016)
by strong_silent_t on Monday February 12, 2018 @02:09PM
(#16361079)
Everytime this question comes up I am powerless to resist re-implementing it.
#include <stdio.h>
int main() {
int i;
for (i = 1; i < 101; i++) {
int div3 = 0 == i % 3;
int div5 = 0 == i % 5;
if (div3 || div5) {
printf("%s%s\n",
div3 ? "fizz" : "",
div5 ? "buzz" : "");
} else {
printf("%d\n", i);
}
}
return 0;
}
I will admit, it took me 4 tries to get this to compile.And now, in VBA:
Sub Main()
Dim i As Integer
For i = 1 To 100
Dim f As Integer
f = IIf(i Mod 3, 0, 1) Or IIf(i Mod 5, 0, 2)
Dim buf As String
If f = 0 Then
buf = Format(i)
Else
buf = IIf(f And 1, "fizz", "") + IIf(f And 2, "buzz", "")
End If
Debug.Print buf
Next i
End Sub