FIZZBUZZ

Let's get a classic Jow Forums thread going.
Show us your mad skills and post your best fizzbuzz!

# DRYBuzz
import sequtils
import strutils

type
Fzstc* = seq[tuple[prime:int, name:string]]

iterator fizzBuzz*(n:int, m: Fzstc): string =
var iTer = 1
while iTer

Attached: 1347558057643.gif (256x256, 80K)

what language is that?

nim

autist

function fizzbuzz(n)
mdl = [modulo3(i) = if i%3 == 0 "Fizz" end
modulo5(i) = if i%5 == 0 "Buzz" end
modulo7(i) = if i%7 == 0 "Woof" end]
for i = 1:n
msg = ""
for m = 1:length(mdl)
if mdl[m](i) != nothing
msg *= mdl[m](i)
end
end
if msg == ""
msg *= "$i"
end
println(msg)
end
end

Import fizzBuzz from "fizzbuzz"
Console.log(fizzBuzz())

when are they gonna make a programming language for non-autists and women
like "if you press the 'G' key, make the character jump" is way easier than this [(string)-,,':;()] shit

they make "coding" programs for children. Shit like scratch, where it's just blocks that snap into each other.

>there are people that actually think like this

Attached: 1364105109855.jpg (300x300, 65K)

>classic Jow Forums

More like /prog/ overflow from when they closed the text boards that just won't go away.

#include
using namespace std;

void fizzbuzz(int);

int main() {
fizzbuzz(100);
return 0;
}


void fizzbuzz(int MAXNUM){
for (int i = 1; i

very nice
>+ follows best practices
>+ looks clean
>- no comments though

easily readable, honestly the best solution that you would want to see in production. your bracket spacing isn't consistent (you put a space after main() but not after fizzbuzz() or for()) but that's minor.

No comments. For something this simple you obviously don't really need it, but if someone doesn't know what fizzbuzz is, you'll want a comment describing what it is.

as a side note, if you're concerned purely about performance, you're doing modulo at least three times. there is a way that's longer and not as "clean" looking, but it only does modulo twice. you'll also want to avoid the iostream library and do a print call only once if possible. print calls are very, very slow.

>you'll also want to avoid the iostream library and do a print call
how can I print to the console without the iostream library? Isn't it required for cout?

class FizzBuzzNumberFactory:

def __init__(self, n):
if n % 15 == 0:
self.FizzBuzzTypeNumber = FizzBuzzNumber(n)
elif n % 5 == 0:
self.FizzBuzzTypeNumber = BuzzNumber(n)
elif n % 3 == 0:
self.FizzBuzzTypeNumber = FizzNumber(n)
else:
self.FizzBuzzTypeNumber = NumberNumber(n)

def __str__(self):
return str(self.FizzBuzzTypeNumber)


class FizzNumber:
def __init__(self, n):
self.FizzNumberNumber = n

def __str__(self):
return "Fizz"


class BuzzNumber:
def __init__(self, n):
self.BuzzNumberNumber = n

def __str__(self):
return "Buzz"


class FizzBuzzNumber:
def __init__(self, n):
self.FizzBuzzNumberNumber = n

def __str__(self):
return "FizzBuzz"


class NumberNumber:
def __init__(self, n):
self.NumberNumberNumber = n

def __str__(self):
return str(self.NumberNumberNumber)


def FizzBuzzin(n):
fizzBuzzingList = []
for i in range(1, n+1):
fizzBuzzingList.append(FizzBuzzNumberFactory(i))
fizzBuzzingList = list(map(str, fizzBuzzingList))
for i in fizzBuzzingList:
print(i)

it is required for cout. i have never done very much c++, but i was always told to avoid it and use the ones from instead, like printf() and fprintf()

Posted this in /dpt/ a couple days ago.
People seemed to enjoy it.

Well, here's a "no-if-statement" fizzbuzz
#define MAX_NUM 100
int main()
{
const char* strings[4] = {"%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n"};
for(int i = 0; i < MAX_NUM; i++ )
printf(strings[((i % 3) == 0) + 2*((i % 5) == 0)], i);
}

neat

enterprise ready

.data
fiz: .asciiz "Fizz"
buz: .asciiz "Buzz"
nl: .asciiz "\n"
.text
main:
li $t0, 1
li $t7 101
li $t3 3
li $t5 5
li $t4 1
li $v0 4

Loop: beq $t0 $t7 End
div $t0 $t3
mfhi $t2
beqz $t2 Fizz

N1: div $t0 $t5
mfhi $t2
beqz $t2 Buzz

N2: beqz $t4 N3
li $v0 1
move $a0 $t0
syscall
li $v0 4

N3: addi $t0 $t0 1
la $a0 nl
syscall
li $t4 1
j Loop

Fizz:
la $a0 fiz
syscall
li $t4 0
j N1
Buzz:
la $a0 buz
syscall
li $t4 0
j N2
End:
li $v0 10
syscall

you say that like it's a bad thing, although I'd much rather had those boards open still

for 1..100 -> $i {say "fizz" x $i %% 3 ~ "buzz" x $i %% 5 || $i}

in c++ this is just

template struct overloaded : Ts... { using Ts::operator()...; };
template overloaded(Ts...) -> overloaded;

int main (int argc, char** argv)
{
const auto isEven = [](const auto i) -> bool { return i%2 == 0;};
const auto sum = [](const auto i, const auto a){ return i + a;};
const auto fb = [](const auto i) -> std::variant
{
if(i % 5 == 0 && i % 3 == 0) return String("fizzbuzz");
if(i % 3 == 0) return ("fizz");
if(i % 5 == 0) return ("buzz");
return i;
};

const auto fbExpr = Integers() | Map(fb);
const auto eval = fbExpr | Take(100) | CollectList();


}


typesafe, pure functional lazy evaluated
not going to bother doing the overloaded shit to print the output because its cancer

Attached: Illya 1200 (DI).jpg (1920x1080, 177K)

and i guess fizz could going to get casted to an int lol oh well lol

function fizzBuzz(num) {
switch(num % 15) {
case 0:
return 'FizzBuzz';

case 5:
case 10:
return 'Buzz';

case 3:
case 6:
case 9:
case 12:
return 'Fizz';
}

return num;
}

for(let i = 1; i < 101; i++) {
console.log(fizzBuzz(i));
}

func fizzBuzz(_ n: Int) -> String {
var ret = String()
if (n % 3 == 0) { ret += "Fizz" }
if (n % 5 == 0) { ret += "Buzz" }
if (ret.isEmpty) { ret = String(n) }
return ret
}

(1...100).forEach { print(fizzBuzz($0)) }

Fuck you

if then buzz fizz buzz

for i in {1..100}; do
[ $(( i % 3 )) -eq 0 ] && o=fizz || {
[ $(( i % 5 )) -eq 0 ] && o=${o}buzz
} || {
[ -z $o ] && o=$i
}
echo $o
o=
done


How do I make this faster?

seq 1 100 | sed '3~3s/$/ Fizz/; 5~5s/$/ Buzz/; / / { s/^[0-9]*//; }; s/ //g;'

This exists; it's called the Unreal Engine.

Why you faggots look for retarded ass complicated solutions. No matter what you do will remain as a o(n) solution.

int main(void)
{
int i;
for (i=1; i

Hate when faggots use single letters to name their variables. Unless you are doing using mathematic formulae stop doing this you scrub.

Here's one in J with no modulus:
>(([`]@.(0:=#@[))&.>)/"1((100$(a:&,)^:2)"1 1(100$(a:&,)^:4

Attached: mind__s_desire_by_ubermonster-d3rbz4b.jpg (800x589, 70K)

tip: swap couts for a string stream and then check if it's empty

#include
#include
void printnum(int num) {
int set = 0;
if ( num % 3 == 0) {set = 1; printf("Fizz");}
if ( num % 5 == 0) {set = 1; printf("Buzz");}
if (set != 0) return;
printf("%d", num);
}
int main(int argc, char **argv) {
if (argc 2) {
fprintf(stderr, "usage: %s \n", argv[0]);
return 1;
}
int max = atoi(argv[1]);
if (max

#include

#define LIMIT 100

int
main ()
{
const char *const p[15] =
{ "FizzBuzz", 0, 0, "Fizz", 0, "Buzz", "Fizz", 0, 0, "Fizz", "Buzz", 0,
"Fizz", 0, 0 }, *c;
for (int i = 0; i < LIMIT; ++i)
(c = p[i % 15]) ? puts (c) : printf ("%d\n", i);
}
//Copyright 2018 Joe - Do NOT Redistribute!
rate??

Attached: 1536247957739.jpg (650x400, 22K)

>Do NOT Redistribute

Attached: images.png (224x225, 12K)

Just doing my part to combat software piracy!

Ok, now define "the character" and "jump".

the character is a human controlled object
the character can be described as "A small smug creature who trusts in the banking system."
the character has the ability "moving"
when moving the character navigates laterally between areas adjacent to the character's current position
the character has the ability "jumping"
when jumping the character is raised upwards by 1 unit for 1 turn

const fizzbuzz = (min, max) => {
for(let i = min; i < max; i++) {
let str = '';
if(i % 3 == 0) str += 'fizz';
if(i % 5 == 0) str += 'buzz';
console.log(str || i);
}
};

while((i++

Attached: 1538885359486.png (749x1200, 670K)

1.upto(100){|n|puts'FizzBuzz'[i=n**4%-15,i+13]||n}

Attached: ruby-tan.jpg (300x440, 19K)

i found a bug i fixed it now
//VERSION 2.0 FIZZER
#include

#define LIMIT 100

int
main ()
{
const char *const p[15] =
{ "FizzBuzz", 0, 0, "Fizz", 0, "Buzz", "Fizz", 0, 0, "Fizz", "Buzz", 0,
"Fizz", 0, 0 }, *c;
for (int i = 1, j = 1; i

PROGRAM FIZZBUZZ
INTEGER t

DO 10 t = 1, 100
IF (MOD(t, 15) .EQ. 0) THEN
PRINT *, 'FIZZBUZZ'
ELSEIF (MOD(t, 5) .EQ. 0) THEN
PRINT *, 'BUZZ'
ELSEIF (MOD(t, 3) .EQ. 0) THEN
PRINT *, 'FIZZ'
ELSE
PRINT *, t
ENDIF
10 CONTINUE

END PROGRAM FIZZBUZZ

Okay. Now this is epic.

is that cobol?

Doey your college save the good languages for after the weeding out?

>No whitespaces in the lines before the "def __str__"

Eeach iteration has 3 tests.
The most used solution

if( i%3==0 && i%5==0)
else if ( i%3==0 )
else if ( i%5==0 )
else

has 3 tests on the worst case per iteration.

ugh
thats my call to go to sleep

void fizzbuzz_ascended()
{
int count = 101;
float div3, div5;

while (true)
{
if (count == 1)
{
break;
}
count--;
div3 = float(count) / 3;
div5 = float(count) / 5;
std::cout

Wut is this

protocol Fizzable {
func canBeFizzed() -> Bool
}

protocol Buzzable {
func canBeBuzzed() -> Bool
}

protocol Fizzbuzzable: Fizzable, Buzzable {
func canBeFizzBuzzed() -> Bool
}

extension Fizzbuzzable {
func canBeFizzBuzzed() -> Bool {
return canBeBuzzed() && canBeFizzed()
}
}

extension Int: Fizzbuzzable {
func canBeFizzed() -> Bool {
return self % 3 == 0
}

func canBeBuzzed() -> Bool {
return self % 5 == 0
}
}

protocol Factory {
func makeString() -> String
}

struct FizzFactory: Factory {
func makeString() -> String {
return "fizz"
}
}

struct BuzzFactory: Factory {
func makeString() -> String {
return "buzz"
}
}

struct FizzBuzzFactory: Factory {
private let fizzFactory = FizzFactory()
private let buzzFactory = BuzzFactory()

func makeString() -> String {
return fizzFactory.makeString() + buzzFactory.makeString()
}
}

struct IntFactory: Factory {
let intValue: Int

func makeString() -> String {
return "\(intValue)"
}
}

// This is where the magic happens
func fizzbuzz(_ range: ClosedRange = 0...100) {
for i in range {
let factory: Factory
if i.canBeFizzBuzzed() {
factory = FizzBuzzFactory()
} else if i.canBeFizzed() {
factory = FizzFactory()
} else if i.canBeBuzzed() {
factory = BuzzFactory()
} else {
factory = IntFactory(intValue: i)
}
print(factory.makeString())
}
}

Fortran

1[[Fizz]n1sw]sF[[Buzz]n1sw]sB[dn]sN[dd0sw3%0=F5%0=Blw0=N[
]n1+d100!

you should push each result into an array and then print the result at the end for better performance

nice

t.

>its a butthurt pajeet tries to make Swift look like a shitlang episode

for i in 1...100 {
switch (i % 3 == 0, i % 5 == 0) {
case (false, false): print(i)
case (true, false): print("fizz")
case (false, true): print("buzz")
case (true, true): print("fizzbuzz")
}
}

>Why you faggots look for retarded ass complicated solutions.
>Fizzbuzz

Attached: nofun.png (448x473, 348K)

I have two fizzbuzzes I wrote last week on my phone when I had read about it here. The first one is the fizzbuzz ever so be nice.
for i in range(1, 101):
if i % 3 == 0:
if i % 5 == 0:
print("fizzbuzz")
else:
print("fizz")
elif i % 5 == 0:
print("buzz")
else:
print(i)

I wrote the second smaller and to have numbers printed for each line, which I like.
for i in range(1, 101):
s = str(i) + " "
if i % 3 == 0:
s += "fizz"
if i % 5 == 0:
s += "buzz"
print(s)

>you'll also want to avoid the iostream library
>i have never done very much c++, but i was always told ___
kek

If (key_pressed('G')) player.jump()

Most game engines make it that intuitive. You shouldn't be programming if you can't read that..

static void FizzBuzz(int upperBound = 100) => Enumerable.Range(1,upperBound).ToList().ForEach(v=>System.Console.WriteLine(v%3==0?v%5==0?"FizzBuzz":"Fizz":v%5==0?"Buzz":""+v));

subset Fizz of Int where * %% 3;
subset Buzz of Int where * %% 5;
subset FizzBuzz of Int where Fizz & Buzz;

for 1..100 -> $n {
first $n ~~ *, FizzBuzz, Fizz, Buzz, :p
andthen .value.^name.say orelse $n.say
}

I'm just learning C++ for work. Is it common practice to use the
using name space
instead of just doing std::cout?

do not do
using namespace std;

you're polluting your namespace

From what I've read on Jow Forums it's better not to use using namespace std because, for example, if you want to create your own sort() function, it could potentially cause headaches. The other thing I've read is that you should never put using namespace std in a header because all the files that include it will be affected.

4

if( !(i%3))

:^)

a={};
for i=1, 100 do
a[i] = i
end

for i=3, 100, 3 do
a[i] = "fizz"
end

for i=5, 100, 5 do
a[i] = "buzz"
end

for i=15, 100, 15 do
a[i] = "fizzbuzz"
end

for i=1, 100 do
print(a[i])
end

I like you

lmao having different prints for "fizzbuzz" and "fizz"

++++++++++[>++++++++++>++++++++++>->>>>>>>>>>-->+++++++[->++++++++ ++[->+>+>+>+>++++++++[-]+++++[-]>-->++++++[->+++++++++++[->+>+>+>+++ ++++>++++++++[-]++++++[-]>-->---+[-+>++[-->++]-->+++[---+>-[++[--+[->[-]+++++[ ---->++++]-->[->+>[.>]>++]-->+++]---+[->-[+>++++++++++- [>+>>]>[+[-]>+>>]+[++++++++.[-]]

perl -e 'say "Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100'

holy waste of time, non-autists and women would kill themselves before being able to complete a single page of this """"""""""""""code""""""""""""""

What part is human controlled?
What defines creature?
Does the human control the arms? Are the arms a separate object? What about inventory? Is that separate? How do you determine when the character is moving laterally? Or when areas are adjacent? What determines a unit or a turn?

Ive only been studying for a month, but I really don't think this is the best way to do it.

>using namespace
>cout
>4 fucking conditionals
#include
int
main (void)
{
for (int i = 0; i < 100; i++) {
printf("%d\r", i);
if (!(i%3)) printf("Fizz");
if (!(i%5)) printf("Buzz");
printf("\n");
}
}

>2019-2.5/12
>looping over prints at all

Attached: 1412448508239.png (421x389, 252K)

zipWith max mold $ map show [1..]
where mold = cycle $ ((++) reverse) ["","","Fizz","","Buzz","Fizz",""] ++ ["FizzBuzz"]

MIPS assembly

Nim does not respect my autism. I want a language that encourage complexity and verbosity without boilerplate.

Attached: Screenshot from 2018-10-17 03-30-22.png (727x728, 79K)

doesnt work for 5+ digit numbers :^)

library ieee;
use ieee.std_logic_1164.all;
library std;
use std.textio.all;

entity fizzbuzz is
end fizzbuzz;

architecture structural of fizzbuzz is
begin
process
begin
for i in 1 to 100 loop
if i mod 3 = 0 and i mod 5 = 0 then
write (output, "FIZZBUZZ" & LF);
elsif i mod 3 = 0 then
write (output, "FIZZ" & LF);
elsif i mod 5 = 0 then
write (output, "BUZZ" & LF);
else
write (output, integer'image(i) & LF);
end if;
end loop;
wait;
end process;
end architecture;

in c++ this is just

template struct overloaded : Ts... { using Ts::operator()...; };
template overloaded(Ts...) -> overloaded;

int main (int argc, char** argv)
{
const auto isEven = [](const auto i) -> bool { return i%2 == 0;};
const auto sum = [](const auto i, const auto a){ return i + a;};
const auto fb = [](const auto i) -> std::variant
{
if(i % 5 == 0 && i % 3 == 0) return String("fizzbuzz");
if(i % 3 == 0) return ("fizz");
if(i % 5 == 0) return ("buzz");
return i;
};

const auto fbExpr = Integers() | Map(fb);
const auto eval = fbExpr | Take(100) | CollectList();


}

typesafe, pure functional lazy evaluated
not going to bother doing the overloaded shit to print the output because its cancer

Attached: Illya 1212 (RW).gif (500x500, 1.25M)

Ironic that roasties and NPCs can't compile code in their minds considering they run it 24/7.

Attached: NPCcomic.jpg (1590x6314, 2.25M)

Jesus christ why

#!/bin/bash/python3
i = 0
while True:
i += 1
if (i % 3 == 0):
print ("Fizz")
if (i % 5 == 0):
print ("Buzz")
if (i % 15 == 0):
print ("FizzBuzz")
else:
print (i)

#include

int main(void)
{
for (unsigned int i = 1; i

This guy knows whats up.

nice

Attached: 1505266747093.jpg (223x225, 9K)

someone made a pretty *banging* pattern matching lib for nim
import gara

for i in 1..100:
match (i mod 3, i mod 5):
of (0, 0): echo "FizzBuzz"
of (0, _): echo "Fizz"
of (_, 0): echo "Buzz"
else: echo i

This is in MATLAB.
No loops, no multi line BS just simple and clean code.

Attached: Screenshot_20180526-165324.png (2880x1440, 122K)

>No matter what you do will remain as a o(n) solution.
Retard. There is a trivial O(1) solution.

Also same complexity means literally nothing for computation time, something anyone who wrote something more complex then fizzbuzz should know.

Not even Java...

If you are making a tiny first semester lab program it doesn't matter. Otherwise, don't pollute your namespace.