[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/g/, it is time. Provide a fizzbuzz implementation in a language
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 131
Thread images: 7
File: 486003037_640.jpg (92 KB, 640x360) Image search: [Google]
486003037_640.jpg
92 KB, 640x360
/g/, it is time.
Provide a fizzbuzz implementation in a language of your choice. Your creativity will be judged.
>>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#define LIMIT 100
#define FIZZ "fizz"
#define BUZZ "buzz"

typedef void ( * handler )( unsigned int const number );

static void fizz( unsigned int const number )
{
( void ) number;
( void ) puts( FIZZ );
}

static void buzz( unsigned int const number )
{
( void ) number;
( void ) puts( BUZZ );
}

static void fizzbuzz( unsigned int const number )
{
( void ) number;
( void ) puts( FIZZ BUZZ );
}

static void normal( unsigned int const number )
{
( void ) printf( "%u\n", number );
}

static handler const actions[ 15 ] =
{
normal,
normal,
fizz,
normal,
buzz,
fizz,
normal,
normal,
fizz,
buzz,
normal,
fizz,
normal,
normal,
fizzbuzz
};

int main( int argc, char * argv[] )
{
unsigned int i;
for( i = 0; i < LIMIT; ++i )
{
( actions[ i % 15 ] )( i + 1 );
}
return 0;
}

>>
File: 1426362604703.jpg (135 KB, 1280x853) Image search: [Google]
1426362604703.jpg
135 KB, 1280x853
>>47110909
for x in {1..100};
do
{ (( x % 5 == 0 )) && (( x % 3 == 0 )) && echo "$x fizzbuzz"; } ||
{ (( x % 5 == 0 )) && echo "$x buzz"; } ||
{ (( x % 3 == 0 )) && echo "$x fizz"; } ||
echo "$x"
done
>>
your thread is part of why this board sucks
>>
>>47110909
def fizzbuzz(start, end):
if not start:
start = int(raw_input("Start: "))
if not end:
end = int(raw_input("End: "))
for x in xrange(start, end):
if x % 15 == 0:
print "FizzBuzz"
elif x % 3 == 0:
print "Fizz"
elif x % 5 ==0:
print "Buzz"
else:
print x

if __name__ == "__main__":
import sys
if len(sys.argv) <= 1:
fizzbuzz(0, 0)
elif len(sys.argv) == 2:
fizzbuzz(sys.argv[1], 0)
else:
fizzbuzz(sys.argv[1], sys.argv[2])

Dunno if it's right, just threw it together
>>
>>47111096
Yeah, we need more apple watch and buy recommendation threads.
>>
class OpIsAFaggot{
public static main(String[] args){
for(int i=1; i<101; i++){
if(i%15==0) System.out.println("fizzbuzz");
else if(i%3 == 0) System.out.println("fizz");
else if(I%5 == 0) System.out.println("buzz");
}
}
}


>>
#include <iostream>
#include <string>
using namespace std;

int main()
{
string output[100] = {"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 (int i = 0;i > 100;i++)
{
cout << output[i] << endl;
}

return 0;
}
>>
>>47111344
Indentation and wrong capitalization is because I'm on an ipad
>>
#include <stdio.h>

int main()
{
int i = 0;

for(i=1; i<=100; i++)
{
if(i%3==0 || i%5==0)
{
if(i%3==0)
printf("fizz");
if(i%5==0)
printf("buzz");
}
else
printf("%d",i);
printf("\n");
}
return(0);
}

pls be gentle i'm new to coding =)
>>
>>47111137
def handler(i):
if not i % 15:
return "fizzbuzz"
elif not i % 5:
return "buzz"
elif not i % 3:
return "fizz"
else:
return i


if __name__ == "__main__":
for i in map(handler, xrange(1, 101)):
print(i)
>>
>>47111166
lol

comparing shit to shit is still leaving the situation shit

no more fixxbutts threads
>>
package main

import "fmt"

func main() {
for i := 1; i <= 100; i++ {
switch {
case i%15==0:
fmt.Println("FizzBuzz")
case i%3==0:
fmt.Println("Fizz")
case i%5==0:
fmt.Println("Buzz")
default:
fmt.Println(i)
}
}
}


It's Go time!
>>
>>47111347
you wrote this by hand, didn't you?
>>
>>47111453
woah, didn't know you can do runtime-check cases in go
>>
print('\n'.join(("Fizz"if i%3==0 else"")+("Buzz"if i%5==0 else str(i)if i%3!=0 else"")for i in range(1,101)))
>>
>>47110909
Here's fizzbuzz in C++11 templates: http://mathieustefani.com/2013/05/using-c-variadic-templates-to-solve-fizzbuzz-at-compile-time/
>>
File: fb.png (5 KB, 463x341) Image search: [Google]
fb.png
5 KB, 463x341
>
>>
Readable one-liner coming through
for x in range(1, 101): print("FizzBuzz" if x % 15 == 0 else "Fizz" if x % 3 == 0 else "Buzz" if x % 5 == 0 else x)
>>
>>47111511
#define _POSIX_C_SOURCE 200112L
#include <stdio.h>

#define MAX_BUF_LEN 11 /* max uint = 4294967295 */

int main( int argc, char * argv[] )
{
char buf[ MAX_BUF_LEN ] = { '\0' };
unsigned int i;

( void ) argc;
( void ) argv;

for( i = 1U; i < 101U; ++i )
{
( void ) snprintf( buf, MAX_BUF_LEN, "%u", i );
( void ) printf( "%.*s\n", ( 0 == printf( "%s%s", ( 0 == ( i % 3 )) ? "fizz" : "", ( 0 == ( i % 5 )) ? "buzz" : "" )) ? MAX_BUF_LEN : 0, buf );
}
return 0;
}

>>
in my country, we had a children game that is like fizzbuzz, but it was with the number seven, and only with the 7. you would say some word if the number is either divisible by 7, or contains the 7 (e.g. 17). i guess american children have more advanced children games. but it was always fun when someone reached 70 and then we had to count how often we had already said the word that replaced the 7, and someone would always fail hahaha

def main(x):
string = list()
for i in range(0, x+1):
current = str(i)
if i % 3 == 0:
current = "Fizz"
elif i % 5 == 0:
current = "Buzz"
elif i%3==0 and i%5==0:
current = "FizzBuzz"
string.append(current)
return "\n".join(string)


yes i know, it is shitty code, pls dont h8. im too tired for this right now, but at least it works. i think.
this is output
 
>>> main(100)
'Fizz\n1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\nFizz\nBuzz\n26\nFizz\n28\n29\nFizz\n31\n32\nFizz\n34\nBuzz\nFizz\n37\n38\nFizz\nBuzz\n41\nFizz\n43\n44\nFizz\n46\n47\nFizz\n49\nBuzz\nFizz\n52\n53\nFizz\nBuzz\n56\nFizz\n58\n59\nFizz\n61\n62\nFizz\n64\nBuzz\nFizz\n67\n68\nFizz\nBuzz\n71\nFizz\n73\n74\nFizz\n76\n77\nFizz\n79\nBuzz\nFizz\n82\n83\nFizz\nBuzz\n86\nFizz\n88\n89\nFizz\n91\n92\nFizz\n94\nBuzz\nFizz\n97\n98\nFizz\nBuzz'
>>
>>47111635
for x in range(100):print x%3/2*'Fizz'+x%5/4*'Buzz'or x+1

Golf, you can snip at least one char from that.
>>
>>47111608
>sys.stdout.write
what is this, java?
>>
>>47111948
ah crap. the fizzbuzz case should be first. either that, or i would use if statements instead of elif, so it would execute the last case regardless of what happened beforehand
>>
File: fizzbuzz.png (48 KB, 632x188) Image search: [Google]
fizzbuzz.png
48 KB, 632x188
such edge
>>
>>47110909
#include <iostream>

int main(){
for(int i = 1; i < 100; i++){
if (!(i%3)||!(i%5)){
if(!(i%3)){
std::cout << "Fizz";
}
if(!(i%5)){
std::cout << "Buzz";
}
std::cout << "\n";
}else
std::cout << i << "\n";
}
}

My first try ever
>>
>>47111988
OP here, this one is really nice.
>>
>>47111344
>java
vomit.png
>>
>fuck your creativity

#FizzBuzz
def FizzBuzz():
for char in range(1,101):
if (char%3 == 0) and (char%5 == 0):
print ("FizzBuzz")
elif (char%3 == 0):
print ("Fizz")
elif (char%5 == 0):
print ("Buzz")
else:
print (char)

FizzBuzz()
>>
>>47112255
forgot to indent oh well whatev
>>
>>47111137
>>47111410
>>47111453
>>47111635
>>47111948
>>47112255
>checking for %15

why
>>
>>47112071
what is that font?
>>
>>47112311
Hope you're kidding.
>>
fizzbuzz = fn
0, 0, _ -> "FizzBuzz"
0, _, _ -> "Fizz"
_, 0, _ -> "Buzz"
_, _, n -> n
end

fb2 = fn
n -> fizzbuzz.(rem(n,3), rem(n,5), n)
end
>>
>>47110909
foreach(range(1,100) as $i){ $o = (0 == ($i % 15)) ? 'fizzbuzz' :  (0 == ($i % 5)) ? 'fizz' : (0 == ($i % 3) ? 'buzz' : $i ) 
echo $o;
}

>>
>>47112335
disgusting code
>>
>>47112311
please grace us with your knowledge
>>
>>47111988
saved a character.
i=0;exec"i+=1;print'FizzBuzz'[i%-3&4:12&8-i%5]or i;"*100


Best fizzbuzz is and always has been random fizzbuzz:
import random
for i in range(0, 100):
if not i % 15:
random.seed(1178741599)
print [i+1, "Fizz", "Buzz", "FizzBuzz"][random.randint(0,3)]
>>
>>47112363
>>>/v/
Also not my code.
>>
>>47112311
Explain why not.
I checked for 3 and 5 but it seems better to check for 15.
>>
>>47112376
lmao
Was that seed bruteforced?
>>
>>47110934
nigger did you just use an array of function pointers to fizzbuzz?
Enterprising lunatic. 8/10
>>
>>47110934
Okay you can leave godmode now
>>
File: cute_fish.jpg (30 KB, 460x276) Image search: [Google]
cute_fish.jpg
30 KB, 460x276
>>47112322
Menlo regular size 14
>>
Can't we at least have a challenge?

fizzbuzz without division, modulus or conditionals
>>
>>47112485
That's inane.
>>
File: fizzbuzz.png (35 KB, 508x152) Image search: [Google]
fizzbuzz.png
35 KB, 508x152
>checking for %15
>being a serious programmer
>shiggy
>>
>>47112499
it's a challenge, you retard
>>
>>47112485
>>47111347
>>
>>47112504
how about you stop being an autist and tell us why it's bad you fucking retard
>>
>>47112369
#include <stdio.h>

int main(int argc, char *argv[]) {
for (int i = 1; i <= 100; ++i) {
if (i % 3 == 0) {
printf("Fizz");
}
if (i % 5 == 0) {
printf("Buzz");
continue;
}
printf("%i", i);
}
return 0;
}
>>
>>47112499
it's definitely possible
>>
>>47112526
You're fired.
>>
>>47112387
its a naive implementation
>>
>>47112526
lol
>>
>>47112405
what's the matter, not imperative enough for you?
>>
>>47112518
not him, but i think he just means that lets say python's print() function automatically starts a new line after print() is called. but you can give it a parameter so that it wont do that, and the next print() call writes on the same line.

i suck at explaining, but basically you would something like
if i%3 == 0:
print("fizz", end="")
if i%5 == 0:
print("buzz", end="")
print("\n")

so its not necessary to check for modulo 15
>>
>>47112507
>>47112530

Inane, not insane. Do you even speak English?
>>
>>47112604
uhh.. anon..
>>
>>47112485
you mean something like
>>47111347
?
do you count for loops as conditionals?
>>
>>47112504
your code only prints fizz and buzz, but it doesnt print the number if its neither divisible by 3 or 5. technically, that may not be required though
>>
>>47112485
main = mapM_ putStrLn $ zipWith ($) (cycle [show, show, const "fizz", show, const "buzz", show, show, const "fizz", show, const "buzz", show, show, const "fizz", show, const "fizzbuzz"]) [1..100]
>>
>>47112530
Not it's not retard. You can't iterate without a conditional.
>>
>>47112637
forgot about that, yeah
>>
program fizzbuzz

i=1
10 if (i .gt. 100) goto 11
if (mod(i,15) .ne. 0) goto 12
print *, 'fizzbuzz'
goto 13
12 if (mod(i,5) .ne. 0) goto 14
print *, 'buzz'
goto 13
14 if (mod(i,3) .ne. 0) goto 15
print *, 'fizz'
goto 13
15 print *, i

13 i = i + 1
goto 10
11 continue

end program fizzbuzz
>>
>>47112670

>>47112339

\_
>>
>>47112485
<?php
echo "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";
>>
>>47112695
rem is modulus. Try agian
>>
>>47112728
I mean you could easily just divide twice.
>>
>>47112746
>I mean you could easily just divide twice.
>>47112485
no division
>>
>>47112746
>divide
again see the original challenge
>>
>>47112757
shit, didn't actually read that list
>>
for i in range(1,101):
b=''
if not i%3:
b+="Fizz"
if not i%5:
b+="Buzz"
else:
b=i
print(b)
>>
>>47112727
winrar
>>
File: 1412409190892.png (46 KB, 363x364) Image search: [Google]
1412409190892.png
46 KB, 363x364
>>47112485
you could list every multiple of 3 and 5 up until it matches your number to avoid division or modulus. You'd need conditionals though.
>>
int main(void) {
int i = 1;
int j = 100;
int k = 0;
not_even_a_while:
printf("%d\n", i++); k += i / (--j);
printf("%d\n", i++); k += i / (--j);
puts("fizz"); k += (i++) / (--j);
printf("%d\n", i++); k += i / (--j);
puts("buzz"); k += (i++) / (--j);
printf("%d\n", i++); k += i / (--j);
printf("%d\n", i++); k += i / (--j);
puts("fizz"); k += (i++) / (--j);
printf("%d\n", i++); k += i / (--j);
puts("buzz"); k += (i++) / (--j);
printf("%d\n", i++); k += i / (--j);
printf("%d\n", i++); k += i / (--j);
puts("fizz"); k += (i++) / (--j);
printf("%d\n", i++); k += i / (--j);
puts("fizzbuzz"); k += (i++) / (--j);
goto not_even_a_while;
}

Really?
>>
>>47112773(You)
Sorry for that space in print
>>
>>47112789
why would you need conditionals when you can just iterate through a list
>>
>>47112799
>>>>47112773(You)
uwotm8
>>
>>47112485
fizz = [nil, nil, "Fizz"].cycle
buzz = [nil, nil, nil, nil, "Buzz"].cycle
numbers = 1..100

numbers.zip(fizz, buzz) do |n, f, b|
fizzbuzz = [f, b].join
puts(fizzbuzz.empty? ? n : fizzbuzz)
end
>>
>>47112793
Was meant for >>47112670

Obviously we're still dividing.
>>
>>47112803
>iterate
requires a conditional
>>
>>47112819
use goto statements instead
>>
>>47112311

least common multiple.

http://www.mathsisfun.com/least-common-multiple.html
>>
>>47112803
you're kind of deviating from the goal of the fizzbuzz program at that point
>>
>>47112830
no more than the proposed challenge

>>47112819
can you show me?
>>
>>47112839

>no more than the proposed challenge

>fizzbuzz without division, modulus or conditionals

okay then

echo fizzbuzz
>>
>>47112826
You could never break out of the goto without a conditional.
>>
10 GOTO /g/
20 PRINT "Fizz Buzz Thread"
30 COPY everyone's efforts
40 END
>>
 for(var i = 1; i <= 1000; i++) {
if(i % 3 === 0 && i % 5 === 0) {
console.log("FizzBuzz");
}
else if(i % 3 === 0) {
console.log("Fizz");
}
else if( i% 5 === 0) {
console.log("Buzz");
}
else {
console.log(i);
}
}
>>
>>47112807
What? I did something wrong. This space is just has to removed so code has to be like this:
for i in range(1,101):
b=''
if not i%3:
b+="Fizz"
if not i%5:
b+="Buzz"
else:
b=i
print(b)
>>
English is my language of choice.

If divisible by 3 fizz, unless divisible by 5 as well, then fizzbuzz. anything else buzz.
>>
>>47112897
>buzz,buzz,fizz,buzz ...
>>
gg
>>
>>47112632
>do you count for loops as conditionals?
no
>>
>>47112485
simple. write code to write code, and then turn in the code written by the program.

example:
for i in range(1,101):
print "print",
if not i%15:
print "Fizzbuzz"
elif not i%3:
print "Fizz"
elif not i%5:
print "Buzz"
else:
print i


outputs:
print 1
print 2
print Fizz
print 4
print Buzz
print Fizz
print 7
print 8
print Fizz
print Buzz
print 11
print Fizz
print 13
print 14
print Fizzbuzz


which you then turn in, and since it has no division mod, or conditionals, it passes.
>>
>>47112922
a 4 loop is a conditional
>>
>>47112855
it's doable. for example in C, you could create a list of 101 function pointers, where elements from 0 to 99 execute fizzbuzz(i+1) and element 100 exetuts exit(0).
then you would have to write fizzbuzz() that doesn't use division or modulus.
>>
>>47112930
yes, but [1..100].each isnt?
>>
>>47112924
for i in range(1,101):
print "print",
if not i%15:
print "\"Fizzbuzz\""
elif not i%3:
print "\"Fizz\""
elif not i%5:
print "\"Buzz\""
else:
print i

code generating code that actually works.
Whoops.
>>
>>47112922
>>47112940
even if for loop counted against the rules, we can do it without it
>>
for i in 1..100
s = ""
s += "fizz" if i % 3 == 0
s += "buzz" if i % 5 == 0

if s == ""
puts i
else
puts s
end
end
>>
#include <iostream>

using namespace std;

int main(){
cout << "1\n2\nFizz\n4\nBuzz\nFizz\7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17\nFizz\n19\nBuzz\nFizz\n22\n23\n24\nBuzz\n26\n27\n28\n29\nFizzBuzz\n";
return 0;
}

really good
>>
#include <6'2">
#include <social.skills>


find spergiest nerd on campus
pretend to be friend
take him to club
put a candyflip in his drink
record him doing cringy sperg shit
blackmail him into doing this shit and everything else for me
turn in assignment
profit

end


Worked so far.
>>
>>47112996
>social.skills
#include <lyingonananonymousimageboard.h>
end


ftfy
>>
>>47112996
error at line one: #include <6'2">
^^^^^^^^
cannot include under 6'3"
>>
>>47112940
You might as well just have a hundred print statements. The point of fizzbuzz is to prompt the user for the number they would like to count up to, not just to count to 100 every time
>>
[spoiler]It works[/spoiler]
#include <stdio.h>

int main(int c, char *v[])
{
static char S[9], *s;
static char *g;
int x, y;
if (!g)
return main((stdin = &&L, g - g + 3), (g = "fizzbuzz", (char **) g));
else if (g - (char *) v > 99)
return 0;
g++;

sprintf((s = S), "%d", (g - (char *) v));
x ^= x;
L:
x += (*s - '0');
if (*++s) goto *stdin;
// do x += (*s - '0'); while (*++s);

s = (y = (x %= 3, (*(s - 1) - '0') % 5), (char *) main);
(!(x*y)) && sprintf(S, "%.*s", 4 * (!x + !y), (char *) v + 4 * !!x);

((int (*)(int, char *[])) s)(puts(S), v);

return 0;
}
>>
>>47113135
Oops. Forgot to remove that comment
>>
string fizzubzz= "1, 2, fizz, 4, buzz... 14, fizzbuzz";
print
parse ints and add 15
print again
add 15 again
etc

done. point is cycle 1-15 and you're good. no conditionals, no division.

#rekt
>>

#include <iostream>
#include <string>

struct Fizz{
std::string f = "Fizz";
//end structure declaration
};

struct Buzz{
std::string b = "Buzz";
//end structure declaration
};

class BufferedIOFizzBuzzConfiguratorWrapperApplet{
public:
bool fetchIsFizzBuzzorFizzOrBuzz(int _n__number__input__var){

int numberContainerPacketHandler= _n__number__input__var;
if(numberContainerPacketHandler % 15 == 0){std::cout << "FizzBuzz\n";}
else if(numberContainerPacketHandler % 3 == 0){std::cout << "Fizz\n";}
else if(numberContainerPacketHandler % 5 == 0){std::cout << "Buzz\n";}

return 0;

}
int fetchWrapperAPIHandleReference(){
return 5-2;
}


void setVariablesHandlerHelperWrapper(){
setVars();
}

void setVars(){_f.f = "Fizz"; _b.b = "Buzz";}

private:

Fizz _f;
Buzz _b;
};

//end wrapper declaration

void doOtherStuff(){
for(int i = 0; i < 100; i++){
BufferedIOFizzBuzzConfiguratorWrapperApplet Handler;
Handler.fetchIsFizzBuzzorFizzOrBuzz(i);
}
}

void doStuff(){
dothings:
doOtherStuff();
goto dothings;
}

int main(){
doStuff();
return 0;
}
//end api set

>>
>>47111344
your shitty code wouldn't even compile.
>>
>>47110934
Disgusting code style, kill yourself.
>>
>>47113135
IOCCC pls go.
>>
#include <stdio.h>

void thingy(int n){
int i;
for(i = 0; i < n; i++){
if(!(i%15)){printf("FizzBuzz\n");}
else if(!(i%3)){printf("Fizz\n");}
else if(!(i%5)){printf("Buzz\n");}
else{printf("%i\n", i);}
}
printf("Done\n");
}

void main(){
thingy(100); //can't be bothered to add input...
}
>>
#include "fizzbuzz.h"

void main(){
fizzBuzz();
}
>>
>>47113059
OP here.
I believe this is how you loop in C without using for():
#include <stdio.h>
#include <stdlib.h>

#define LIMIT 100

typedef void ( * fn )( unsigned int * const i );

void operation( unsigned int * const i )
{
printf( "this does fizzbuz for %u\n", *i );
*i = *i + 1;
}

void breakout( unsigned int * const i )
{
( void ) i;
exit( 0 );
}

static fn const main_loop[ 2 ] =
{
breakout,
operation
};

int main( int argc, char * argv[] )
{
unsigned int const from_user = LIMIT;
unsigned int iterator = 0;

( void ) argc;
( void ) argv;

MAIN_LOOP:
( main_loop[ !!(iterator ^ from_user) ] )( &iterator );
goto MAIN_LOOP;

/* never reached */
return 0;
}

>>
>>47110909
https://github.com/haasn/fizzbuzz/

I am the master of fizzbuzz
>>
#!/usr/bin/python

d = { 0: lambda x: x,
1: lambda x: "Fizz",
2: lambda x: "Buzz",
3: lambda x: "FizzBuzz"}

def fizzle(x):
a, b = int(x%3==0), int(x%5==0)*2
return d[a+b](x)

for x in range(0,100):
print(fizzle(x))
>>
#include <stdio.h>
int main()
{
for (int i = 0; i++ < 100; printf("%d\n\0FizzBuzz\n\0Fizz\n"+(i%3?i%5?0:8:i%5?14:4), i));
}


Still working on shortening index selection.
>>
>>47113677
very nice
>>
>>47112855
#include <stdio.h>

int main(void)
{
static const char *s[] = { "%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" };
unsigned long p = 0x30490610;
unsigned i = 1;
volatile unsigned x;
fb:
printf(s[p&3], i++);
p = (p>>2) | ((p&3)<<28);
x = 1 / (i - 101);
goto fb;
}


// ...
94
Buzz
Fizz
97
98
Fizz
Buzz
Floating point exception (core dumped)

^)
>>
>>47110909

#import 'fizzbuzz'
fizzbuzz()
>>
>>47113725
You're going to go far, anon.
>>
Wtf is the point of fizzbuzz? It's brain dead simple.
>>
: fizz? 3 mod 0= if 1+ ." fizz" then ;
: buzz? 5 mod 0= if 1+ ." buzz" then ;
: fizzbuzz 101 1 do cr 0 i fizz? i buzz? if else i . then loop ;
>>
>>47112485

Ok, so we have a for loop, using only xor
>>47113574
Anyone has any ideas for fizzbuzz in c without conditionals, division or modulo?
>>
>>47113575
very nice.
>>
>>47113937
Now without any division (uses GNU C extensions though)
#include <stdio.h>

int main(void)
{
static const char *s[] = { "%u\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" };
unsigned long p = 0x30490610;
unsigned i = 1, x;
void *labels[] = { &&done, &&loop };
loop:
printf(s[p&3], i++);
p = (p>>2) | ((p&3)<<28);
goto *labels[!!(i^101)];
done:
return 0;
}
>>
>not formally proving your fizzbuzz

https://gist.github.com/david-christiansen/3660d5d45e9287c25a5e
>>
fizzBuzz = map fizzBuzz' [1..100]
fizzBuzz' x | fizz ++ buzz == [] = show x
| otherwise = fizz ++ buzz
where fizz = if x `mod` 5 == 0 then "Fizz" else ""
buzz = if x `mod` 3 == 0 then "Buzz" else ""
Thread replies: 131
Thread images: 7

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.