FizzBuzz

Implement FizzBuzz in your language of choice.

No manual unrolling allowed.

Easy mode: no modulus or division
Hard mode: no looping, only recursion
Harder mode: no variables, use only literals, functions and their arguments
Even harder mode: only arithmetic allowed is + 1
Ultra hard mode: no branching

Other urls found in this thread:

github.com/xoreaxeaxeax/movfuscator
twitter.com/NSFWRedditGif

Forgot to mention that increasingly harder modes must also follow rules for easier modes.

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

Fuck rules, write something more elegant than this.

def eval(n: Int): Any = n match {
case n if n % 5 == 0 && n % 3 == 0 => "fizzbuzz"
case n if n % 3 == 0 => "fizz"
case n if n % 5 == 0 => "buzz"
case _ => n
}

def from(n: Int): Stream[Int] = n #:: from(n+1)

(from(1) map eval).take(100).toList

import fishbuss

Fishbuss.start()

You can collapse the "n % 5 and n % 3" into "n % 15"

Yes, doable, more coincise and somewhat less expressive, would go for it though

it's part of the fizzbuzz joke

select = (i) =>
(i % 3 == 0 ? "fizz" : "") + (i % 5 == 0 ? "buzz" : "") || i

Array
.apply(null, {length: 101})
.map(Number.call, Number)
.splice(1)
.map(select)
.forEach((i) => console.log(i))

More coincise, but
>arrays
>console.log
>side effect

Except for output, what's the side effect?

Was just sperging about output, I lke your implementation

And just remove the last line if you don't want to print every member.

U0 main() {
U8 i, fizz, buzz;
for (i = 0, fizz = 0, buzz = 0; i < 100; i++, fizz++, buzz++) {
Print("%2u ", i);
if (fizz == 3) {
Print("Fizz");
fizz = 0;
}
if (buzz == 5) {
Print("Buzz");
buzz = 0;
}
Print("\n");
}
}

main;

I like this one.

That's pretty neat.

>Sup Forumsay retards still doing normie fizzbuzz challenges

Pffft, show me all the prime factors of 1 billion (1000000000) in 30 seconds maximum. Corelets not allowed, sorry Intel pajeets.

Protip: use FORTRAN or C.

>Ultra hard mode: no branching
What?

No conditions.

2^9 * 5^9
You can do that in your head, c'mon now

>1 gorrilion in 1 sec

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

You can do fizzbuzz in your head too, retard, it's a game designed for little kids. You can also google the solution to my challenge, that's not the thing I want.

The idea is to show a program figuring it out from scratch, so hurry up.

But the point is that 10^9 is 2ez, even the following shitty code can do it in a few millis tops. Choose a number with a more interesting prime factorization next time.
def slowfactors(n):
o = []
p = 2
while n > 1:
d, m = divmod(n, p)
if m:
p += 1
else:
n = d
o.append(p)
return o

Probably doesn't even work but that's how I remember it and I'm on an old tablet and can't test it.

dafuq are u doing

The speed isn't the point either (the 30 second limit is to stop complete retards).

That code snippet doesn't even do shit at all. My challenge still stands, it's very easy to do, that's why 1 billion was picked so the results are easily confirmable.

>Using while instead of for

Kek.

#include
#include
#include

#define is_set(i) \
!!(bitmap[(i) >> 4] & (1 > 4] |= 1

it works and is fun.

int mod(int x, int y) {
int res = x;
while (res >= y)
res -= y;

return res;
}

void fizzBuzz (int n) {
if (n == 0)
return;

fizzBuzz(n-1);
if (!mod(n,3))
printf("Fizz");
else if (!mod(n,5))
printf("Buzz");
else
printf("%i", n);
printf("\n");

}

int main(){
fizzBuzz(100);
}

Only - is used

With output

#include
#include
#include

#define is_set(i) \
!!(bitmap[(i) >> 4] & (1 > 4] |= 1

Impressive. Should be trivial to make mod recursive too?

>Not understanding the use of while instead of for in this situation is better
Ladies and gentlemen, a code monkey
>Leddit spacing
Fuck off back to your safespace, bitchboy.

>Does not fulfill requirements
>Terrible formatting
>Does not conform to code standards
>C
0/10

No modulo
No looping (only recursion)
No variables (only literals and arguments)
Only + 1
Sadly, I have to do a conditional on wrapping on 15 though.

#include

const char* fb_fmt[] = {
"fizzbuzz\n",
"%u\n",
"%u\n",
"fizz\n",
"%u\n",
"buzz\n",
"fizz\n",
"%u\n",
"%u\n",
"fizz\n",
"buzz\n",
"%u\n",
"fizz\n",
"%u\n",
"%u\n"
};


void fizzbuzz(int i, int n, int f)
{
if (i == n)
{
return;
}

printf(fb_fmt[f], i);
fizzbuzz(i + 1, n, ++f == 15 ? 0 : f);
}


int main()
{
fizzbuzz(1, 101, 1);
return 0;
}

No one is going to do your homework for you, pajeet.

return (x < y) ? x : mod(x-y, y);

I still don't see how to do that without branching.

Well done.

>I still don't see how to do that without branching.
I _think_ it's not possible.

What language is this?

JavaScript

t. Code monkey

How can something so elegant be shitty JavaScript??????

user, I didn't ask for all prime numbers up to 1 billion. I asked for prime factors of 1 billion. Good work regardless, as it just werks, except:

bitmap[N];

Come on now. Arrays with variables as sizes? Nu-C please.

>Can't justify his use of while over for
>Not even slightly pythonic
>Browses Reddit to know how they do spacing over there

I won't go to your safespace until you let me in :)

>Says this in a fizzbuzz thread of all things

Sure thing, Mrs. Kloss.

>U0
>U8
That is not c I belive

Because javascript is great...? Nigger, you are thinking of Java.

>I didn't ask for all prime numbers up to 1 billion. I asked for prime factors of 1 billion.
I see, I read wrong. Sorry.

>Come on now. Arrays with variables as sizes?
It's not variable, N is defined const.
lrn2 C

>pythonic
Okay, now I know this is just bait.

No, I'm thinking of webpajeet.

Fizzbuzz oneliners, here's python

python -c "[print('Fizz'*(not i%3) + 'Buzz'*(not i%5) or i for i in range(1,101)])"

>Says this in a fizzbuzz thread of all things
>Sure thing, Mrs. Kloss.
Fair enough, but even schools do more complex shit than fizzbuzz. That question the other poster put up was just straight up homework.

whelp, my brackets got fucked

Non retard version:
python -c "print(['Fizz'*(not i%3) + 'Buzz'*(not i%5) or i for i in range(1,101)])"

Thats pretty elegant

nice m8, mine is based on yours

#include
#include

typedef std::map fizzbuzz_t;
typedef fizzbuzz_t::const_iterator fizzbuzz_it;

void dofizzbuzz(fizzbuzz_t &fizzbuzz, int from, int to, int inc, const std::string &what) {
if(from >= to) return;
fizzbuzz[from] = what;
dofizzbuzz(fizzbuzz, from + inc, to, inc, what);
}

void dofizzbuzz(fizzbuzz_t &fizzbuzz, int from, int to, int inc) {
if(from >= to) return;
fizzbuzz[from] = std::to_string(from);
dofizzbuzz(fizzbuzz, from + inc, to, inc);
}

void print(const fizzbuzz_it &begin, const fizzbuzz_it &end) {
if (begin == end) return;
std::cout second

> Does not know JavaScript
> code monkey

What?? So writing exclusively in low-level languages like C is being a code monkey?

Not mine but yeah it is. List comprehensions are one of my favorite things about python.

Count all numbers from 1 to 100.
If the number is divisible by 3, then say "fizz".
If the number is divisible by 5, then say "buzz".
Otherwise, say the number.

Any compiler still treats it as a variable, I had to change it myself to not "dynamically" set or variably modified as the error shoots out. Switching between C and Python is fucking me up with the pedantics.

>Can't use a language properly by adhering to its philosophy
>"M-m-mmust be BAIT!!! Right guys??! I'm not dumb!!! wtf"

(You) just prove why most people using Python are fucking retards.

Finding prime factors is literally easier or just as easy as fizzbuzz, it just takes a long fucking time for a computer to do it for a large number; thus it's useful in encryption. It's only homework if you are in elementary school. I stole the idea from Project Euler lmao.

Is that Python?

int start = 0;
int end = 100;

for (int i = start + 1; i < 101; i += 1) {
if (i % 3 == 0) {
System.out.print("Fizz");
if (i % 5 == 0) {
System.out.print("Buzz");
}
}
else {
if (i % 5 == 0) {
System.out.print("Buzz");
}
}

if (i % 3 != 0 && i % 5 != 0) {
System.out.print(Integer.toString(i));
}

System.out.print("\n");
}

>reddit spacing

>newfag

>That code snippet doesn't even do shit at all.
At best you could say that it's not a complete program, but the function it defines has meaning.
>Using while instead of for
What iterator, if I may be so bold?

char v[] = "FizzBuzz%d";
int b[] = {8,8,0,8,4,0,8,8,0,4,8,0,8,8,0};

static int mod(int x, int y) {
return (x < y) ? x : mod(x-y, y);
}

void fizzBuzz (int n) {
if (n == 0)
return;

fizzBuzz(n-1);
printf("%.*s\n", 4

What the fuck is that garbage?

Ultra hard mode is literally impossible.

Metaprogramming?

easy. next.
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"

brainlets
#include
int main()
{
for (int i=0;++i

FactorInteger[1000000000]

github.com/xoreaxeaxeax/movfuscator

Mov everything!!!

>tfw declerative programmer

Twas a quite naive and simple solution, but it gets the job done. FYI, my laptop is a potato.
time ./test
2 2 2 2 2 2 2 2 2 5 5 5 5 5 5 5 5 5

real 0m0.107s
user 0m0.104s
sys 0m0.000s


#include
#include
#include

using namespace std;

void genPrimes(vector& primes, int maxValue);

int main()
{
vector primes;
int value = 1000000000;

genPrimes(primes, sqrt(value) + 1);
for (int p : primes) {
while (value % p == 0) {
cout

Recursive lazy solution in racket. What is the purpose of not using basic arithmetic for a problem like fizzbuzz? It's number theory, so you need to test at some point if things are divisible or not...

#lang racket

(require srfi/41)

(define (fizzbuzz-stream)
(let loop ([n 1])
(stream-cons
(match* ((modulo n 3) (modulo n 5))
[(0 0) "FizzBuzz"]
[(0 _) "Fizz"]
[(_ 0) "Buzz"]
[(_ _) (number->string n)])
(loop (add1 n)))))

(module+ test
(require rackunit)
(check-equal? (stream->list (stream-take 15 (fizzbuzz-stream)))
'("1" "2" "Fizz" "4" "Buzz" "Fizz" "7" "8" "Fizz" "Buzz" "11" "Fizz" "13" "14" "FizzBuzz")))

(module+ main
(stream-for-each displayln (stream-take 100 (fizzbuzz-stream))))

Things have improved in ES6

0/ x will always be zero lol

> Loops aren't branching

#include

void fizzbuzz(int n, int fizz, int buzz)
{
if (n > 100)
return;

if (fizz == 3 && buzz == 5) {
printf("FizzBuzz\n");
fizzbuzz(n+1, 1, 1);
return;
}

if (fizz == 3) {
printf("Fizz\n");
fizzbuzz(n+1,1, buzz+1);
return;
}

if (buzz == 5) {
printf("Buzz\n");
fizzbuzz(n+1, fizz+1, 1);
return;
}

printf("%d\n", n);
fizzbuzz(n+1, fizz+1, buzz+1);
}

int main()
{
fizzbuzz(1, 1, 1);
return 0;
}

>Ultra hard mode: no branching
You need a branch for conditionals, unless you hardcode it such that you break
>Hard mode: no looping, only recursion

(((3∘∣⍱⍥(=∘0)5∘∣)(/⊙)⍕),∘⊃,⌿∘(/∘('Fizz' 'Buzz')(0=3∘∣(,[.5])5∘∣)))¨∘⍳

Though it's cheating.

What language is this and how doesn't it contain branching?

(defun is-mult-p (n multiple)

(= (rem n multiple) 0))


(defun fizzbuzz (&optional n)

(let ((n (or n 1)))

(if (> n 100)

nil

(progn

(let ((mult-3 (is-mult-p n 3))
(mult-5 (is-mult-p n 5)))
(if mult-3(princ "Fizz"))(if mult-5(princ "Buzz"))
(if (not (or mult-3 mult-5))

(princ n))

(princ #\linefeed)

(fizzbuzz (+ n 1)))))))

It's APL, here's a shorter version
(∊∘(/∘('Fizz' 'Buzz')3∘∣(0=,)5∘∣),⍕(F⍨)3∘∣⍱⍥(=∘0)5∘∣)¨∘⍳

Also I said it's "cheating", because it never expresses branching (= goto = →), but its implementation obviously does, e.g. ¨ (each adverb), / (replicate verb), ⍳ (index vector verb).

for i in range(1, 101):
if(i % 3 == 0):
print("FIZZ")
if(i % 5 == 0):
print("BUZZ")
if not (i % 3 == 0 or i % 5 == 0):
print(i)


Can we try some other fucking challenges other than goddamn fizzbuzz for once? It's already as solved as it can get when it comes to speed.

Nice copy-paste brainlet

what if i originally wrote this

It's amazing how the lack of indentation and double newlines where they don't make sense really makes this code look less elegant than it is.

where's "fizzbuzz" brainlet python?

> What's programming

Fizzbuzz is unnecessary, you dumb fucking (i % 15) brainlet, learn some software logic. It's an "if" statement after the previous "if", not an "elif". That's why the "if not" is included at the end instead of an "elif". Effectively making 3 if statements instead of what would be 4 or 5. It checks if it's divisible for 3 and 5.

If you cannot even get this wrapped around in your head, then go back to Sup Forums.

No modulus, loops, variables, faggot.

>Fizzbuzz is unnecessary
no, it's not.

x = 1:100
y = rep("", length(x))
y[x %% 3 == 0] = "fizz"
y[x %% 5 == 0] = "buzz"
y[x %% 15 == 0] = "fizzbuzz"

I don't know about this modulus, literals, or branching hokus pokus

>Ultra hard mode: no branching
#include
int main() {
int n;
char* t[] = {"%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n"};
for (n = 1; n

Run the code retard

Yes it is. "Fizzbuzz" as a whole is only included because of readability, but that's not the point of these threads now is it?

If you check for (i % 3) AND THEN (i % 5) separately, you will get Fizz and then Buzz (in Python it's on seperate lines due to how print works).

So this:
Output:
14
FIZZ
BUZZ
16


Will be the same as:
Output:
14
FIZZ
BUZZ
FIZZBUZZ
16


Or:
Output:
14
FIZZBUZZ
16


The words are all attributed to the number 15. The program fundamentally just werks. You're so retarded you can't even comprehend a simple 7 line Python program that isn't even complicated.

If you still include (i % 15), kill yourself.

>not even requiring an enterprise-grade solution

Sad.

I RUNed

it's called "fizzbuzz"
print the fucking "fizzbuzz" you retarded

his thing does print fizzbuzz. did you even read his post or are you actually autistic?

In python3
pip3 install fzzbzz
python3
import fzzbzz
fzzbzz(100)

fizz
buzz
isn't
fizzbuzz

correct your code nobody will judge you

whats the difference