[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
FizzBuzz thread
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: 105
Thread images: 5
File: fizzbuzz.jpg (142 KB, 1600x1000) Image search: [Google]
fizzbuzz.jpg
142 KB, 1600x1000
Can we get a FizzBuzz thread going?

I'm a Ruby guy, total PHP noob, how's this for a PHP solution? Marks out of 10?

<?php

for ($i = 1; $i <= 100; $i++) {
$string = "";
if ($i % 3 == 0)
$string .= "Fizz";
if ($i % 5 == 0)
$string .= "Buzz";
if (empty($string))
$string .= $i;
echo $string . "\n";
}

?>
>>
>>54854611
0
Where is the fizzbuzz
>>
>>54854700
do you even code?
>>
>>54854700

....what? The code is literally there

If you run that code it works fine, the first fifteen lines are this:

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
>>
Shameless bump
>>
>>54854611
def fizzBuzz(i: Int): String = {
if (i % 15 == 0)
"FizzBuzz"
else if (i % 3 == 0)
"Fizz"
else if (i % 5 == 0)
"Buzz"
else
i.toString
}

(1 until 100).map(fizzBuzz _ andThen println)
>>
>not fizzbuzzing in tensorflow
>http://joelgrus.com/2016/05/23/fizz-buzz-in-tensorflow/


go to bed pajeet
>>
>>54854611

So I got this right.. you know Ruby and want to learn PHP ?

Just when you think you've seen it all..
>>
>>54854950
is that supposed to be functional?
dont use map for side-effects, use foreach.
>>
>>54854611
> if (empty($string))
> $string .= $i;

There is no need use 'empty()'

if ($string == "")


Then it should work fine.
>>
Been a while since I PHPed. Don't even know if this'll work.

<?php

class FizzBuzz
{
public static function getFizzBuzz($max)
{
$numbers = Array();

for ($i = 0; $i <= $max; $i++) {
$numbers[] = self::makeFizzBuzz($i);
}

return $numbers;
}

private static function makeFizzBuzz($number)
{
if ($number % 15 === 0) {
return "FizzBuzz";
}

if ($number % 3 === 0) {
return "Fizz";
}

if ($number % 5 === 0) {
return "Buzz";
}

return $number;
}
}

var_dump(FizzBuzz::getFizzBuzz(100));
>>
>>54854611
>employing a fucking string variable for simple number comparisons

Nice piece of bloat you coded there Ranjeep, do you work for Microsoft by any chance?
>>
I don't understand the obsession with this task
>>
I wish /g/ stopped with this fizz buzz meme already. it's literally hello world 1.01. why don't you pick something that's simple, but involves something more than a single logical branch, like the sieve of Eratosthenes
>>
>>54857422
rate

#include<stdio.h>

int main(){
int n=120,array[999],i;

// generate list of integers from 2 to n
for(i=2;i<=n;i++){
array[i-2]=i;
}
// cross every 2nd number by increments of 2, starting at 4
for(i=4;i<=n;i+=2){
array[i-2]=0;
}
// cross every 3rd number by increments of 3, starting at 6
for(i=6;i<=n;i+=3){
array[i-2]=0;
}
// cross every 5th number by increments of 5, starting at 10
for(i=10;i<=n;i+=5){
array[i-2]=0;
}
for(i=0;i<n-2;i++){
if(array[i]!=0) printf("%d\n",array[i]);
}
}
>>
File: 38572395765.jpg (1 MB, 1920x1080) Image search: [Google]
38572395765.jpg
1 MB, 1920x1080
>go to job interview
>actually get the fizzbuzz question
>>
Never done one before, but would this be correct?

void main(int argc, char * argv)
{
int iter = 0;

while (iter <= 100)
{
bool fizzed = false;
if (!(iter % 3)) {printf("Fizz"); fizzed = true;}
if (!(iter % 5)) {printf("Buzz"); fizzed = true;}
if (!fizzed) printf("%i", iter);
printf("\n");

++iter;
}

}
>>
We’re not here to do your homework. Google it you retard.
>>
 
fizzBuzz i = if null desc then show i else desc where desc = concat [label | (j,label) <- tags, 0 == rem i j] tags = [ (3,"Fizz"), (5,"Buzz")] main = mapM_ (putStrLn . fizzBuzz) [1..100]
>>
One line python reporting in :)
<CODE> for x in range(100):print"fizz"*(x%3==0)+"buzz"*(x%5==0)or x </CODE>
>>
>>54856611
>So I got this right.. you know Ruby and want to learn PHP ?

You're correct.

Yes Ruby is definitely way fucking better, but I'm NEET right now and there are more jobs in PHP.

I keep applying to PHP jobs so I should probably fucking know some PHP.

It's not my fault they don't use superior Rails

>>54856720
I suppose that's true but is there an obvious advantage? Maybe it's just because I'm used to Ruby where I would use
string.empty?
>>
import java.util.pajeet;

public class FizzBuzz {

public static void main(String[] args) {
System.out.println(pajeet.fizzBuzz(100));
}
}
>>
>>54859124
How could you fuck up such a short code? I guess this is representative of how retarded FizzBuzz circlejerkers are.
>>
>>54857272

Alright then, is this better?

<?php

for ($i = 1; $i <= 100; $i++) {
if ($i % 15 == 0) {
echo "FizzBuzz\n";
} else if ($i % 3 == 0) {
echo "Fizz\n";
} else if ($i % 5 == 0) {
echo "Buzz\n";
} else {
echo $i . "\n";
}
}

?>
>>
>>54859251
Lol
>>
>>54859272
What did i fuck up?
>>
>>54859352
it starts by printing fizzbuzz
doesn't go to 100

we'll call you
>>
>>54859418
oh haha sorry my bad here's an update
for x in range(101):print"fizz"*(x%3==0)+"buzz"*(x%5==0)or x
>>
>>54859418
>it starts by printing fizzbuzz
that's not wrong if you start counting at 0.

I'm not sure what the real FizzBuzz problem states, the other guy's implementation is correct if you view numbers from 0 to 99.

OP should have posted the wording of the FizzBuzz problem
>>
>>54859465
everyone knows the fizzbuzz problem is 1-100, people just make mistakes and then backpedal it
"i-i'm not like those other hundreds of thousands of people who apply for programming jobs and can't fizzbuzz, I s-swear! this common stupid mistake I made doesn't count!"
>>
>>54859454
I don't really see a reason to start at 1, if you would want to just do integers 1 - 100 i guess you would do range(1, 101). Sorry for the misunderstanding, been writing python as my first programming language for a week now ;). Would love some not to harsh criticism.
here's 2 functions that could be put to use in a for loop that i made up,

def fizzbuzz(x):
if x % 15 == 0:
print "FizzBuzz"
elif x % 5 == 0:
print "Buzz"
elif x % 3 == 0:
print "Fizz"
else:
print x


def fizzbuzz2(x):
if x % 5 == 0 and x % 3 != 0:
print "buzz"
elif x % 3 == 0:
if x % 5 == 0:
print "FizzBuzz"
else:
print "Fizz"
else:
print x
>>
>>54859518
People are too used to for loops beginning with i = 0
>>
>>54859548
yes, that's what the fizzbuzz test is about, your attention to detail.

lol at 4channers "almost" getting fizzbuzz right and thinking it counts, that they aren't as dumb as those other people.
>>
#include <stdio.h>

int main (void)
{
char s[42] = "FizzBuzz\0Fizz";
size_t o[4] = {15,9,4,0};
unsigned a = 4;
unsigned b = 1;

for (int i = 1; i <= 100; ++i) {
sprintf(s+15, "%d", i);
puts(s + o[(a&1)+(b&2)]);

a = (a>>1)|((a&1)<<2);
b = (b>>1)|((b&1)<<4);
}
}
>>
>>54859542
indentations fucked up sorry guys
>>
function fizzBuzz(n) {
function generate(array, n) {
if (n === 1) {
array.push(n);
return array.reverse();
}

if (n % 15 === 0) {
array.push('FizzBuzz');
} else if (n % 5 === 0) {
array.push('Buzz');
} else if (n % 3 === 0) {
array.push('Fizz');
} else {
array.push(n);
}

return generate(array, n - 1);
}

if (n === 0 || n < 1) {
return [];
}

return generate([], n);
}

console.log(fizzBuzz(100).join('\n'));
>>
I failed FizzBuzz, I admit it. I was asked that as an interview question. I studied hard for my interview but I forgot about the mod operator and totally fumbled my way through the interview. I am now the Senior Web Developer and turned out to be a great asset to the company. But you wouldn't have known that from my FizzBuzz results. I also didn't have 'Computer Science' as a Major. Couple strikes. However they took a chance on me.
Since then I've been able to interview others and I look for different things than FizzBuzz compliance. I want to see how they solve problems in general. I want to see if they have any passion for what they do. I want to see things they've developed.
>>
>>54854611
function *every(n, s) {
yield* new Array(n - 1).fill('');
yield s;
yield* every(n, s);
}


function fizzBuzz(n) {
let fizz = every(3, 'fizz');
let buzz = every(5, 'buzz');
for (let i = 1; i <= n; i++) {
console.log(fizz.next().value + buzz.next().value || i);
}
}

fizzBuzz(20);
;
>>
>>54854611

>All these FizzBuzz threads recently.

Is it college finals week or something? Do your own damn work.
>>
#include <stdio.h>

int main()
{
int i = 1;

counter:
printf("%d, ", i++);
if(i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 == 0) goto buzzer;
goto counter;

fizzer:
printf("Fizz");
if(i++ % 5 == 0) goto buzzer;
printf(", ");
if(i > 100) goto exit;
if(i % 5 == 0) goto buzzer;
if(i % 5 && i % 3) goto counter;
goto fizzer;

buzzer:
printf("Buzz, ");
if(++i > 100) goto exit;
if(i % 3 == 0) goto fizzer;
if(i % 5 && i % 3) goto counter;
goto buzzer;

exit:
return 0;
}
>>
>>54854611

>if
>if
>if

Fucking hell, sure is scrub in here.

>>54859578
Of course it did, you forgot to use a code block.
>>
Protip: If you write a FizzBuzz code that either
>Uses more than 200 modulo operations
>Isn't in a well-established programming language
>Lacks a documentation
then you will not get the job.
>>
>>54859941
Who cares. I already have a job. I'm doing these for the lulz.
>>
>>54859622
>I forgot about the mod operator
You could have easily done it without the mod operator.

for (int i = 1, fizz = 1, buzz = 1, i <= n; i++, fizz++, buzz++) {
if (fizz == 3 && buzz == 5) {
print 'FizzBuzz';
fizz = 1;
buzz = 1;
} else if (fizz == 3) {
print 'Fizz';
fizz = 1;
} else if (buzz == 5) {
print 'Buzz';
buzz = 1;
} else {
print i;
}
}
>>
>>54859542
Fixed indentations
def fizzbuzz(x):
if x % 15 == 0:
print "FizzBuzz"
elif x % 5 == 0:
print "Buzz"
elif x % 3 == 0:
print "Fizz"
else:
print x


def fizzbuzz2(x):
if x % 5 == 0 and x % 3 != 0:
print "buzz"
elif x % 3 == 0:
if x % 5 == 0:
print "FizzBuzz"
else:
print "Fizz"
else:
print x

for x in range(1, 101):
fizzbuzz2(x)
fizzbuzz(x)


thanks
>>54859918
>>
What is FizzBuzz?
>>
>>54860139
That's FizzBuzz son:
for i in range(1,101):
print("FizzBuzz"[i*i%3*4:8--i**4%5] or i)
>>
It's prob shit.
public class fizzbuzz{
public static void main(String[] args){
for(int i = 1; i <= 100; i++){
if(i%15 ==0){
System.out.println("FizzBuzz");
}else if(i%5==0){
System.out.println("Buzz");
}else if(i%3 == 0){
System.out.println("Fizz");
}else{
System.out.println(i);
}
}
}
}
>>
>>54860180
But what IS it? Is there a way to explain it to someone who doesn't know any programming languages?
>>
count up to a hundred, but if the number is div by 3 say fizz and if it's by 5 say buzz and if it's both say fizzbuzz
>>
>>54860217
>>54860225

shit forgot to reply
>>
>>54860180
how does that work? I understand python's array notation, but I don't understand the numbers behind those equations.
>>
>>54859202
I can't comment on the speed of using 'empty()' compared to '$foo == ""' since I can't be assed to test. I think they'll be similar, nevertheless speed doesn't matter too much unless it's very significant (by maybe a few seconds more than milliseconds).

Though in programming languages that use C-style (null-terminated) strings, comparing to "" will be faster.

Even though built-in functions are there to make it easy for programmers, you should NOT rely on them entirely.

IF you do:
$kek = "0123";

echo empty($kek) ? "The string is empty" : "The string is NOT empty";


It will print 'The string is NOT empty' as expected.

Though if you do
$kek = "0";

echo empty($kek) ? "The string is empty" : "The string is NOT empty";


It will print 'The string is empty' this is incorrect.

Therefore

This is a reason why it's sometimes better just use operators than call functions and procedures to do simple shit.
>>
#include <stdio.h>

void increment ( char* no )
{
if (*no == '9') {
*no = '0';
increment(no-1);
} else {
(*no)++;
}
}

char* seek ( char* no )
{
for (;*no == '0';++no);
return no;
}

int divisible_by_3 ( char* no )
{
char s[] = "00000000";

for (int k = 0; k < 7; ++k) {
if (no[k] == '0') continue;

for (int i = 0; i < 8;++i)
for (int j = no[i]-'0'; j>0; --j)
increment(s+7);

return divisible_by_3(s);
}

return no[7] == '0' || no[7] == '3' || no[7] == '6' || no[7] == '9';
}

int divisible_by_5 ( char* no )
{
return no[7] == '0' || no[7] == '5';
}

int main (void)
{
for(char s[] = "00000001"; s[5]=='0'; increment(s+7)) {
if (divisible_by_3(s) && divisible_by_5(s)) {
puts("FizzBuzz");
} else if (divisible_by_5(s)) {
puts("Buzz");
} else if (divisible_by_3(s)) {
puts("Fizz");
} else {
puts(seek(s));
}
}
}
>>
>>54860922

*slow clap*
>>
Is FizzBuzz the only thing /g/ is capable of programming?

#include <stdio.h>

#define BUZZZ int
#define FIZZZ printf
#define FIZZ for
#define BUZZ if
#define BZZ "\n"
#define FUZZ return
#define FIZZBUZZZ main
#define FIZZZBUZZ "%d"
#define FIZZBUZZ else
#define BUZZFIZZ 3
#define FIZZFIZZ 5
#define BUZZBUZZ 100

BUZZZ FIZZBUZZZ(){BUZZZ fizzbuzz;FIZZ(fizzbuzz=BUZZFIZZ/BUZZFIZZ;fizzbuzz<=BUZZBUZZ;++fizzbuzz){BUZZ(fizzbuzz%(BUZZFIZZ*FIZZFIZZ)==BUZZBUZZ-BUZZBUZZ)FIZZZ("FIZZBUZZ");FIZZBUZZ BUZZ(fizzbuzz%BUZZFIZZ==FIZZFIZZ-FIZZFIZZ)FIZZZ("FIZZ");FIZZBUZZ BUZZ(fizzbuzz%FIZZFIZZ==BUZZFIZZ-BUZZFIZZ)FIZZZ("BUZZ");FIZZBUZZ FIZZZ(FIZZZBUZZ,fizzbuzz);FIZZZ(BZZ);}FUZZ BUZZBUZZ-fizzbuzz;}
>>
>>54859418
No parentheses after print, it goes from 0 to 99 and that or means absolutely nothing. FizzBuzz circlejerkers confirmed for Pajeet-tier code monkeys.
>>
>>54860341
I have no clue. I just copypasted. This is called FizzBuzz of the Christ.
>>
>>54857414

/g/ is looking for work.
>>
>>54861092
>Is FizzBuzz the only thing /g/ is capable of programming?

Does that surprise you?
>>
#include <stdio.h>

int main() {

int i;
while( i < 101 ) {
i % 15 == 0 ? printf("FizzBuzz\n") : i % 3 == 0 ? printf("Fizz\n"): i % 5 == 0 ? printf("Buzz\n"): printf("%d\n", i);
i++;
}

return 0;
}
>>
Program FizzBuzz;
Uses sysutils;
Var
i, n: Integer;
fbarr: Array [1..15] of String[9] = ('%', '%', 'Fizz', '%', 'Buzz', 'Fizz', '%', '%', 'Fizz', 'Buzz', '%', 'Fizz', '%', '%', 'Fizz Buzz');
Begin
If Length(ParamStr(1)) = 0 Then
n := 30
Else
n := StrToInt(ParamStr(1));

For i := 0 To n-1 Do Begin
If fbarr[(i Mod 15) + 1] = '%' Then
Write(IntToStr(i+1))
Else
Write(fbarr[(i Mod 15) + 1]);
If i <> n-1 Then Write(', ');
End;
WriteLn('.');
End.
>>
open Printf;;
open List;;

let rec range a b =
if a > b then []
else a :: range (a+1) b;;

let num = range 1 100 in
let rec aux x =
match (x mod 3, x mod 5) with
| (0, 0) -> "FizzBuzz"
| (0, _) -> "Fizz"
| (_, 0) -> "Buzz"
| (_, _) -> string_of_int x in
map (printf "%s\n") (map aux num)


get on my level
>>
>>54862809
Glorious OCaml or filthy F#?
>>
>>54862939
lmao
>functional progamming
>somehow non tail recursion is bad practice
>>
>>54862809
I rewrite your whole code to teach you anon
open Printf;;
open List;;

let rec iter_range f a b =
if a > b then
()
else
begin
f a;
iter_range f (succ a) b
end

let _ =
iter_range
(fun x ->
let s =
match (x mod 3, x mod 5) with
| (0, 0) -> "FizzBuzz"
| (0, _) -> "Fizz"
| (_, 0) -> "Buzz"
| (_, _) -> string_of_int x in
print_endline s)
1 100
>>
>>54858020
stupid/10
>>
>>54854611
fizzbuzz x 
| x `mod` 15 == 0 = putStrLn "FizzBuzz"
| x `mod` 5 == 0 = putStrLn "Buzz"
| x `mod` 3 == 0 = putStrLn "Fizz"
| otherwise = print x

main = mapM_ fizzbuzz [1..100]
>>
>>54859465
>>54859518
As long as it does a fair amount of numbers and the business logic is sound, it really doesn't matter what range of numbers it does.
>>
>>54854974
this is pretty kek
>>
IF YOUR CODE HAS
15
or
fizzbuzz

IN IT, THEN YOU ARE BAD AT PROGRAMMING.
>>
>>54859858
No it's not, I just saw all the threads recently and wanted to see what people thought of my noob PHP solution
>>
static void Main(string[] args)
{
for (int i = 1; i <= 100; i++)
{
if ((i % 3 == 0) && (i % 5 == 0))
{
Console.Write("FizzBuzz\n");
}
else if (i % 3 == 0)
{
Console.Write("Fizz\n");
}
else if (i % 5 == 0)
{
Console.Write("Buzz\n");
}
else Console.Write(i + "\n");
}
Console.ReadKey();
}
>>
>>54863159
Why?
>>
>>54858020
Learn to allocate dynamic memory
>>
>>54863203
because you're already checking for division by 3 & 5, and already printing fizz & buzz.
You don't need a special case for 15.
>>
>>54863264
You forgot performance.
>>
>>54863280
performance IS the reason for removing the 3rd check.
>>
File: 1444115874000.jpg (567 KB, 1664x1040) Image search: [Google]
1444115874000.jpg
567 KB, 1664x1040
These are literally the gayest threads.

But I need to show off my extra optimized fizzbuzz.
(loop for i from 1 to 100 do
(print (case (gcd i 15)
(3 "fizz")
(5 "buzz")
(15 "fizzbuzz"))))
>>
>>54854950
That might be the worst Scala I've ever seen
>>
>>54863314
You should compare the different solutions.
>>
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)]


:^)
>>
>>54863459
what the fuck
>>
>>54854611
rate
for i in range(1, 101):
if (i % 3) and (i % 5):
print(i)
continue
if i % 3:
print("Fizz", end = "")
if i % 5:
print("Buzz", end = "")
print()
>>
>hundreds of questions on project euler to make threads about.
>huuurrr le fizz buzz maymay thread

STOP.
>>
>>54859518
>those other hundreds of thousands of people who apply for programming jobs and can't fizzbuzz


Sounds like jobs need to stop using some retarded arbitrary test and try actual real world scenarios to find out the competency of people coding for real life scenarios instead of ones thought up for the sole purpose of being difficult and confusing and useless.
>>
>>54863570
thats wrong you dolt
>>
>>54863595
oops meant

for i in range(1, 101):
if (i % 3) and (i % 5):
print(i)
continue
if i % 3 == 0:
print("Fizz", end = "")
if i % 5 == 0:
print("Buzz", end = "")
print()
>>
>>54863664
still wrong senpai
>>
>>54863782
not him but it seems to work when I tested it
>>
>>54863459
Wow for a moment I actually believed this worked.
>>
>>54863782
Good thing it isn't an actual program and is just designed to waste peoples time on an trick questions.
>>
>>54863880
>>54863901

you didn't get the concept right, the code works, but it doesn't do what is asked
>>
> conditional logic

whichfizz = fn
(0, 0, _) -> "FizzBuzz"
(0, _, _) -> "Fizz"
(_, 0, _) -> "Buzz"
(_, _, n) -> n
end

fizzbuzz = fn (n) ->
whichfizz.(rem(n, 3), rem(n, 5), n)
end

IO.inspect Enum.map(1..100, fizzbuzz)
>>
>>54863782
>>54863951
wait what
>>
A Haskell one-liner I made a few months ago.

mapM_ print [if x `mod` 15 == 0 then "FizzBuzz" else if x `mod` 5 == 0 then "Fizz" else if x `mod` 3 == 0 then "Buzz" else show x | x <- [1..100]]
>>
>>54864076
Oh, and I was just starting to learn haskell at the time, so I'm sure this can be shortened by like, half or something.
>>
>>54864103
I'm not a haskell guru myself but generally using if then else is less preferred to guards, I think. A list comprehension also isn't really needed for this
>>
>>54864015
if i mod 3 == 0 and i mod 5 == 0, print FizzBuzz

when it doesn't get in any of the 3 contidions (mod 3 and 5, mod 5, mod 3), then print i
>>
>>54864076
fizz 0 0 _ = "Fizzbuzz"
fizz 0 _ _ = "Fizz"
fizz _ 0 _ = "Buzz"
fizz _ _ n = show n

fizzbuzz = [(fizz (rem x 3) (rem x 5) x) | x <- [1..100]]
>>
>>54864142
ur dum, learn to read
>>
File: 1445145145285.png (604 KB, 735x710) Image search: [Google]
1445145145285.png
604 KB, 735x710
My probably horribly inefficient MIPS assembly version I made awhile back.

1/2

## FizzBuzz in MIPS ASM
.data
fizz: .asciiz "Fizz" #declare and instantiate the Strings we will use to print to the console
buzz: .asciiz "Buzz"

.text

main:
addi $s1, $zero, 1 #current value of our incrementor
add $s2, $zero, $zero #Flag for if something was printed to the console (fizz or buzz). 0 = false, 1 = true
addi $s3, $zero, 3 #value of 3 used for our div function
addi $s4, $zero, 5 #value of 5 used for our div function
addi $s5, $zero, 101 #value to terminate at

j mainLoop #jump to the loop

# Block of functions we will use to print to the console

printFizz: li $v0, 4
la $a0, fizz #print Fizz to the console
syscall

li $s2, 1 #set the printed flag
jr $ra

printBuzz: li $v0, 4
la $a0, buzz #print Buzz to the console
syscall

li $s2, 1 #set the printed flag
jr $ra
>>
File: 1445145206805.jpg (202 KB, 448x426) Image search: [Google]
1445145206805.jpg
202 KB, 448x426
>>54864337
printNumber:    li $v0, 1
move $a0, $s1 #print the current value to the console
syscall

jr $ra

# End of block of funtions, begin the loop code

mainLoop: div $s1, $s3 #divide the current value by 3. HI holds remainder
mfhi $t1
bnez $t1, buzzSection #skip to the next section if the calue is not divisible by 3
jal printFizz #jump to the printFizz function

buzzSection: div $s1, $s4 #divide the current value by 5. HI holds remainder
mfhi $t1
bnez $t1, printCheck #skip to the next section if the calue is not divisible by 5
jal printBuzz #jump to the printBuzz function

printCheck: bnez $s2, endOfLoop #skip to the next section if either Fizz or Buzz have been printed (skips printing the current value)
jal printNumber #jump to the printNumber function

endOfLoop: li $v0, 11 #get the loop ready for the next iteration
li $a0, 10
syscall ##print a newline

li $s2, 0 #set the printed flag back to false
addi $s1, $s1, 1 #increment the value

bne $s1, $s5, mainLoop #continue to loop if the current value is not 101 (Program evaluates from 1-100)


end: #program is finished, drop off the end of execution
>>
>>54863586
I agree the test is superficial but tons of people feel smug upon knowing that a lot of people fail while they think they can do it, yet they fail as well. It's an attention test, not an IQ test.
>>
>>54864103
yea to this found on the internet
let (m ~> str) x = str <$ guard (x `mod` m == 0)
in map (fromMaybe . show <*> 3 ~> "fizz" <> 5 ~> "buzz")
Thread replies: 105
Thread images: 5

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.