FizzBuzz

Post your FizzBuzzes in a language of your choice, mine's incoming in a minute

Attached: 1520649955373.jpg (722x420, 65K)

Other urls found in this thread:

github.com/kmltml/oxidation/blob/master/examples/fizzbuzz.ox
nadesi.com/v3/storage/show.php?app_id=129
en.wikipedia.org/wiki/Brainfuck
twitter.com/NSFWRedditGif

HolyC
I64 i;

for(i=1; i

Attached: vimfizzbuzz.webm (1024x768, 741K)

MIT/GNU Scheme:
(for-each (lambda (n)
(cond
((= (modulo n 15) 0) (display "FizzBuzz"))
((= (modulo n 3) 0) (display "Fizz"))
((= (modulo n 5) 0) (display "Buzz"))
(#t (display n)))
(newline))
(iota 100 1 1))

use std::io::{self, BufWriter, Write};

fn fizz(n: u32, w: &mut W) -> bool {
if n % 3 == 0 {
write!(w, "Fizz").unwrap();
true
} else {
false
}
}

fn buzz(n: u32, w: &mut W) -> bool {
if n % 5 == 0 {
write!(w, "Buzz").unwrap();
true
} else {
false
}
}
fn fizz_buzz(n: u32) {
let _stdout = io::stdout();
let mut stdout = BufWriter::new(_stdout.lock());
for i in 0..=n {
if fizz(i, &mut stdout) | buzz(i, &mut stdout) {
stdout.write(b"\n").unwrap();
} else {
write!(&mut stdout, "{}\n", i).unwrap();
}
}
}

fn main() {
fizz_buzz(100);
}

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

4"fizzbuzz"[[^^>][$;,1+]#%%]p:
[$.][8 4p;!][12 8p;!][12 4p;!]3:2:1:0:
0[1+$101

c++
#include
#include

std::string fizzbuzz(int x)
{
std::string out = "";
int fizz{3};
int buzz{5};

if (x%fizz==0)
{
out=out+"fizz";
}
if (x%buzz==0)
{
out=out+"buzz";
}
if (out=="")
{
printf("%i",x);
}
return out;
}

int main()
{
int x{0};
do
{
x=x+1;
std::cout

Brainfuck. Instruction pointer has to wrap:
++++++++++[-]>++++++++++[-]>++++++++++[-]+
>+[-]+>+[-]+>+[
-]+++>+>+>+[-]+>+[-]>+[-]>>>>>>>>>>>>>>++
>+[-][[-]

All this time lurking and hearing about fizzbuzz and not googling it and thinking it's some elaborate coding task... It's just a few modulus expressions?

It's a smoke test originally designed to weed out hiring candidates who cannot program at all.

There are a lot of those.

Ah. Like the "test" I was given in which there's a page of instructions and the first instruction is to "read all the instructions" and the last instruction is "disregard all previous instructions and turn the paper in with just your name and date"

Yes, it's used to weed out Pajeets and other fucktards like the ones claiming to have "5 years industry experience", who only copy-pasted from StackOverflow

Jesus fuck people.
Writing on my phone without aid of a compiler, don't complain about tiny errors:
Console.Write(string.Join('\n', Enumerable.Range(1, 100).Select(x => (x % 15) == 0 ? "fizzbuzz" : (x % 3) == 0 ? "fizz" : (x % 5) == 0 ? "buzz" : x)));


Glorious C#. Linq is always the answer.

for(int i = 0; i < 6969; i++) {
string s;
if(i & 1) {
s += i % 5 != 0 ?: "buzz";
cout

Here's this program in an imaginary variant of DUP that had word operators instead of symbol soup. It's pretty straightforward.

{ store the string fizzbuzz from 4 to 12 }
4 "fizzbuzz"

{ ( pend pstart --> ) print string }
[[over over >] [dup fetch , 1 +] while drop drop] P store

{ print as a number }
[dup .] 0 store

{ print substrings of fizzbuzz}
[8 4 P fetch !] 1 store
[12 8 P fetch !] 2 store
[12 4 P fetch !] 0 store

{ main loop }
0
[1 + dup 101

This is probably the kind of test where it gets more complex if you do it right.

you know, like :
>OK, now do it for -100 to 100
>Now to some big ass number
>make it go up to N, where N is user input and the user is a retard, what can we do ?
>Let's say i have a **char array where everything is either "Fizz","Buzz","FizzBuzz" or numbers as chars. How do i check if this is what our function could output ?
>Our IT guy is scared of iterators, pointers or whatever, do it again without those.

Attached: 4427-full.png (137x103, 32K)

I think the '\n' needs to be double quotes, the final x needs a .ToString(), and missing a closing parentheses.

Here's my Javascript smallest - fizz - buzz attempt from a while back, enjoy skids:

for(int i =0; i < 6969; i++) {
console.log((i%3?'':'fizz')+(i%5?'':'buzz')||i);
}

Ah fuck I forgot you have to print out the numbers in between. I'm a brainlet, fixed edition

for(int i = 0; i < 6969; i++) {
string s;
if(i & 1) {
s += i % 3 != 0 ?: "fizz";
s += i % 5 != 0 ?: "buzz";
cout

Shouldn't != 0 be == 0?

>String.Join 100 times

Fuck's sake user use a buffer or something

Attached: 170706-exorcism-popularity-feature.jpg (618x410, 76K)

Also, you print numbers even if you've already printed "fizz" or "buzz."

God damn I'm being such a faggot today

Thanks user, change that last cout to the above cout and itl work then.

i % 3 != 0 ?: "fizz";

Is the same as

i % 3 == 0 ? "fizz":"";

C++
#include

void fizzbuzz(){
auto i = 0;
auto fizz = [&](){!(i % 3) ? (std::cout

Check again. String.join is called once across the collection. Internally it just copies memory.

QBASIC
FOR N = 1 TO 100
IF N MOD 15 = 0 THEN
PRINT "FizzBuzz"
ELSE IF N MOD 3 = 0 THEN
PRINT "Fizz"
ELSE IF N MOD 5 = 0 THEN
PRINT "Buzz"
ELSE
PRINT N
END IF
NEXT N

My 7th grade science teacher did that.

can you explain the first part of the third line?

[&]()

I've never seen this sort of syntax in C++.

sounds like something i would do

for(var i = 1; i

that's a lambda

#include
#include
#include

int main()
{

std::string buffer;
std::vector fizz = { 70, 105, 122, 122 };
std::vector buzz = { 66, 117, 122, 122 };

for (int i = 1; i

English
Say you have a set of integers, ranging from one to one hundred. For each number, you'll want to determine its factors. If five is a factor of said number, say "Buzz". If three is a factor, say "Fizz". Alternatively, if both three and five are factors, say "FizzBuzz".

>if (i % 3 && i % 5 == 0)
3 needs == 0

It's a lambda (anonymous) function. The [&] indicates that we are capturing any local variables by reference and the () just means that no parameters are being passed to the function.

best FizzBuzz was Tab Soda I am so sad it's gone. Next best FizzBuzz I like is probably Dr. Pepper

Attached: soda-tab-2.jpg (500x608, 235K)

import System.IO
main :: IO()
main =
mapM_ (putStrLn . fun) [1..100]
fun x
| (mod x 15) == 0 = "FizzBuzz"
| (mod x 3) == 0 = "Fizz"
| (mod x 5) == 0 = "Buzz"
| otherwise = show x

I was trying to inline that function as an anonymous function but couldn't find how to do it with guards too. I am kinda new to Haskell, does anyone know a way to make it one line?

you just copied my javascript one liner from above and separated it out like a complete faggot

reposting my glorious block you skid

for(int i =0; i < 6969; i++) {
console.log((i%3?'':'fizz')+(i%5?'':'buzz')||i);
}

Holy shit. I'm white boarding this next time.

Perl:
perl -e 'say "Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100'
C:
//main blah blah
int i;
for (i = 0; i < MAX; i++) {
printf("%d\n);
if (i % 3) printf("Fizz");
if (i % 5) printf("Buzz");
printf("\n");
}
//etc

Ahh piss.
printf("%d\r");

Kinda important distinction

>disgusting ternary abuse
>glorious

#lang racket/base

;PositiveInteger -> Void/Display
(define (fizzbuzz n)
(let loop [(i 1)]
(let [(fizz? (= (remainder i 3) 0))
(buzz? (= (remainder i 5) 0))]
(cond
[(and fizz? buzz?) (printf "FizzBuzz!\n")]
[fizz? (printf "Fizz!\n")]
[buzz? (printf "Buzz!\n")]
[else (printf "~a\n" i)]))
(if (< i n)
(loop (add1 i))
(void))))
(fizzbuzz 100)

being able to name a let is pretty neat

Explain this

>ternary abuse
and you praise the fags doing %15 in here
dont hate just because you cant understand it

what an ugly language

Don't project dumbass

kek all these fucking idiots outputting to the console on every iteration. Do you retards have any idea how expensive synchronous console writes are?

It's mostly self-explanatory. A "let" creates a local binding for some variables (which can be data types or functions themselves); if I hadn't named the first let, I could've used a single let* for all three variables i, fizz?, and buzz?. Since the first let binding is named loop, I can call it like a procedure, e.g. (loop 2) or (loop 100), where the variables will be set in order of the ones in the binding -- in the examples, i is set to 2 or 100.

Besides that, a goal was to only calculate the remainders by 3 and 5 only once per "i" iteration, so they get temporarily stored as booleans in fizz? and buzz?. Then, of course, the fizz/buzz/"i" printing happens. printf, by the way, is pretty neat and cooler than commonly-used "display" in Racket and other Lisps, since you can add format escapes for arguments as you would in C/etc.. That explains the ~a in the last printf.

The program then exits the inner unnamed let binding (although it doesn't have to, due to the quirks of "let"); then we do a test to see if we're at the end of the loop. That "if" is actually not very good, as outright returning void is kinda gross; I'd be better off using the "unless" syntax.

The ";PositiveInteger -> Void/Display" line is just a comment for my own reading and isn't a typing requirement from Racket. "#racket/base" is mostly for speed, since this doesn't require any non-base Racket procedures.

please no bully. I am still a scrubby Racketeer.

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

1 :i
(i 100

>Javascript
>int
You had one job.

github.com/kmltml/oxidation/blob/master/examples/fizzbuzz.ox

What language is that?

retard here
in C do you solve this problem with memory allocations? isn't it just as cumbersome codewise and expensive as console logs?

since when C++ got lambda?
never touch C++ since 1995.

this code only write once to console

var then

c++11

Not even the shortest
for(i=0;i++

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

ФиззБaзз

i like it

nadesi.com/v3/storage/show.php?app_id=129

カウンタを1から100まで繰り返す。
カウンタを15で割った余り。
もし、それが0ならば、「フィズバズ」と表示。
違えば、
カウンタを5で割った余り。
もし、それが0ならば、「バズ」と表示。
違えば、
カウンタを3で割った余り。
もし、それが0ならば「フィズ」と表示。
違えば、カウンタを表示。

No. Writing to the standard output is an order of magnitude more expensive than memory allocation. For 1-100 just buffering the entire output then sending it all at once is perfectly acceptable. If you expect to have to print 1-1000000 then maintaining an output buffer and flushing when it gets full is a reasonable solution. In C# you can get this by using streams.

A teacher tried it on my class in high school. Not a single student fell for it. The teacher almost looked like she was going to cry afterward.

UnrealScript
class FizzBuzzCommandlet extends Commandlet;

event int Main(string Parms)
{
local int i;
local string S;

while(i++ < 100)
{
S = "";
if(i % 3 == 0)
S $= "Fizz";
if(i % 5 == 0)
S $= "Buzz";
Log(Eval(S=="",i,S));
}
return 0;
}

I wrote both of those posts.

for = flip map

fb :: (Show a, Integral a) => a -> [[Char]]
fb n =
let
eval x
| mod x 15 == 0 = "FizzBuzz"
| mod x 3 == 0 = "Fizz"
| mod x 5 == 0 = "Buzz"
| otherwise = show x
in
for [1..n] eval


not optimized but readable

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

Perl 6
say "Fizz"x$_%%3~"Buzz"x$_%%5||$_ for 1..100

This is why Python is the best language for 99.9% of the cases

I dont have to, I'm CFO of your shitty tech startup. Cant wait to get hired to a real company

I took part of your syntax
main :: IO()
main = mapM_ (
putStrLn . \x -> case () of
_ | mod x 15 == 0 -> "fizzbuzz"
| mod x 5 == 0 -> "buzz"
| mod x 3 == 0 -> "fizz"
| otherwise -> show x
) [1..100]

Seriously, what is this?

I use StringBuilder if I concat lots of string.

for(i=0;i

yes

Attached: fail.png (624x469, 451K)

>not knowing about brainfuck in 2018
en.wikipedia.org/wiki/Brainfuck

I remember doing this test in high school.
tfw brainlet and only I and 1 other person did it right and did nothing before reading the whole thing.

get on my level

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

Lua:
for i = 1, 100 do
local s = ""
if i % 3 == 0 then s = s .. "Fizz" end
if i % 5 == 0 then s = s .. "Buzz" end
if #s == 0 then s = s .. i end
print(s)
end

i got got in middle school by one of those

are you the same user who replied with an even smaller version of what i originally made, or are you just a guy who found that glorious line of javascript he replied to me with and decided to change it up a bit?

Fucking A user

Underrated

pretty cool

rust i think

VHDL
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity fizzbuzz is
port(
fizz : out std_logic;
buzz : out std_logic;
cout : out std_logic_vector(7 downto 0);
clk : in std_logic);
end fizzbuzz;

architecture behaviour of fizzbuzz is
signal counter : unsigned(7 downto 0);
signal mod3 : unsigned(1 downto 0);
signal mod5 : unsigned(2 downto 0);
signal f : std_logic;
signal b : std_logic;
signal fb : std_logic;
begin

fb

Attached: fizzbuzz.png (2560x275, 26K)

import fizzbuzz

holy fucking shit

> if mod3 = "10" then
mod3

1
100
15 0
"fizzbuzz"
3 0
"fizz"
5 0
"buzz"



1


Fun fact: someone made an emoji language 3 years ago called Emoji-lang, way before Emojicode.

m-muh emojis...


1
100
15 0
"fizzbuzz"
3 0
"fizz"
5 0
"buzz"



1

What is this? It's not cobol

Hirohito doesn't like emojis then. Well, can't say I disagree.

Fortran 77

i wanna fug nagatoro

print("FizzBuzz")

based