[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]

GIVE ME A FIZZ BUZZ WITH NO IF STATEMENT

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: 50
Thread images: 8

File: db8.jpg (14KB, 256x256px) Image search: [Google]
db8.jpg
14KB, 256x256px
GIVE ME A FIZZ BUZZ

WITH
NO
IF
STATEMENT
>>
python
wordmap = dict()
for i in range(3,101, 3):
wordmap[i] = "Fizz"

for i in range(5,101, 5):
wordmap[i] = "Buzz"

for i in range(15,101, 15):
wordmap[i] = "FizzBuzz"

# some assertion to ensure that things are correct
assert wordmap.get(1, 1) == 1
assert wordmap.get(3, 3) == "Fizz"
assert wordmap.get(4, 4) == 4
assert wordmap.get(5, 5) == "Buzz"
assert wordmap.get(15, 15) == "FizzBuzz"
assert wordmap.get(27, 27) == "Fizz"
assert wordmap.get(55, 55) == "Buzz"
assert wordmap.get(90, 90) == "FizzBuzz"
assert wordmap.get(98, 98) == 98


for i in range(1,101):
print(wordmap.get(i,i))
>>
>>56398808
Literally google
https://gist.github.com/reader1000/2551078
>>
>>56399344
Think I give a fuck nigger?
>>
>>56399374
Wow, someone is mad.
>>
>>56398788
Haskell - a favorite
[max(show x)(concat[n|(f,n)<-[(3,"Fizz"),(5,"Buzz")],mod x f==0])|x<-[1..100]]
>>
>>56399374
angry little shitstain
>>
>>56399388
My own:
fizzbuzz = zipWith max nums (fizz /++ buzz)
where
nums = map show [1..]
(/++) = zipWith (++)
fizz = 2 !? "fizz"
buzz = 4 !? "buzz"
n !? w = cycle (replicate n "" ++ [w])
>>
File: e06.png (79KB, 399x500px) Image search: [Google]
e06.png
79KB, 399x500px
>>56399374
wow, rude.
>>
for i=0-100
switch i
case i % 15 == 0
Etc etc
>>
>>56399606
In what kind of degenerate language can you do this?
>>
>>56398788
(define (fizzybuzzy limit)
(for ([i (in-range 1 limit)])
(cond [(= 0 (modulo i 3)) (printf "Fizz\n")]
[(= 0 (modulo i 5)) (printf "Buzz\n")]
[(= 0 (modulo i 15)) (printf "FizzBuzz\n")]
[else (printf "~a~n" i)])))
>>
#include <stdlib.h>
#include <stdio.h>
int main() {
char key[2][2][10] ={{"0","buzz"},{"fizz","fizzbuzz"}};
for (int i = 0; i <= 100; ++i) {
sprintf(key[0][0],"%d",i);
printf("%s\n",key[!(i%3)][!(i%5)]);
}
}
>>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
for (int i = 0; i <= 100; ++i) {
char s[3] = {0};
sprintf(s, "%d", i);

printf("%s\n",
i % 15 == 0 ? "FizzBuzz" :
i % 3 == 0 ? "Fizz" :
i % 5 == 0 ? "Buzz" :
s);
}
}
>>
File: popcorn.jpg (48KB, 600x600px) Image search: [Google]
popcorn.jpg
48KB, 600x600px
>>56399482
>"with no if statement"
>yfw haskell has no statements, just expressions
Merely answering in Haskell ensures victory
>>
for x in range(100):print(x%3//2*'Fizz'+x%5//4*'Buzz' or x+1)
>>
File: image.jpg (102KB, 960x1248px) Image search: [Google]
image.jpg
102KB, 960x1248px
i=0
touch Maki #inappropriately
ln Maki 'a cute'
while [[ Maki -ef 'a cute' ]]; do
echo "$((i+1))\n$((i+2))\nFizz\n$((i+4))\nBuzz\nFizz\n$((i+7))\n$((i+8))\nFizz\nBuzz\n$((i+11))\nFizz\n$((i+13))\n$((i+14))\nFizzBuzz"
i=$((i+15))
done
>>
>>56398788
(Print["Fizz"];Print["Buzz"];Print["FizzBuzz"];#0[])&[]

Just try running it ;^)
>>
I'm crap at this. C.

void FizzBuzz(int x) {
while (x % 3 == 0) {
while (x % 5 == 0) {
printf("FizzBuzz\n");
return;
}
printf("Fizz\n");
return;
}
while (x % 5 == 0) {
printf("Buzzz\n");
return;
}
printf("%d\n", x);
}

int main() {
int x;
char string[9];
for (x = 1; x < 101; x++) {
FizzBuzz(x);
}
}
>>
>>56398788
@echo off
:1
color 0a
echo Fizz Buzz
color 1b
echo Fizz Buzz
color 2c
echo Fizz Buzz
goto 1
>>
>>56398788
count = 0
while (count < 101):
if (count % 5) == 0 and (count % 3) == 0:
print "FizzBuzz"
count = count +1
elif (count % 3) == 0:
print "Fizz"
count = count + 1
elif (count % 5) == 0:
print "Buzz"
count = count +1
else:
print count
count = count + 1
>>
File: 1461416155144.png (139KB, 294x256px) Image search: [Google]
1461416155144.png
139KB, 294x256px
>>56405789
>i don't know how to read
>>
isit (n%15 == 0) printf("FizzBuzz");
else isit (n%3 == 0) printf("Fizz");
else isit (n%5 == 0) printf("Buzz");
>>
File: 0eaabf15085b1892be158edafdf57570.jpg (130KB, 1200x630px) Image search: [Google]
0eaabf15085b1892be158edafdf57570.jpg
130KB, 1200x630px
// http://en.wikipedia.org/wiki/Precomputation
var vals = [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fizz", 28, 29, "FizzBuzz", 31, 32, "Fizz", 34, "Buzz", "Fizz", 37, 38, "Fizz", "Buzz", 41, "Fizz", 43, 44, "FizzBuzz", 46, 47, "Fizz", 49, "Buzz", "Fizz", 52, 53, "Fizz", "Buzz", 56, "Fizz", 58, 59, "FizzBuzz", 61, 62, "Fizz", 64, "Buzz", "Fizz", 67, 68, "Fizz", "Buzz", 71, "Fizz", 73, 74, "FizzBuzz", 76, 77, "Fizz", 79, "Buzz", "Fizz", 82, 83, "Fizz", "Buzz", 86, "Fizz", 88, 89, "FizzBuzz", 91, 92, "Fizz", 94, "Buzz", "Fizz", 97, 98, "Fizz", "Buzz"];
for(var i=1, len=res.length; i<len; i++){
console.log(res[i]);
}
>>
>>56403002
Maki Maki gimme that faki
>>
>>56405820
Good one.
>>
File: IMG_20160829_222514_HDR.jpg (2MB, 3456x4608px) Image search: [Google]
IMG_20160829_222514_HDR.jpg
2MB, 3456x4608px
>>56405820
Kek
>>
>>56398788
>>56399548
who this cute
>>
Perl
for (1..100) {
while ($_ % 3 == 0) {
print "fizz";
last;
}
while ($_ % 5 == 0) {
print "buzz\n";
last;
}
print "\n";
}
>>
>>56405926
ah bugger, buzz\n was just meant to be buzz
>>
>>56405820
kek
>>
>>> fuck = ['']*101
>>> for i in range(3,101,3):
... fuck[i] += 'fizz'
...
>>> for i in range(5,101,5):
... fuck[i] += 'buzz'
...
>>> for i in range(1,101):
... print fuck[i] or i
...
>>
fn main() {
for i in 1..101 {
match (i % 3, i % 5) {
(0,0) => println!("FizzBuzz"),
(0,_) => println!("Fizz"),
(_,0) => println!("Buzz"),
_ => println!("{}", i),
}
}
}
>>
use std::io::stdio::flush;
use std::io::timer::sleep;
use std::thread::Thread;
use std::time::duration::Duration;

fn main() {
let counter = Thread::spawn(|| -> () {
let mut i = 0u;
loop {
i = i + 1;
print!("\n{}", i);
flush();
sleep(Duration::seconds(1));
}
});

let fizzbuzz = Thread::spawn(|| -> () {
loop {
print!("\rfizzbuzz");
flush();
sleep(Duration::seconds(15));
}
});

let buzz = Thread::spawn(|| -> () {
loop {
print!("\rbuzz");
flush();
sleep(Duration::seconds(5));
}
});

let fizz = Thread::spawn(|| -> () {
loop {
print!("\rfizz");
flush();
sleep(Duration::seconds(3));
}
});

let _ = counter.join();
let _ = fizzbuzz.join();
let _ = buzz.join();
let _ = fizz.join();
}
>>
import numpy as np
import tensorflow as tf

NUM_DIGITS = 10


def binary_encode(i, num_digits):
return np.array([i >> d & 1 for d in range(num_digits)])


def fizz_buzz_encode(i):
if i % 15 == 0: return np.array([0, 0, 0, 1])
elif i % 5 == 0: return np.array([0, 0, 1, 0])
elif i % 3 == 0: return np.array([0, 1, 0, 0])
else: return np.array([1, 0, 0, 0])

trX = np.array([binary_encode(i, NUM_DIGITS) for i in range(101, 2 ** NUM_DIGITS)])
trY = np.array([fizz_buzz_encode(i) for i in range(101, 2 ** NUM_DIGITS)])


def init_weights(shape):
return tf.Variable(tf.random_normal(shape, stddev=0.01))

def model(X, w_h, w_o):
h = tf.nn.relu(tf.matmul(X, w_h))
return tf.matmul(h, w_o)

X = tf.placeholder("float", [None, NUM_DIGITS])
Y = tf.placeholder("float", [None, 4])

NUM_HIDDEN = 100
w_h = init_weights([NUM_DIGITS, NUM_HIDDEN])
w_o = init_weights([NUM_HIDDEN, 4])
py_x = model(X, w_h, w_o)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(py_x, Y))
train_op = tf.train.GradientDescentOptimizer(0.05).minimize(cost)
predict_op = tf.argmax(py_x, 1)

def fizz_buzz(i, prediction):
return [str(i), "fizz", "buzz", "fizzbuzz"][prediction]

BATCH_SIZE = 128

with tf.Session() as sess:
tf.initialize_all_variables().run()

for epoch in range(10000):
p = np.random.permutation(range(len(trX)))
trX, trY = trX[p], trY[p]

for start in range(0, len(trX), BATCH_SIZE):
end = start + BATCH_SIZE
sess.run(train_op, feed_dict={X: trX[start:end], Y: trY[start:end]})


print(epoch, np.mean(np.argmax(trY, axis=1) ==
sess.run(predict_op, feed_dict={X: trX, Y: trY})))

numbers = np.arange(1, 101)
teX = np.transpose(binary_encode(numbers, NUM_DIGITS))
teY = sess.run(predict_op, feed_dict={X: teX})
output = np.vectorize(fizz_buzz)(numbers, teY)

print(output)
>>
>>56402490
It does...
>>
#include <stdio.h>
#include <stdlib.h>

#define FIZZBUZZ_CASE(term) case term: printf("FizzBuzz"); break
#define FIZZ_CASE(term) case term: printf("Fizz"); break
#define BUZZ_CASE(term) case term: printf("Buzz"); break
#define EMPTY_CASE(term) case term:
#define NORMAL_CASE(term) case term: printf("%d", i); break

int main(void)
{
int i;
for (i = 1; i <= 100; i++)
{
int j = i;
while (j - 15 >= 0) j = j - 15;

switch (j)
{
FIZZBUZZ_CASE(0);
EMPTY_CASE(1);
NORMAL_CASE(2);
FIZZ_CASE(3);
NORMAL_CASE(4);
BUZZ_CASE(5);
FIZZ_CASE(6);
EMPTY_CASE(7);
NORMAL_CASE(8);
FIZZ_CASE(9);
BUZZ_CASE(10);
NORMAL_CASE(11);
FIZZ_CASE(12);
EMPTY_CASE(13);
NORMAL_CASE(14);
}
printf("\n");
}

return 0;
}
>>
Enumerable.Range(0, 1000).Select(x => x % 15 == 0 ? "FizzBuzz" : x % 5 == 0 ? "Buzz" : x % 3 == 0 ? "Fizz" : x.ToString()).ToList().ForEach(WriteLine);


LINQ is the best.
>>
f = dict(zip(range(1,101), range(1,101)))
a = dict.fromkeys(list(filter(lambda n: n % 3 == 0, range(1, 101))), "fizz")
b = dict.fromkeys(list(filter(lambda n: n % 5 == 0, range(1, 101))), "buzz")
c = dict.fromkeys(list(filter(lambda n: (n % 15 == 0), range(1, 101))), "fizzbuzz")
d = {**a, **b, **c}

for key in d:
f[key] = d[key]

for key in f:
print(f[key])


It's shit! Should need python >= 3.5
>>
Javascript. Too long to post here.

http://pastebin.com/a6UevGxC
>>
PHP, 69 characters
<?while($i++<99)echo(($a=($i%3?'':fizz).($i%5?'':buzz))?$a:$i).'<p>';
>>
File: change.jpg (136KB, 1300x866px) Image search: [Google]
change.jpg
136KB, 1300x866px
>>56399374
I'm tired of seeing your tripfag 5 dollar bill ass all over this board. Something's gotta change.
>>
>>56405749
no doubt
>>
int range = 100;
for (int i = 1; i <= range; i++) {
System.out.print((i % 3 == 0 && i % 5 == 0 ? "FizzBuzz" : (i % 3 == 0 ? "Fizz" : (i % 5 == 0 ? "Buzz" : i))) + " ");
}
>>
.data
fizz_str: .asciiz "fizz\n"
buzz_str: .asciiz "buzz\n"
fizzbuzz_str: .asciiz "fizzbuzz\n"
newline_str: .asciiz "\n"

.text
ori $s0, $zero, 1
loop_st:
ori $s1, $zero, 15
div $s0, $s1
mflo $s1
mfhi $s2
ori $s1, $zero, 0
beq $s1, $s2, fizzbuzz
ori $s1, $zero, 3
div $s0, $s1
mfhi $s2
ori $s1, $zero, 0
beq $s1, $s2, fizz
ori $s1, $zero, 5
div $s0, $s1
mfhi $s2
ori $s1, $zero, 0
beq $s1, $s2, buzz
j int
fizzbuzz:
la $t0, fizzbuzz_str
jal print_s
j loop_end
fizz:
la $t0, fizz_str
jal print_s
j loop_end
buzz:
la $t0, buzz_str
jal print_s
j loop_end
int:
ori $t0, $s0, 0
jal print_i
loop_end:
addi $s0, $s0, 1
addi $s1, $s0, -100
bgtz $s1, finish
j loop_st
finish:
j finish
print_s:
li $v0, 4
ori $a0, $t0, 0
syscall
jr $ra
print_i:
li $v0, 1
or $a0, $zero, $t0
syscall
li $v0, 4
la $a0, newline_str
syscall
jr $ra


MIPS assembly. I ran it in QTSpim. Branch instructions are technically not "if" statements
>>
>>56398808
This is trash.
>>
fizzbuzz(_, 0, 0, 'fizzbuzz').
fizzbuzz(_, 0, _, 'fizz').
fizzbuzz(_, _, 0, 'buzz').
fizzbuzz(X, _, _, X). % yuno what it is

buzzmyanus(N) :-
FIZZ is N mod 3,
BUZZ is N mod 5,
fizzbuzz(N, FIZZ, BUZZ, R),
write(R), nl.

fizzmybuzz :-
foreach(between(1, 100, N), buzzmyanus(N)).
>>
>>56405848
Animefeces McGenericovna
>>
>>56404502
>using the smiley with a carat nose
>>
```
import requests
print(requests.get('https://raw.githubusercontent.com/Keith-S-Thompson/fizzbuzz-c/master/expected-output.txt').text)
```
Thread posts: 50
Thread images: 8


[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.