Post FizzBuzz in your language of choice
>"Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”."
OP:class FizzBuzz
{
public static void main(String... c)
{
for(int i = 1; i < 101; i++)
{
System.out.println((i % 15 == 0) ? "FizzBuzz" :
((i % 3 == 0) ? "Buzz" :
((i % 5 == 0) ? "Fizz" : i)));
}
}
}
>>58244392### Functions ###
range = $(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)
### Variables ###
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)))))
### Target ###
.PHONY: all
all: ; $(info $(fizzbuzz))
>>58244392for i in 1...100 {
if i % 15 == 0 {
print("FizzBuzz")
} else if i % 5 == 0 {
print("Buzz")
}else if i % 3 == 0 {
print("Fizz")
}
else {
print(i)
}
}
main = putStrLn (show (fb [1..100]))
fb:: (Show a, Integral a) => [a] -> [[Char]]
fb [] = []
fb (a:as)
| mod a 15 == 0 = "FizzBuzz" : fb as
| mod a 3 == 0 = "Fizz" : fb as
| mod a 5 == 0 = "Buzz" : fb as
| otherwise = (show a) : fb as
Just started learning haskell, how did I do
Here's my implementation in VB.NET
>>58245579
>uses >3 MB of memory
Perfect
>>58244392
OMG MATH.
for (int i = 1; i <= 100; i++)
{
string fizzBuzz = "";
if ((i % 3) == 0) fizzBuzz = "Fizz";
if ((i % 5) == 0) fizzBuzz += "Buzz";
if (string.IsNullOrEmpty(fizzBuzz)) fizzBuzz = i.ToString();
Console.WriteLine(fizzBuzz);
}
>>58244392(1..100).each do |number|
case
when number % 15 == 0 then puts 'FizzBuzz'
when number % 3 == 0 then puts 'Fizz'
when number % 5 == 0 then puts 'Buzz'
else puts number
end
end
>>58245643
Hi Pajeet!
fizzbuzz = sequence [putStrLn x | x <- map f [1..100]]
where
f x | x `mod` 15 == 0 = "FizzBuzz"
| x `mod` 3 == 0 = "Fizz"
| x `mod` 5 == 0 = "Buzz"
| otherwise = show x
threes = {*range(3,100,3)}
fives = {*range(5,100,5)}
fizz = [[x,"fizz"] for x in threes - fives]
buzz = [[x,"buzz"] for x in fives - threes]
fizzbuzz = [[x,"fizzbuzz"] for x in fives & threes]
remainders = [[x,x] for x in {*range(100)} - threes - fives]
comp = fizz + buzz + fizzbuzz + remainders
print("\n".join((str(i) for _, i in sorted(comp))))
> }. (<'FizzBuzz') (I.0=15|n)} (<'Buzz') (I.0=5|n)} (<'Fizz') (I.0=3|n)} ":&.> n=: i.101
>>58245656
>>58246669
>>58246885
wtf is this even
looks like some PLC graphical abomination
vimLfu! Fizzbuzz()
let @q = "yyp\<C-a>"
let @w = "0CFizz\<C-[>3j"
let @e = "ABuzz\<C-[>5j"
exe "norm! i1\<C-[>99@q3G33@w5G20@e"
exe "norm! :%s/\\d*\\zeB\<C-m>"
endf
import >>58244598
>>58246905
Prograph. Found it in an abandonware repository. It's actually a pretty interesting language from the 90s.
>>58246964
Interesting.
Will have to read up more on that.
How do you guys have time to think of all these retarded ways?
#include <iostream>
class FizzBuzz {
public:
FizzBuzz (int begin, int end);
bool operator () ();
void print (std::ostream &os) const;
private:
int _begin;
int _end;
int _current;
};
inline FizzBuzz::FizzBuzz (int begin, int end)
: _begin (begin)
, _end (end)
, _current (begin - 1) {}
inline bool FizzBuzz::operator () () {
return ++_current <= _end;
}
inline void FizzBuzz::print (std::ostream &os) const {
if (_current % 15 == 0) {
os << "fizzbuzz";
} else if (_current % 5 == 0) {
os << "buzz";
} else if (_current % 3 == 0) {
os << "fizz";
} else {
os << _current;
}
}
std::ostream &operator << (std::ostream &os, const FizzBuzz &fb) {
fb.print (os);
return os;
}
int main () {
FizzBuzz fb (1, 100);
while (fb ()) {
std::cout << fb << std::endl;
}
return 0;
}