Fizzbuzz Thread (pic unrelated)

I know a big chunk of Holla Forums can't program. Get in here and learn something.
A Fizzbuzz is a simple test to make sure you have some grasp on programming. The rules are simple:


However you do this is up to you. Efficient, inefficient, readable or unreadable, it doesn't matter. Just post a FizzBuzz in the language you choose. Here's one in Perl: #!/usr/bin/perluse warnings;use strict;use feature "say";#Takes one number, Returns the number, or Fizz/Buzz/FizzBuzz.sub fizzbuzz { my $number = $_; return "FizzBuzz" if ($number % 15 == 0); return "Buzz" if ($number % 5 == 0); return "Fizz" if ($number % 3 == 0); return $number;}#Applies FizzBuzz to the first 100 natural numbers and prints the resultssay fizzbuzz($_) for (1..100);

Other urls found in this thread:

github.com/EinBaum/FizzBuzz
github.com/EinBaum/1488
ghostbin.com/paste/693u8
paste.ofcode.org/kSMr86PrxyuFknSZRtBWgV
ghostbin.com/paste/mbauj
github.com/Leonidaz0r/fizzbuzz-asm/blob/master/fizz.s
pastebin.ca/3605204
twitter.com/SFWRedditGifs

Here's one I wrote in C for another thread:

[Code]
#include

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

#include int main(int artgc, char** argv){ for (int i; i < 101; i++) { if (i % 3 != 0 && i % 5 != 0) { std::cout

*int argc

lua

for i=1,100 do print(i%15==0 and 'Fizzbuzz' or i%3==0 and 'Fizz' or i%5==0 and 'Buzz' or i) end

...

Just noticed that I fucked up the code tags, so I'm fixing it with this post:


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

package fizzbuzz;public class Fizzbuzz { public static void main(String[] args) { for (int i = 1; i

Not mine:
++++++++++[>++++++++++>++++++++++>->>>>>>>>>>-->+++++++[->++++++++++[->+>+>+>+>++++++++[-]+++++[-]>-->++++++[->+++++++++++[->+>+>+>+++++++>++++++++[-]++++++[-]>-->---+[-+>++[-->++]-->+++[---+>-[++[--+[->[-]+++++[---->++++]-->[->+>[.>]>++]-->+++]---+[->-[+>++++++++++-[>+>>]>[+[-]>+>>]+[++++++++.[-]]

#include #include #include #include using namespace std;int main(){ generate_n(ostream_iterator(cout,"\n"),100, [i = 1]() mutable { return i%3==0 ? ((i++)%5==0 ? "FizzBuzz" : "Fizz") : (i++)%5==0 ? "Buzz" : to_string(i-1);}); return 0;}

Simply magical.

Perfect!

FizzBuzz 100

github.com/EinBaum/FizzBuzz

kek what is this
github.com/EinBaum/1488

wew

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

C#
[code]
using System;
using System.Linq;

namespace fizzbuzz
{
class Program
{
public static void Main(string[] args)
{
int maxNum = 100;
if (!int.TryParse(args.FirstOrDefault(), out maxNum)) maxNum = 100;
for (int i = 1, tot = maxNum; i

dafuq?

It cut off my post, so here's what it's supposed to be (with a ghostbin link instead of code):

C#
>ghostbin.com/paste/693u8

People got mad at me in a separate thread for being too verbose. So this program will only print to console if debug mode is active.

Here is fizzbuzz in Common Lisp. I tested it in GNU Common Lisp 2.6.1.
(defun fizzbuzz (x) (if (= 0 (rem x 15)) (format t "FizzBuzz~%") (if (= 0 (rem x 5)) (format t "Fizz~%") (if (= 0 (rem x 3)) (format t "Buzz~%") (format t "~S~%" x))))(if (< x 100) (fizzbuzz (+ 1 x))))

php ;^)

$a = [];foreach (range(1,100) as $i) { $a[] = ($i % 3 === 0 ? ($i % 5 === 0 ? "FizzBuzz" : "Fizz") : ($i % 5 === 0 ? "Buzz" : $i));}echo implode($a, ", ");

haskell one liner
f n|m 15=t++s|m 5=s|m 3=t|True=show n where{m x=mod n x==0;s="buzz";t="fizz"}

ayy

var divisible = new RegExp(".0+$");var template = 'if(divisible.test(i.toString({0}))){output += "{1}";dirty = true;};'var mod = (x, y) => {eval(template.replace(/\{0\}/g, x).replace(/\{1\}/g, y))};var output = "1";for (var i = 2; i

Python:

#!/usr/bin/env python3def fizz_buzz(limit): for i in range(1, limit + 1): multiple_3 = i % 3 == 0 multiple_5 = i % 5 == 0 if multiple_3 and multiple_5: print("FizzBuzz") elif multiple_3: print("Fizz") elif multiple_5: print("Buzz") else: print(i)fizz_buzz(100)

OP here bumping with some Racket#lang racket;Function which applies Fizzbuzz to one number(define (fizzbuzz x) (match (list ;Making a list of 2 numbers. ([x % 5] [x % 3]) (remainder x 5) (remainder x 3)) [(list 0 0) "FizzBuzz"] ; If list = '(0 0) then x is divisible by both 5 and 3 [(list _ 0) "Fizz"] ; Underscore = something we don't care about [(list 0 _) "Buzz"] [_ x]));Apply the above function to the numbers 1 to 100(for [(i (range 1 101))] (displayln (fizzbuzz i)))

Ah, shit, that one's way better than mine.

I've been teaching myself about sockets, so I decided to make a fizzbuzz client/server. Just for fun, I made the client in C and the server in python.

Client:
#include #include #include #include #include #include #include #include #include #define BUFFERLEN 65536int main(int argc, char** argv){ int socket_id, err; struct addrinfo hints, *recvd; struct sockaddr_in serv_addr; struct hostent *server; char buffer[BUFFERLEN]; int port = -1; if(argc != 4){ printf("USAGE: %s \n", argv[0]); return 1; } port = atoi(argv[3]); if(port < 0){ puts("Specify a positive amount number"); return 1; } memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; if(err = getaddrinfo(argv[1], argv[3], &hints, &recvd)){ printf("Error finding host %s: %s\n", argv[1], gai_strerror(err)); return 1; } if((socket_id = socket(recvd->ai_family, recvd->ai_socktype, recvd->ai_protocol)) < 0){ puts("Could not create socket"); freeaddrinfo(recvd); return 1; } if(err = connect(socket_id, recvd->ai_addr, recvd->ai_addrlen)){ printf("Count not connect to host: %s\n", strerror(errno)); freeaddrinfo(recvd); return 1; } freeaddrinfo(recvd); strncpy(buffer, argv[2], BUFFERLEN); unsigned int msglen = strlen(buffer); err = write(socket_id, buffer, msglen); if(err < 0) puts("Error writing to socket"); else{ memset(buffer, 0, msglen); err = read(socket_id, buffer, BUFFERLEN); if(err >= 0) printf("Server says:\n%s", buffer); } close(socket_id); return 0;}

Server:
#!/usr/bin/env pythonimport sockethost = ''port = 50000backlog = 5size = 1024s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)s.bind((host,port))s.listen(backlog)print("Listening on port: " + str(port))while 1: client, address = s.accept() data = client.recv(size) if data: strn = data.decode() value = int(strn) print(value) output = '' for x in range(1, value + 1): if (x % 3) == 0: output = output + ' fizz' if (x % 5) == 0: output = output + ' buzz' if (x % 5) != 0 and (x % 3) != 0: output = output + ' ' + str(x) output = output + '\n' client.send(output.encode()) client.close()

cool stuff

Fizz = Fizz + 1Buzz = Buzz +1if Fizz =[3,6,,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99]: preint fizzif Buzz = [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100]: print Buzzif Fizz = Buzz: print FizzBuzz


Where my js bros at?

Module Module1 Sub Main() Dim list(100) As String Dim adder As Integer For looper As Integer = 0 To 100 Step 1 adder = adder + 1 If adder Mod 3 = 0 And adder Mod 5 = 0 Then list(looper) = "fizzbuzz" ElseIf adder Mod 3 = 0 Then list(looper) = "buzz" ElseIf adder Mod 5 = 0 Then list(looper) = "Fizz" Else list(looper) = adder.ToString End If Console.WriteLine(list(looper)) Next Console.ReadLine() End SubEnd Module


I've only recently started browsing here but I already understand the hate for Visual basic, hopefully this wont upset too many people
Thanks to for giving me the general algorithm

From memory, not tested:

for (i = 1; i++; i < 100){
if (i % 3 == 0 && i % 5 == 0){
print FizzBuzz}
elseif (i % 3 == 0){
print fizz};
elseif (i % 5 == 0){
print buzz}
else print i
}

Thats awful

12Fizz4BuzzFizz78FizzBuzz11Fizz1314FizzBuzz1617Fizz19BuzzFizz2223FizzBuzz26Fizz2829FizzBuzz3132Fizz34BuzzFizz3738FizzBuzz41Fizz4344FizzBuzz4647Fizz49BuzzFizz5253FizzBuzz56Fizz5859FizzBuzz6162Fizz64BuzzFizz6768FizzBuzz71Fizz7374FizzBuzz7677Fizz79BuzzFizz8283FizzBuzz86Fizz8889FizzBuzz9192Fizz94BuzzFizz9798FizzBuzz

works on every single 8-bit and more architecture

The more i look at it the more wrong it is. This is amazing.

10/10

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

scheme master race

(define (divides? num div) (eq? (modulo num div) 0))(define (fizzbuzz limit) (let loop ((i 1)) (when (

#include
#include

using namespace std;

void fizzbuzz(int low, int high);

int main(int argc, char* argv[])
{
if(argc != 3){
cout

fucking goddamn codetags

#include #include using namespace std;void fizzbuzz(int low, int high);int main(int argc, char* argv[]){ if(argc != 3){ cout

#include enum return_value_type { WORD, NUMBER};struct word_or_number { enum return_value_type type; union { char *word; int number; };};struct number { int number;};typedef struct word_or_number number_to_word_or_number(struct number number);void loop_through_ntwon_and_print(int *looping_variable, number_to_word_or_number *ntwon_fun, int looping_variable_min, int looping_variable_max) { struct word_or_number word_or_number; struct number number; for (*looping_variable = looping_variable_min; *looping_variable

...

Are you a mentally retarded boiler-plate pasting moron?
It does not matter what you call it in the slightest. argc is a convention. The important part is the int, which tells c that main will have, above it in the stack frame, an int. By standard, the loader makes sure that int is a count of the number of arguments.

#include #define COUNT 100#define ARGS i+1, i+2, i+4, i+7, i+8, i+11, i+13, i+14char pattern[] = "%llu, %llu, Fizz, %llu, Buzz, Fizz, %llu, %llu, Fizz, Buzz, %llu, Fizz, %llu, %llu, FizzBuzz, ";int main() { long long i; for(i = 0; i

STRONG WOMYN DEV SIMULATOR

#include #include #include #include #include using namespace std;int main(){ vector buzzwords = { "FUCKING SHITLORD!!", "MYSOGYNIST!!", "RACIST FUCKWIT!!", "FUCK THE PATRIARCHY!!", "WE NEED MORE DIVERSITY!", "I AM SO FUCKING TRIGGERED!!", "I PROGRAM HTML, CSS, AND HAVE A FRIEND WHO WRITES JAVASCRIPT. I AM A PROGRAMMER AND I AM STRONG!", "LOL LONELY VIRGIN DEVS! PATHETIC! YOU PROBABLY HAVE A SHORT DICK AND ARE AFRAID OF A PROGRESSIVE AND SEXUAL WOMAN AS A DEV!!", "BUT CRITICIZING MY CODE IS RAPE!!", "THAT'S HARRASSMENT!" }; srand(time(0)); string output = ""; for(int i = -50; i < 51; ++i){ if(i < 0 && i % 3 == 0){ output = "I'm a genderfluid trans-wymyn aromatic demilich fat-positive muslim persyn of color with only one left hand from sweden~~"; if(i % 5 == 0){ output += ", and this has nothing to do with anything~~!!!"; } }else if(i < 0 && i % 5 == 0){ output += "and this has nothing to do with anything~~!!!"; }else if(i == 0){ output = "\nCan you craft software?\n"; }else{ if(i < 0){ output = to_string(i); }else{ int todays_buzzword = rand() % buzzwords.size(); output = buzzwords[todays_buzzword]; } } cout

perl
map { CORE::say $_ % 15 ? $_ % 5 ? $_ % 3 ? $_ : "fizz" : "buzz" : "fizzbuzz" } 1 .. 100;

W-what have you done...

var f="f",u="i",c="z",k="z",co="bu";for(var i=1;i

kek

this is too easy that it is stupid. It is just a loop and check the remainder. You need to be not know nothing about programming to not be able to do this.

[code]
public class StupidShit {

/**
* @param args the command line arguments
*/
void print(String shit)
{
System.out.println(shit);
}
public void looper(int times)
{
times += 1;
if (checkEqualZero(remainder(times , 3))&&checkEqualZero(remainder(times , 5)))
{
print("FuzzBuzz");
}
else if (checkEqualZero(remainder(times , 5)))
{
print("Fizz");
}
else if (checkEqualZero(remainder(times , 3)))
{
print("Buzz");
}
else
{
print(Integer.toString(times));
}


if (times != 100)
{
looper(times);
}
}
int remainder(int i, int x)
{
return i % x;
}
boolean checkEqualZero (int i)
{
return i == 0;
}
public static void main(String[] args)
{
StupidShit stupid = new StupidShit();
stupid.looper(0);

}

}
[code]

fuck i never used these tags before
[code]
public class StupidShit {

/**
* @param args the command line arguments
*/
void print(String shit)
{
System.out.println(shit);
}
public void looper(int times)
{
times += 1;
if (checkEqualZero(remainder(times , 3))&&checkEqualZero(remainder(times , 5)))
{
print("FuzzBuzz");
}
else if (checkEqualZero(remainder(times , 5)))
{
print("Fizz");
}
else if (checkEqualZero(remainder(times , 3)))
{
print("Buzz");
}
else
{
print(Integer.toString(times));
}


if (times != 100)
{
looper(times);
}
}
int remainder(int i, int x)
{
return i % x;
}
boolean checkEqualZero (int i)
{
return i == 0;
}
public static void main(String[] args)
{
StupidShit stupid = new StupidShit();
stupid.looper(0);

}

}
[code]

The closing tag is [/code].

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

it's (code) and (/code) buddy... with [] brackets

Your code will not account for fizzbuzz (15 and friends).

poo in loo pajeet

alacrity command: rebuild cache

#include #include #include #include int main (int argc, char* argv[]) { if (argc != 2) { printf("It needs one number parameter\n"); return 1; } int size = atoi(argv[1]) + 1; int last = size - 2; char muh_determinism[size]; memset(muh_determinism, ' ', last); muh_determinism[0] = '*'; muh_determinism[last] = '*'; muh_determinism[last + 1] = '\n'; write(STDOUT_FILENO, muh_determinism, size); for(int i = 0; i < last; i++) { muh_determinism[i] = ' '; muh_determinism[last - i] = ' '; muh_determinism[i + 1] = '*'; muh_determinism[last - i - 1] = '*'; write(STDOUT_FILENO, muh_determinism, size); } return 0;}

#include enum e_fizzbuzzstate{ NUMBER, FIZZ, BUZZ, FIZZBUZZ};e_fizzbuzzstate p_fizzbuzztable[]{ NUMBER, NUMBER, FIZZ, NUMBER, BUZZ, FIZZ, NUMBER, NUMBER, FIZZ, BUZZ, NUMBER, FIZZ, NUMBER, NUMBER, FIZZBUZZ};const char s_fizz[] = "FIZZ";const char s_buzz[] = "BUZZ";const char s_fibu[] = "FIZZBUZZ";int main(){ for(int i = 0; i < 100; i++) switch(p_fizzbuzztable[i % 15]) { case NUMBER: printf("%d\n", i+1); break; case FIZZ: printf("%s\n", s_fizz); break; case BUZZ: printf("%s\n", s_buzz); break; case FIZZBUZZ: printf("%s\n", s_fibu); break; } }

M$ 3rdworlder detected

#includeusing namespace std;int main(){ for(int i=0;i

Fuck off

if you feel like dragging the number through the litany of if statements with zero consideration of the most likely cases occuring with no field for the compiler to optimize is better than precalc table then I wish you good luck at your webdev carreer

Broken hungarian notation.

def fizzbuzz(n = 100): lines = map(str, range(0, n + 1)) lines[::3] = ["fizz"]*(n/3 + 1) lines[::5] = ["buzz"]*(n/5 + 1) lines[::15] = ["fizzbuzz"]*(n/15 + 1) print("\n".join(lines[1:]))

BITS 16ORG 0x7c00BOOT equ 0x7c00 jmp 0:bootboot: cld xor ax, ax mov es, ax mov ds, ax mov ss, ax mov sp, BOOT xor cx, cx xor dx, dxcalc: inc dx cmp dx, 101 je halt call .test test cx, cx jz .fizzbuzz test cl, cl jz .fizz test ch, ch jz .buzz mov ax, dx call itoa jmp calc.buzz: mov si, msg_buzz call puts jmp calc.fizz: mov si, msg_fizz call puts jmp calc.fizzbuzz: mov si, msg_fizzbuzz call puts jmp calc.test: mov ax, dx mov bx, 5 div bl mov ch, ah mov ax, dx mov bx, 3 div bl mov cl, ah rethalt: cli hlt jmp haltitoa: pusha pushf lea edi, [buff_end] mov ecx, 10.loop: xor edx, edx idiv ecx add edx, 0x30 dec edi mov byte [edi], dl inc esi cmp eax, 0 jnz .loop mov esi, edi call puts mov esi, msg_space call puts popf popa retputs: pusha mov ah, 0x0e mov bx, 0x001f.puts_loop: lodsb test al, al jz .puts_done int 0x10 jmp .puts_loop.puts_done: popa retmsg_space db ' ',0msg_fizzbuzz db 'fizzbuzz ', 0msg_fizz db 'fizz ', 0msg_buzz db 'buzz ', 0buff: times 10 db 0buff_end:times 447-($-$$) db 0x00 db 0x80, 0x00, 0x01, 0x00, 0xEB, 0xFF, 0xFF, 0xFF db 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFFtimes 510-($-$$) db 0x00 dw 0xAA55

and there's this guy

for(var i =1; i

...

public class StupidShit {/*** @param args the command line arguments*/void print(String shit){System.out.println(shit);}public void looper(int times){times += 1;if (checkEqualZero(remainder(times , 3))&&checkEqualZero(remainder(times , 5))){print("FuzzBuzz");}else if (checkEqualZero(remainder(times , 5))){print("Fizz");}else if (checkEqualZero(remainder(times , 3))){print("Buzz");}else{print(Integer.toString(times));}if (times != 100){looper(times);}}int remainder(int i, int x){return i % x;}boolean checkEqualZero (int i){return i == 0;}public static void main(String[] args){StupidShit stupid = new StupidShit();stupid.looper(0);}}

paste.ofcode.org/kSMr86PrxyuFknSZRtBWgV

This was an interesting problem. The reason why it's perhaps hard for so many people is because it has a lot of "demons in the details". As in, one must have a good sense of how to manipulate strings before attempting this and as one knows someone in academia really isn't sitting their manipulating strings.

The naive' way to do this would be to some how do it without a string buffer in an attempt to find a relationship between the left spaces and the middle spaces; however, one will quickly find this becomes a major head ache. Let's break this problem down, you know that the total spaces is decreasing by two each cycle, so let's make an equation. starting spaces - numberofcycles*2 = 1, since you know you must end up with 1 spaces at the end. Ok, now one can look at the picture and know that the number of times you need to "draw" in the for loop is 4 times since 9/2 = 4 (integer division). However, the first cycle will not be used to decrease the amount of spaces; therefore, startingSpaces - (4-1)*2 = 1, solving this simple linear equations yields, starting spaces = 1 + 3*2.

The rest should be pretty self explanatory, just be careful of off by one errors when writing the code. ALSO USE A STRING BUFFER!!!!

import base64import zlibdeflated = "Tc27DQMxDAPQ1NxGH+vTXpFdMkCamz6BLeBYmaZAPIHi/blvOK7v/9k5USfsSuR8xCC+46kDknNpGqtCjeYa0xe0n7kJbGhj2xLGuo/uBifdAz66s74Ui/U1+ios0kMQowfrkQjWc/Q0JOkZyNGT9VIU6zV6FYr0FvTozXonmvXXDw=="print zlib.decompress(base64.b64decode(deflated), -15)

echo H4sIAK7sNFcCA03Nuw3EMAwD0J7b6GN92hTZ5Qa4JtPnYAs4VqYpEE+guD/PA8f1/T07J+qEXYmcjxjEdzx1QHIuTWNVqNFcY/qC9n9uAhva2LaEse6ju8FJ94CP7qwvxWJ9jb4Ki/QQxOjBeiSC9Rw9DUl6BnL0ZL0UxXqNXoUivQU9erPeiWb9Bb19h7OdAQAA | base64 -d | gunzip

from itertools import cycle, islicefor t in islice(zip(*(cycle(range(i)) for i in (3,5,7))),1,101): print("".join((j*(not i) for i,j in zip(t,("Fizz","Buzz")))) \ or sum(i*j for i,j in zip(t,(70,21,15)))%105)

oh my fucking god im retarded

i wrote this at 2 AM, looked at the first 5 returns and was like "good enough"
for(int i = 1; i

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

...

Just for the fun of being obscure, here's squirrel:

local function println(string) { print(string + "\n");}local function range(from, to) { while (from

This far in the thread and no gross C++ abuse of templates yet? I'm disappointed in you all.

Here we go, done with no function parameters at all.

#include template struct fb { static void call() { std::cout

I don't understand the "!=0" part.

It means that i isn't divisible by 3 and isn't divisible by 5.

Why can't i just do:

if(!i % 3 && !i % 5)

! has a higher precedence than %, which has a higher precedence than &&, so that's equivalent to this:
if(((!i) % 3) && ((!i) % 5))
Any value that's not 0 is considered true, so for all i from 1 to 100, !i equals 0. Therefore:
if((0 % 3) && (0 % 5))
The remainder of 0 / 3 is 0, and the remainder of 0 / 5 is 0, so that's equivalent to
if(0 && 0)
0 is false, so 0 && 0 is false, so
if(0)

ooo is this a choose your own adventure game :D lets go for worst end.

...

Good luck on first grade, gotta reinforce that phrasing.

Try (zero? n) instead.

[code]
for x in range(0, 100):
if x % 15 == 0:
print "fizzbuzz"
elif x % 5 == 0 :
print "buzz"
elif x % 3 == 0:
print "fizz"
else:
print x
[\code]

How to improve it?

for x in range(0, 100): if x % 15 == 0: print "fizzbuzz" elif x % 5 == 0 : print "buzz" elif x % 3 == 0: print "fizz" else: print x

function form:
def fizzbuzz(max): for x in range(0, max + 1): if x % 15 == 0: print "fizzbuzz" elif x % 5 == 0 : print "buzz" elif x % 3 == 0: print "fizz" else: print xfizzbuzz(100)

That's not an interesting way to use functions. It doesn't add any value, you just put your entire program in a function. This is better:
def fizzbuzz(n): if n % 15 == 0: return "fizzbuzz" elif n % 5 == 0: return "buzz" elif n % 3 == 0: return "fizz" else: return nfor x in range(1, 101): print fizzbuzz(x)
If you use functions like that your code becomes more flexible. You can fizzbuzz a number without printing it, so you can do other things with it. For example:
def fizzbuzz(n): if n % 15 == 0: return "fizzbuzz" elif n % 5 == 0: return "buzz" elif n % 3 == 0: return "fizz" else: return nx = input("What is your number? ")print "Your number is: " + str(fizzbuzz(x))

The first example in C was nice.
[code]
for x in range(0, 100):
if x % 3 == 0:
print "fizz"
if x % 5 == 0 :
print "buzz"
else:
print x
print("\n")
[\code]

Ayy thanks man, I'm still learning.
Should you add an if statement after the input using .isalpha to be sure the person only inputs numbers?

A check like that is a good idea. But not with .isalpha(), because .isalpha() checks if all characters in the string are letters. "abc".isalpha() returns True, "abc123".isalpha() returns False, "!@#".isalpha() returns False. Instead, reject the input if .isdigit() returns False.

You could do this instead:
try: x = int(input("What is your number? "))except ValueError: print "Not a number" exit()
If the input can't be converted to an int, int() throws a ValueError, which causes the second block of code to be executed. There are downsides to that. If the try: block is long and has multiple places it could throw an exception, you might end up skipping code without wanting to or being aware of it. I'd use a simple check with .isdigit() for this.

have some UE4Blueprint in the form of pic related

Text for the nodes: ghostbin.com/paste/mbauj

Is there any discernable difference between what I did and what this fellow did?

Powershell
1..100|%{(('Fizz'*!($_%3)+'Buzz'*!($_%5)),$_|sort)[1]}

I wrote this for linux like a year ago, tried to be as short as possible.

github.com/Leonidaz0r/fizzbuzz-asm/blob/master/fizz.s

Nice, 64-bits!

Here's "optimized" version - 182 bytes (512 bytes master boot record)

pastebin.ca/3605204

Build & test (nasm is fine too)

yasm -fbin boot.asm -o f.img -l boot.lst
qemu-system-i386 -fda f.img -monitor stdio

Running is master boot record is actually pretty neat
Nice one

Written in Bash. It makes use of /usr/bin/seq, but it can be re-arranged to avoid that if need be.

#!/bin/bashfor i in $(seq 1 100); do bits=$(($i % 3)) bits="$bits"$(($i % 5)) case $bits in 00) echo "fizzbuzz" ;; 0*) echo "buzz" ;; *0) echo "fizz" ;; *) echo "$i" ;; esacdone

If you're writing in bash there's no reason to use seq. Bash has that functionality built-in. Instead of $(seq 1 100), use {1..100}.

Hey I didn't know that. Thanks for cluing me in fam.

Put in the change and also corrected since I had my fizzes and my buzzes backwards

#!/bin/bashfor i in {1..100}; do bits=$(($i % 3)) bits="$bits"$(($i % 5)) case $bits in 00) echo "fizzbuzz" ;; 0*) echo "fizz" ;; *0) echo "buzz" ;; *) echo "$i" ;; esacdone

in Java, similar to the one that another user made
public class FizzBuzz{ public static void main(String[] args){ for (int i=0; i

I just started learning about programming in general. I began with C99 first:

#include int main(){ for (int cnt = 1; cnt

You have some style issues that make your code harder to read.

"i" is generally accepted as a name for a counting variable, so it's a better option here than "cnt".

You don't need to use braces around a single line of code. These are equivalent: if (i == 0){ printf("Hello\n");}if (i == 0) printf("Hello\n");

The == operator has a very low precedence, so you don't need to put parentheses around the % operation. And && has an even lower precedence, so you don't need to put parentheses around the things it checks either. These are equivalent: if ( ((cnt % 3) == 0) && ((cnt % 5) == 0) )if (cnt % 3 == 0 && cnt % 5 == 0)

Behold:#include #include int main(int argc, char *argv[]){ for(int i = 0; i < 100; ++i) printf("%s\n", get_line(i)); return 0;}char *get_line(int i){ static char Buffer[32]; sprintf(Buffer, "%i", i); switch(i % 15) { case 0: return "FizzBuzz"; case 3: case 6: case 9: case 12: return "Fizz"; case 5: case 10: return "Buzz"; default: return Buffer; }}

I know, but for some reason my professor insists on me using something a bit more detailed, like "cnt" (counter).

I know too, I just wrote it that way to make it easier for me to read. I still haven't fully memorized the precedences.

You'll get used to the precedences more quickly if you start using them.

Another alternative is to use ii instead of i.

Also I recommend you use an unsigned value instead of an int for the counter value.

you may not *need* to, but you always should

Brainfuck, 400 Bytes
+[+[+>--[>-->-->--->++++>++++>>----->>>+++++>>>>+++>>-+]>+++[-][-->+[->+]>+>+[-]++++++++++-[>+>>]>[+[-]>+>>]

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

Brainfuck, 292 Bytes
-[++>+[+]>[>++>+++>---->------->+++[-]>>>++++++>->-----[> >> +> -- [+ ++> +< > >+]>> >+[>+ >+[ >+ +++ ++++++ - [>+>>] >[ +[ -< +>]> +>> ]<

This is nice.

...

...

From where does all this phrase come from? And what does it mean?

I am bad. It's been too long. Made it in Python.

def fizzbuzz(): for i in range(100): if (i+1)%5 == 0 and (i+1)%3 == 0: print("Fizzbuzz") elif (i+1)%3 == 0: print("Fizz") elif (i+1)%5 == 0: print("Buzz") else: print(i+1)fizzbuzz()

Instead of adding 1 to i each time you access it, just start your counter at 1 instead

def fizzbuzz(): for i in range(1,101): if (i)%15 ==0: print("Fizzbuzz") elif (i)%3 == 0: print("Fizz") elif (i)%5 == 0: print("Buzz") else: print(i)fizzbuzz()

Here's one in C#.

[code]
class Program
{
static void Main(string[] args)
{
for (int x = 1; x

[code]

[code]

posted on my iPhone :^3

[code]



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

[code]

Because fuck you!

package mainimport "fmt"func startNumberService() chan int { numberOut := make(chan int) go numberService(numberOut) return numberOut}func numberService(numberOut chan int) { for i := 1; i

fb li { padding-left: 16px } li:nth-child(3n), li:nth-child(5n) { list-style: none } li:nth-child(3n):before { content: "fizz"; } li:nth-child(5n):before { content: "buzz" } li:nth-child(15n):before { content: "fizzbuzz" }

:^)

ok seriously though how do you use code tags is it [like this?] like this[code] [code]like this? the FAQ is so fucking vague about it

[/code]

I know, but I like it pretty and conventional.

for(var i = 1; i

Haskell
main :: IO ()main = do mapM_ (fizzPrint) [1,2..100] where fizzPrint :: Int -> IO () fizzPrint x | ((mod x 5 == 0) && (mod x 3 == 0)) = putStrLn "FizzBuzz" | (mod x 5 == 0) = putStrLn "Buzz" | (mod x 3 == 0) = putStrLn "Fizz" | otherwise = putStrLn (show x)

#include void main(void){ int i = 0; unsigned char fzd = 0, fzd2 = 0; while (i++ < 100) { if (fzd = !(i % 3)) printf("fizz"); if (fzd2 = !(i % 5)) printf("buzz"); if (!(fzd | fzd2)) printf("%d", i); printf("\n"); }}

#include using namespace std;void main(int artgc, char** argv){cout

Woops, didn't compile, I forgot this: ;

I see what you're going for by omitting the loop and pre-baking the outputs, but I'm quite sure that using write() over cout would be more efficient.

It refers to saying stupid social justice garbage, especially obscure concerns or impractical demands, to show off how idealistic and sheltered you are.

>>>/g/

fuck off and get cancer, cunt.

Python 3
i = 0while i < 100: i += 1 if i % 3 == 0 and i % 5 == 0: print('FizzBuzz') elif i % 3 == 0: print('Fizz') elif i % 5 == 0: print('Buzz') else: print(i)

You're confusing Holla Forums with /g/ OP.
Unlike /g/ we are miles away from fizzbuzzing and searching for the best antivirus software.

: fizzbuzz101 1 ?do0i 3 mod 0 = if ." fizz" 1+ theni 5 mod 0 = if ." buzz" 1+ then0 = if i . thencrloop;fizzbuzzbye

Where are we, exactly?

Nice trips doe.

You can never make too many fizzbuzzes though, it's employed as a standart test for lots of programming jobs for a reason.

In other news I tested this on a PPC Macintosh and it works in OpenFirmware.

#include int main(){ int i; int print = 0; for (i = 1; i

package fizzbuzz;public class Fizzbuzz { public static void main(String[] args) { for (int i = 1; i

I shaved off a few lines and also made it so each printed number doesn't take up a whole line to itself.

n = 1while n != 101: if n % 15 == 0: print('fizzbuzz'), elif n % 3 == 0: print('fizz'), elif n % 5 == 0: print('buzz'), else: print (str(n)), n = n + 1

4D

C_LONGINT($i)C_TEXT($tOutput)For ($i;1;100) If (Mod($i;3)=0) $tOutput:="Fizz" End if If (Mod($i;5)=0) $tOutput:=$tOutput+"Buzz" End if If ($tOutput="") $tOutput:=String($i) End if ALERT($tOutput)End for