Fizzbuzz

Post your fizzbuzz solutions.

#include

using namespace std;

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

Other urls found in this thread:

gist.github.com/anonymous/773239ad3e608cb50fcd760cee08a78f
codepen.io/SachaG/pen/jCpba
github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition/
github.com/xoreaxeaxeax/movfuscator
github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition
pastebin.com/hKttv1KQ
twitter.com/SFWRedditVideos

>endl
Thanks you for coming, WE will call you

if(3/5)
print fizz
else if(5/3)
print buzz
else
print fizzbuzz

Im sorry but I have a stable job and dont need to put up with this bullshit

Just look at this faggot.

what's wrong with it

Who taught you how to program?

fzzbzz :: Int -> String -> (String, Int) -> (String, Int)
fzzbzz m sound (str, x) = (str ++ if mod x m == 0 then sound else "", x)

fix :: (String, Int) -> String
fix ("", x) = show x
fix (st, _) = st

fizzbuzz :: [(String, Int)] -> Int -> String
fizzbuzz sounds top
| top x ++ "\n" ++ y) [] (map fizzer numbers)
where fizzer = (foldl (.) fix (reverse [fzzbzz i s | (s, i)

> (3/5)
explain please. How is this viable? Also is this c?

>"functional code is just so readable and elegant user!"

I forgot what fizzbuzz actually does lol

what language is this?

It will print a single line. And it is not even the first correct line of fizzbuzz. Dammit, just tell me it's bait.

It prints 99 lines, not 100. Also, compiler error on first if.

fz = [""]*100
for i in range(2, 100, 3):
fz[i] += "Fizz"
for j in range(4, 100, 5):
fz[j] += "Buzz"
print('\n'.join(fz[i] or i+1 for i in range(0,100)))

You can't just pick and choose the requirements you like, you are supposed to be working to spec.

def fizzybuzzy(n):
if n==0:
return ''
x = ''
if not n%3:
x+='Fizz'
if not n%5:
x+='Buzz'
if x=='':
x+=str(n)+'\n'
else :
x+='\n'
return x + fizzybuzzy(n-1)

gist.github.com/anonymous/773239ad3e608cb50fcd760cee08a78f

i;main(){for(;i++

DOCLAY FizzBuzz:

REGISTER i ARABIC 1 1;
REGISTER mod3 ARABIC 1 1;
REGISTER mod5 ARABIC 1 1;

DEFAULTS
SET
WHILE = "${i}

If a number is divsible by 3 and 5 you can just write % 15 --- cant believe no one on Sup Forums nailed this basic shit

Its not like the compiler will optimize to that anyways

public class FizzButts {
public static void main(String[] args){
for(int i = 0; iinb4 poo in loo

it's more coincise and less verbose, easier to maintain, etc. no wonder ppl here got no real dev job

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');
end;
end.

main = do
mapM_ (putStrLn . f) [1..100]
where
f n
| mod n 15 == 0 = "FizzBuzz"
| mod n 3 == 0 = "Fizz"
| mod n 5 == 0 = "Buzz"
| otherwise = show n

fizzbuzz usually requires you to print the number if it's not divisible by 3 or 5.
int main () {
for(int i=1; i

Come on OP, you gotta use your C++17.
#include
#include
#include

constexpr std::size_t N = 100 + 1;

template constexpr void fizzbuzz(std::index_sequence i) {
auto helper = [](auto f) {
constexpr std::size_t buf_size = (sizeof(std::size_t) * CHAR_BIT) / 3;
std::size_t val = f.value, index = buf_size - 1;
char to_print[buf_size];
while(val) to_print[index--] = '0' + val % 10, val /= 10;
for(std::size_t i = index + 1; i < buf_size; i++) std::cout

What is the most outrageous way you could do this?

":`('Fizz'"_)`('Buzz'"_)`('FizzBuzz'"_)@.(0&=@(3&|)++:@(0&=)@(5&|))"0 >: i.100

pure css codepen.io/SachaG/pen/jCpba

#include
#include
#include
#include

int main ()
{
std::vector numbers (100);
std::iota (numbers.begin(), numbers.end(), 1);
std::transform (numbers.begin(), numbers.end(), std::ostream_iterator(std::cout, "\n"), [](int x) -> std::string
{
if (x % 15 == 0)
return "FizzBuzz";
else if (x % 5 == 0)
return "Buzz";
else if (x % 3 == 0)
return "Fizz";
else
return std::to_string (x);
});
}

sad!

package com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.FizzBuzz;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.factories.FizzBuzzSolutionStrategyFactory;
import com.seriouscompany.business.java.fizzbuzz.packagenamingpackage.interfaces.strategies.FizzBuzzSolutionStrategy;

@Service
public class StandardFizzBuzz implements FizzBuzz {

private final FizzBuzzSolutionStrategyFactory _fizzBuzzSolutionStrategyFactory;

@Autowired
public StandardFizzBuzz(final FizzBuzzSolutionStrategyFactory _fizzBuzzSolutionStrategyFactory) {
super();
this._fizzBuzzSolutionStrategyFactory = _fizzBuzzSolutionStrategyFactory;
}

public void fizzBuzz(final int nFizzBuzzUpperLimit) {
final FizzBuzzSolutionStrategy mySolutionStrategy =
this._fizzBuzzSolutionStrategyFactory.createFizzBuzzSolutionStrategy();
mySolutionStrategy.runSolution(nFizzBuzzUpperLimit);
}

}


from github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition/

Yeah I like it, it really captures the essence of it. We really need range objects though.

At least write something that compiles.

IntProgression.fromClosedRange(1,100,1).forEach{
when (it) {
3, 6, 9, 12, 18, 21, 24, 27, 33, 36, 39, 42, 48, 51, 54, 57, 63, 66, 69, 72, 78, 81, 84, 87, 93, 96, 99 -> println("Fizz")
5, 10, 20, 25, 35, 40, 50, 55, 65, 70, 80, 85, 95, 100 -> println("Buzz")
15, 30, 45, 60, 75, 90 -> println("FizzBuzz")
}
}

how do i into code tags

IntProgression.fromClosedRange(1,100,1).forEach{
when (it) {
3, 6, 9, 12, 18, 21, 24, 27, 33, 36, 39, 42, 48, 51, 54, 57, 63, 66, 69, 72, 78, 81, 84, 87, 93, 96, 99 -> println("Fizz")
5, 10, 20, 25, 35, 40, 50, 55, 65, 70, 80, 85, 95, 100 -> println("Buzz")
15, 30, 45, 60, 75, 90 -> println("FizzBuzz")
}
}

i see you like fast solutions

One of the obsecure coding languages with absolutely no libraries so you're just pushing and popping values in a really fucked way. Like the l33t talk language or the one that is 2d and is arrows pointing everywhere.

assembly but only using mov

### 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))

b(X) when (X rem 15) == 0 -> "fizzbuzz~n";
b(X) when (X rem 3) == 0 -> "fizz~n";
b(X) when (X rem 5) == 0 -> "buzz~n";
b(X) -> integer_to_list(X) ++ "~n".

f() -> lists:map(fun io:format/1, [b(X) || X

p{counter-increment: item}p:not(:nth-of-type(5n)):before{content: counter(item)}p:nth-of-type(3n):before{content: "Fizz"}p:nth-of-type(5n):after{content: "Buzz"

(defn fz-match [divider string]
(fn [x]
(unless (% x divider)
string)))

(defn fizzer [fizzers]
(fn [x]
(or (.join "" (filter None
((juxt #* fizzers) x)))
(str x))))

(defn dofizz [iterator &rest fizzers]
(map (fizzer fizzers)
iterator))

(defn fizzbuzz [iterator]
(for [x (dofizz iterator
(fz-match 3 "fizz")
(fz-match 5 "buzz"))]
(print x)))

# Fizzbuzz

%:import:(read) |> r.

:do:(_ _ :Xs:X) |> :Xs:X
:do:(_ _ _ _ :Xs:X) |> :Xs:X


:if:(|T :Xa:X :_:_) |> :Xa:X
:if:(|F :_:_ :Ya:Y) |> :Ya:Y

:fizzbuzz:(101) |> ()
:fizzbuzz:(X) |> :do:(
:r.printn:X
:if:(
:==:(:mod:(X 3) 0)
:r.prints:" Fizz"
()
)
:if:(
:==:(:mod:(X 5) 0)
:r.prints:" Buzz"
()
)
:printc:'\n'
:fizzbuzz:(:+:(X 1))
)

:main:() |> :fizzbuzz:(1)

But you can compile to that from c
github.com/xoreaxeaxeax/movfuscator

>i=1
>i < 101
ewwwwwwwww

python3

from itertools import cycle
for l in (''.join(fb) or str(i) for i,*fb in zip(range(1,101),cycle(['']*3 + ['Fizz']), cycle(['']*5 + ['Buzz']))): print(l)

fucking pdf, good one user

puts (1..100).map { |i| (fb = [["Fizz"][i % 3], ["Buzz"][i % 5]].compact.join).empty? ? i : fb }

*teleports behind you*
main = do
mapM_ (putStrLn . f) [1..100]
where
f n
| rem n 15 == 0 = "FizzBuzz"
| rem n 3 == 0 = "Fizz"
| rem n 5 == 0 = "Buzz"
| otherwise = show n

nothing personel kid
*outperforms you*

def fizzbuzz(n: Int): Unit =
(Stream.from(3).filter(a => a%3 == 0 || a%5 == 0) take n) foreach {x =>
if(x%3 == 0 && x%5 == 0) println("fizzbuzz")
else if(x%3 == 0) println("fizz")
else println("buzz")
}

Loops are for brainlets.

[Code]def fizzbuzzHelper(n):
if n==0:
return []
x=''
if not n%3:
x += 'Fizz'
if not n%5:
x += 'Buzz'
if x=='':
return [str(n)]+f(n-1)
else:
return [x]+f(n-1)

def fizzbuzz(100):
print('\n'.join(fizzbuzzHelper(100)[-1::-1]))[\Code]

Jesus Christ

for (int i = 1; i

Or you can simply not write it at all

The absolute state of Sup Forums

Haskell. It's a troll post because the haskell fizzbuzz is actually THE #1 tutorial example for functional languages. Just google "haskell online interpreter" and you will get a fucking proper fizzbuzz.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

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

github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

for i in range(101):
print(i%3==0)*"Fizz"+(i%5==0)*"Buzz" or i)

Impressive. Very nice.

>#include
>#include
>#include
>#include
>#include
>#include
>#include
>#include
>#include
>#include
>#include
>#include
>#include
>#include
>using namespace std;

Holy fuck, I kek'd hard.

No modulo, division, or even addition/subtraction:
#include
#include
using namespace std;

int main () {
for(uint_least32_t x=1, y=2, z=2; x != 1048576; y

>tips fedora

global _start

section .data
fizz db "Fizz"
buzz db "Buzz"
a dd 3
b dd 5
c dd 10

section .bss
sb resb 800

section .text
_start:
mov ebx, 1
lea edi, [sb]
.l:
mov ecx, 1

mov eax, ebx
xor edx, edx
div dword [a]
test edx, edx
jnz .c1

lea esi, [fizz]
mov ecx, 4
rep movsb
.c1:
mov eax, ebx
xor edx, edx
div dword [b]
test edx, edx
jnz .c2

lea esi, [buzz]
mov ecx, 4
rep movsb
.c2:
test cl, cl
jz .b

mov eax, ebx
mov rbp, rsp
.l1:
xor edx, edx
div dword [c]
add dx, '0'
push dx
test eax, eax
jnz .l1
.l2:
pop ax
stosb
cmp rbp, rsp
jne .l2

.b:
mov eax, 10
stosb

inc ebx
cmp ebx, 100
jbe .l

sub edi, sb
mov rdx, rdi
lea rsi, [sb]
mov rdi, 1
mov rax, 1
syscall

mov rax, 60
xor rdi, rdi
syscall

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

well fug

#include

for i in {1..100}
do (
sleep $i
if [ $((i % 3)) -eq 0 -a $((i % 5)) -eq 0 ]; then
echo fizzbuzz
elif [ $((i % 3)) -eq 0 ]; then
echo fizz
elif [ $((i % 5)) -eq 0 ]; then
echo buzz
else
echo $i
fi
)&
done

...

if you do it without else if you only need two if statements one for fizz and one for buzz

pastebin.com/hKttv1KQ

Did I do it right?

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)


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))

No, looks like python 2.7

Yeah

#include

template struct Value;

template< int n, typename = Value >
struct fizzbuzz
{
fizzbuzz()
{
fizzbuzz fb;
printf("%d\n", n);
}
};

template
struct fizzbuzz< n, Value >
{
fizzbuzz() { }
};

template
struct fizzbuzz< n, Value 0 && n % 15 == 0)> >
{
fizzbuzz()
{
fizzbuzz fb;
puts("fizzbuzz");
}
};

template
struct fizzbuzz< n, Value 0 && n % 3 == 0 && n % 5 != 0)> >
{
fizzbuzz()
{
fizzbuzz fb;
puts("fizz");
}
};

template
struct fizzbuzz< n, Value 0 && n % 5 == 0 && n % 3 != 0)> >
{
fizzbuzz()
{
fizzbuzz fb;
puts("buzz");
}
};

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

What's good about it? He literally failed to do fizzbuzz

>Not using a while loop

Heh. Faggot.

Imperative pleb

select = (a, b, c) => a + b || c

cycler = (v) => () => {
v.push(v.shift());
return v[v.length + -1];
};

fizz = cycler(['','','Fizz'])
buzz = cycler(['','','','','Buzz'])

Array.from({length: 100}, (_, i) => console.log(select(fizz(), buzz(), i + 1)))

What does fizzbuzz do?

Shows the potential employer you've been wasting your time on useless shit (aka learning FizzBuzz) instead of learning programming, so they, in turn, don't waste their time on you.

Employers allegedly use it to filter out canidates that can't do kindergarden programming problems.

It generates shitposting.

>Intel syntax
>_start and not main
Disgusting.

for i in 1..100
if (i % 3).zero? && (i % 5).zero?
puts 'fizzbuzz'
elsif (i % 3).zero?
puts 'fizz'
elsif (i % 5).zero?
puts 'buzz'
else puts i
end
end


am i brainlet and missed the point or is it fizzbuzz really that easy? why is it even asked in interviews?

Most computer science graduates apparently can't do it. look it up

This isn't portable but works on x86_64 Linux for me.

#include
#include
#include

#define Oo 100ULL
#define __(oo,oO)\
for (o=(Oo*(oo)>>(oO));o>(oO)))OO ++[O]

int _o(const void *o, const void *O) { return
((*(uint64_t*)o) >> 48) > (uint64_t)(*((char*)O + 6)) ;}

int main(void)
{
uint64_t oo, oO, o, O [Oo * 0x1bbbbbbbd4 >> 36], OO = 0;

__(0x3e0f83e1ull, 35) = (o 060; oo =o;
while (!(oO^ (o [O])) && (o [O]&16711680))
printf("%s", (char*)&o ++[O]);
printf(!(o ^oo) ? "%s\n" : "\n", (char*)&o [O]);
} return

0;
}

what language is this
this is fucking gross

lisp

> fucking gross
oO

>stable job
>programming

lmao you think the fact that you don't job hop every few years is a good thing? enjoy your stagnant wages.

holy shit, hired

It's C, but it's hand optimised.

This is Emacs Lisp

(defun fizzbuzz (n)
(append (if (> n 1) (fizzbuzz (1- n)))
(list (pcase `(,(% n 3) ,(% n 5))
(`(0 0) "FizzBuzz")
(`(0 ,_) "Fizz")
(`(,_ 0) "Buzz")
(`(,_ ,_) (number-to-string n))))))

(princ (mapconcat 'identity (mapcar (lambda (x) (concat x "\n")) (fizzbuzz 100)) ""))

You could've done this in like three lines

well
it works

Erlang:
#!/usr/bin/env escript
main(_) ->
ToWord = fun({0, 0}) -> {true, "FizzBuzz"}; ({0, _}) -> {true, "Fizz"}; ({_, 0}) -> {true, "Buzz"}; (_) -> false end,
[io:format("~s~n", [Word]) || Word

public class FizzBuzz {
public static void main(String arg) {
if(arg.equals(""))
main("1");
else {
int fizzcounter = Integer.parseInt(number);
if(fizzcounter > 100) {
if(fizzcounter % 15 == 0)
System.out.println("FizzBuzz");
else if (fizzcounter % 5 == 0)
System.out.println("Buzz");
else if (fizzcounter % 3 == 0)
System.out.println("Fizz");
else
System.out.println(fizzcounter.toString());

main((fizzcounter + 1).toString());
}
}
}
}

why a class? there's literally no reason to make it a class

>why is your java code contained within a class
>why is your main within a class

>java