[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

FizzBuzz

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 29
Thread images: 11

File: OjVonSO.jpg (174KB, 750x563px) Image search: [Google]
OjVonSO.jpg
174KB, 750x563px
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))
>>
>>58244392
for 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)
}
}
>>
File: visualstudio.jpg (79KB, 1554x663px) Image search: [Google]
visualstudio.jpg
79KB, 1554x663px
>>
File: fizz_my_buzz.jpg (90KB, 948x902px) Image search: [Google]
fizz_my_buzz.jpg
90KB, 948x902px
>>
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
>>
File: vbnet.png (49KB, 637x582px) Image search: [Google]
vbnet.png
49KB, 637x582px
Here's my implementation in VB.NET
>>
File: FizzBuzz LogicSim.gif (2MB, 585x454px) Image search: [Google]
FizzBuzz LogicSim.gif
2MB, 585x454px
>>
File: FizzBuzz.gif (489KB, 341x678px) Image search: [Google]
FizzBuzz.gif
489KB, 341x678px
>>
>>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!
>>
File: FizzBuzz.png (21KB, 568x239px) Image search: [Google]
FizzBuzz.png
21KB, 568x239px
>>
File: FizzBuzz Machine code.png (74KB, 1089x757px) Image search: [Google]
FizzBuzz Machine code.png
74KB, 1089x757px
>>
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
>>
File: FizzBuzz.webm (1MB, 1532x716px) Image search: [Google]
FizzBuzz.webm
1MB, 1532x716px
>>
>>
File: 151465539873788.gif (1MB, 400x275px)
151465539873788.gif
1MB, 400x275px
>>58245656
>>58246669
>>
>>58246885
wtf is this even
looks like some PLC graphical abomination
>>
vimL
fu! 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;
}
Thread posts: 29
Thread images: 11


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.