Fizzbuzz thread. In the language of your choice write a program that prints "fizz" for multiples of 3, "buzz" for multiples of 5, "fizzbuzz" for multiples of both, and the number for multiples of neither.<?php
foreach(range(1,100) as $number){
if($number % 15 == 0){
echo("fizzbuzz\r\n");
}
elseif($number % 3 == 0){
echo("fizz\r\n");
}
elseif($number % 5 == 0){
echo("buzz\r\n");
}
elseif($number % 5!== 0 && $number % 15!==0 && $number % 3!==0){
echo("$number\r\n");
}
}
?>
puts (1..100).map { |i| (fb = [["Fizz"][i % 3], ["Buzz"][i % 5]].compact.join).empty? ? i : fb }
>>55418341main = do
let x = concat [if x `mod` 15 == 0 then "fizzBuzz!\n"
else if x `mod` 5 == 0 then "Buzz!\n"
else if x `mod` 3 == 0 then "fizz!\n"
else show x ++ "\n" | x <- [1..]]
putStrLn x
>>55418480
1/10 for technically solving the problem
>>55418341public final class FizzBuzz {
public static void main(String[] args) {
for(int i = 0; i <= 100; i++) {
if (i % 15 == 0) {
System.out.println("FizzBuzz");
} else if (i % 3 == 0) {
System.out.println("Fizz");
} else if (i % 5 == 0) {
System.out.println("Buzz");
} else {
System.out.println(i);
}
}
}
}
>>55418405
what the shitting dick nipple is this
>>55418623
Ruby. Just started using it this year and it's been fun. Coming from a C++/c#/Java background, it's a fresh breath of weirdly pleasing air.
>>55418480
>>55418544
>using an extra modulo instead of reusing the results of the two orhet modulo
I get that you're trying to be clever by using a more "mathematical" approach but that you're actually doing is sacrificing basic logic and using a lot of extra CPU cycles
You are wasting so many CPU cycles
>>55418341for(let i = 1; i <= 100; ++i) {
let x = '';
if (i % 3)
x += 'fizz';
if (i % 5)
x += 'buzz';
console.log(x || i);
}
>>55418799
go away evil dogger.
for n in range(1, 101):
if n % 15 == 0:
print "FizzBuzz"
elif n % 3 == 0:
print "Fizz"
elif n % 5 == 0:
print "Buzz"
else:
print n
raw_input()
How shitty is my code?
>>55418819
Not as shitty as OP's so you're fine.
>>55418799
Oops, forgot to check the modulo result. Both if statements should beif (i % 3|5 === 0)
Or I suppose this would work tooif (!(i % 3|5))
>>55418819
Fine other than using input at the end and using python 2 instead of 3.
>>55418510
>>55418666
Alright smartasses, how would you do it then?
int n = 0;
bool printed;
while (n < 100)
{
fizzed = false;
if (!(n % 3)) printf("Fizz"); printed = true;
if (!(n % 5)) printf("Buzz"); printed = true;
if (!printed) printf("%i, ", n);
++n;
}
coming for your jobs
let rec f n s =
if n > 100
then print_string s
else f (n+1) (s ^ (
if (n mod 15) = 0
then "fizzbuzz\r\n"
else
if (n mod 3) = 0
then "fizz\r\n"
else
if (n mod 5) = 0
then "buzz\r\n"
else (string_of_int n) ^ "\r\n"
))
in
f 0 ""
niggers
>>55419355
>printed is not used
>fizzed is not defined
>>55419407
>\r\n
Might as well double click fizzBuzz.exe at this point, pajeet.
>>55419429
What's wrong with using \r\n?
>>55419412
"fizzed" is supposed to be "printed" but brainfart
program fizzbuzz;
var
i:integer;
begin
for i:=1 to 100 do
begin
if (i mod 3=0) and (i mod 5=0) then
writeln('FizzBuzz')
else if (i mod 5=0) then
writeln('Buzz')
else if (i mod 3=0) then
writeln('Fizz')
else
writeln(i);
end;
end.
>>55418341
>>55418341for(i=0;i++<100;)console.log((i%3?'':"fizz")+(i%5?'':'buzz')||i)
class FizzBuzzCommandlet extends Commandlet;
event int Main(string Parms)
{
local int i;
local string S;
while(i++ < 100)
{
S = "";
if(i % 3 == 0)
S $= "Fizz";
if(i % 5 == 0)
S $= "Buzz";
Log(Eval(S=="",i,S));
}
return 0;
}
##FizzBuzz
for num in xrange(1,101):
msg = ''
if num % 3 == 0:
msg += 'Fizz'
if num % 5 == 0:
msg += 'Buzz'
print msg or num
private static void fizzBuzz(int length)
{
IntStream.range(1, length).forEach(i ->
{
String s = "";
if (i % 3 == 0) s += "Fizz";
if (i % 5 == 0) s += "Buzz";
if (s.isEmpty()) s += String.valueOf(i);
System.out.println(s);
});
}
>>55418341
ok<!DOCTYPE html>
<html>
<body>
<script>for (var i = 1; i < 101; i++) {document.body.innerHTML += '<div>' + i + '</div>'}; document.querySelectorAll('script')[0].remove()</script>
<style>
div:nth-child(3n):before{content: "Fizz"}
div:nth-child(5n):after{content: "Buzz"}
div:nth-child(3n):before, div:nth-child(5n):after{font-size: initial}
div:nth-child(3n), div:nth-child(5n){font-size: 0}
div{font-family: Helvetica; font-weight: 300}
</style>
</body>
</html>
Works in chromium
>>55424698
Good work, Daniel
how about the weirdest language you can code on huh?
>inb4 that fag that posts a solution with tensorflow
>>55424728IDENTIFICATION DIVISION.
PROGRAM-ID. FIZZBUZZ.
DATA DIVISION.
01 CUNT PIC 9(3) VALUE 001.
01 REMAINDER PIC 9(3) VALUE 000.
01 FIZZ PIC A(4) VALUE "FIZZ".
01 BUZZ PIC A(4) VALUE "BUZZ".
PROCEDURE DIVISION.
A-PARA.
PERFORM B-PARA UNTIL CUNT>100.
STOP RUN.
B-PARA.
COMPUTE REMAINDER = FUNCTION MOD (CUNT,3).
IF REMAINDER EQUALS 0
DISPLAY FIZZ
COMPUTE REMAINDER = FUNCTION MOD (CUNT,5)
IF REMAINDER EQUALS 0
DISPLAY BUZZ
COMPUTE REMAINDER = FUNCTION MOD (CUNT,15)
IF REMAINDER EQUALS 0
DISPLAY FIZZ + BUZZ
Only took one uni course like 3 years ago and haven't touched it since. I doubt this will compile because I wrote it on my phone and the alignment will be off aside from other issues.
>>55424939
Forgot the increment... shit
fn main() {
for i in 1..102 {
if i % 15 == 0 { println!("FizzBuzz") }
else if i % 3 == 0 { println!("Fizz") }
else if i % 5 == 0 { println!("Buzz") }
else { println!("{}", i) }
}
}
>>55424698
ok i improved this so now it's actually stable<!DOCTYPE html>
<html>
<body>
<style>body{counter-reset: item;list-style-type: none;}
div{counter-increment: item}
div:not(:nth-of-type(3n)):not(:nth-of-type(5n)):before{content: counter(item) ""}
div:nth-of-type(3n):before{content: "Fizz"}
div:nth-of-type(5n):after{content: "Buzz"}
div{font-family: Helvetica; font-weight: 300}</style>
<script>for (var i=0;i<100;i++) {document.body.innerHTML += '<div></div>'}</script>
</body>
</html>
for i in range(1,101): print "FizzBuzz"[i*i%3*4:8--i**4%5] or i
fite me
>>55425348
>look mom, I posted it again
I'VE PREPARED FOR THIS THREAD IN ADVANCE
Too lazy to rewrite my C version to not do a "% 15" check, so I'm posting the edgy Python version I cooked up with a boolean flag.for i in range(1,101):
divisorFound = False
if i % 3 == 0:
# Prevent default behavior of automatically printing of newline
print("Fizz", end="")
divisorFound = True
if i % 5 == 0:
print("Buzz", end="")
divisorFound = True
if divisorFound == False:
print(i, end="")
# Print newline after falling through all cases
print("\n", end="")
#include <stdio.h>
int main(int i)
{
char *s[] = {"%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n"};
for (i=0; i++ < 100;)
printf(s[!(i % 3) + (!(i % 5) * 2)], i);
return 0;
}
>>55424033
What language is this?
>>55425903
Forgot to mention I indent with only two spaces because I am a masochist
>>55424592
clever use of s.isEmpty(), like it
>>55425905
really fucking clever minimalist approach
fn main() {
for i in 1..101 {
if (i % 3 == 0) && (i % 5 == 0) { println!("FizzBuzz") }
else if i % 3 == 0 { println!("Fizz") }
else if i % 5 == 0 { println!("Buzz") }
else { println!("{}", i) }
}
}
is this good enough to get me a job at google as a diversity officer?
Guess the languagerange = $(if $(filter $1,$(lastword $3)),$3,$(call range,$1,$2,$3 $(words $3)))
make_range = $(foreach i,$(call range,$1),$(call range,$2))
equal = $(if $(filter-out $1,$2),,$1)
limit := 101
numbers := $(wordlist 2,$(limit),$(call range,$(limit)))
threes := $(wordlist 2,$(limit),$(call make_range,$(limit),2))
fives := $(wordlist 2,$(limit),$(call make_range,$(limit),4))
fizzbuzz := $(foreach v,$(numbers),\
$(if $(and $(call equal,0,$(word $(v),$(threes))),$(call equal,0,$(word $(v),$(fives)))),FizzBuzz,\
$(if $(call equal,0,$(word $(v),$(threes))),Fizz,\
$(if $(call equal,0,$(word $(v),$(fives))),Buzz,$(v)))))
.PHONY: all
all: ; $(info $(fizzbuzz))
fizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzzfizzbuzz
>>55426582
web assembly
>>55419355int n = 0;
bool printed;
while (n < 100)
{
fizzed = false;
if (!(n % 3)) {
printf("Fizz");
}
printed = true;
if (!(n % 5)) {
printf("Buzz");
}
printed = true;
if (!printed) {
printf("%i, ", n);
}
++n;
}
You dun goofed
[...Array(100).keys()].map(function(a){return a+1}).map(function(a){return 0===a%3&&0===a%5?"fizzbuzz":0===a%3?"fizz":0===a%5?"buzz":a})