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

Fizz buzz Fizzbuzz

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: 21
Thread images: 4

File: images.png (8KB, 284x177px) Image search: [Google]
images.png
8KB, 284x177px
GIVE ME MY FIZZBUZZ

void fizzbuzz() {
for(int i=1;;i++) {
String s = i%3==0?"fizz":"";
s += i%5!=0?"":"buzz";
System.out.println(s.isEmpty()?i:s);
}
}
>>
perl -e 'say"Fizz"x!($_%3)."Buzz"x!($_%5)||$_ for 1..100'
>>
#!/usr/bin/env xcrun swift -I

print((1...100).map{ $0 % 3 == 0 ? $0 % 5 == 0 ? "FizzBuzz" : "Fizz" : $0 % 5 == 0 ? "Buzz" : "\($0)"})
>>
what's the point of these threads? there's no challenge whatsoever in writing fizzbuzz.
>>
>>58114873
Yeah, it's the most basic of programming tasks. But who gives a shit.
>>
File: 3zhDJEx.jpg (139KB, 1919x1079px) Image search: [Google]
3zhDJEx.jpg
139KB, 1919x1079px
python2
for x in range(100): print x%3/2*'Fizz'+x%5/4*'Buzz' or x+1
>>
>>58114873
newfag
>>

for(i=1;i<=100;i++){
i=i.toString();
var tmp = i.split('');
if(tmp[tmp.length-1] == 5){
if(tmp[tmp.length-1] == 3)
{
console.log("FizzBuzz!")
}
else{
console.log("Buzz!");
}
}
else if(tmp[tmp.length-1] == 3){
console.log("Fizz!");
}
else{
console.log(i);
}
}


graduated a bit ago but only starting to apply to some jobs now so am doing these excersizes for practice

any pointers would be appreciated
>>
>>58117354
int *ptr
>>
>>58117388
What?

I'm using javascript
>>
>>58117452
Then I am afraid pointers will be of no use to you.
>>
File: XLR2BNC.jpg (78KB, 600x787px) Image search: [Google]
XLR2BNC.jpg
78KB, 600x787px
using namespace std;


int main() {
int i;

i = (5/5) - 1;
i *= 0;

cin >> i;
i = 0;

for(int i = 0; i < 25; i++){
if(i == 15)
cout << "Fizzbuzz"; // This prints Fizzbuzz, since 15 is divisible by both 5 and 3 ;3
else if(i == 5 || 10 || 15 || 20 || 25)
cout << "Buzz"; // This prints only Buzz, as these numbers are only divisible by 5 ;)
else if(i == 3 || 6 || 9 || 12 || 15 || 18 || 21 || 24)
cout << "Fizz"; //This prints Fizz, as these numbers are only divisible by 3 :)
}


>>
>>58117354
Here's a pointer: don't use that font, please.

Fixd for you btw

for(i=1;i<100;i++) {
var tmp = i%3==0?'fizz':'';
tmp += i%5!=0?'':'buzz';
console.log(tmp.length==0?i:tmp);
}
>>
>>58114846
fugg thats hot
>>
>>58117354
>>58118076

Alternative because I was bored

for(i=1;i<100;i++) {
var tmp = '';

switch(true) {
case(i%3==0):
tmp += 'fizz';
case(i%5==0):
tmp += i%5==0?'buzz':'';
break;
}

console.log(tmp.length==0?i:tmp);
}
>>
>>58117354
>>58118076
>>58118219

I'm bored. Now I'm going to bed. Here's what I could come up with for you.

for(i=1;i<100;i++) {
console.log((i%3?'':'fizz')+(i%5?'':'buzz')||i);
}
>>
>>58114433
>not providing glorious hex magic value solution
function fizzbuzz(n) {
let m = [null, "Fizz", "Buzz", "FizzBuzz"];
let v = 0x30490610;
for (let i = 1; i <= n; i++) {
console.log(m[v & 3] || i);
v = (v >> 2) | (v & 3) << 0x1c;
}
}
>>
>>58114433
package fb;

class FizzBuzz {

private static final FIZZ = "fizz";
private static final BUZZ = "buzz";
private int n;

public FizzBuzz(int n) {
this.n = n;
}

public void run() {
for (int i=0; i<n+1; i++) {
if (i%3==0 && i%5==0) {
System.out.println(FIZZ+BUZZ);
} else if (i%3==0) {
System.out.prinln(FIZZ);
} else if (i%5==0) {
System.out.prinln(BUZZ);
} else {
System.out.prinln(Integer.toString(i));
}
}
}

public static void main(String[] args) {
FizzBuzz fizzBuzz = new FizzBuzz(100);
fizzBuzz.run();
}
}
>>
>>58118996
Forgot the type on the constants. Should be this instead:
package fb;

class FizzBuzz {

private static final String FIZZ = "fizz";
private static final String BUZZ = "buzz";
private int n;

public FizzBuzz(int n) {
this.n = n;
}

public void run() {
for (int i=0; i<n+1; i++) {
if (i%3==0 && i%5==0) {
System.out.println(FIZZ+BUZZ);
} else if (i%3==0) {
System.out.prinln(FIZZ);
} else if (i%5==0) {
System.out.prinln(BUZZ);
} else {
System.out.prinln(Integer.toString(i));
}
}
}

public static void main(String[] args) {
FizzBuzz fizzBuzz = new FizzBuzz(100);
fizzBuzz.run();
}
}
>>
File: 2016-12-22-025340_700x532_scrot.png (14KB, 700x532px) Image search: [Google]
2016-12-22-025340_700x532_scrot.png
14KB, 700x532px
I hate that mine is too long for these threads http://pastebin.com/raw/WjbiGNEC
>>
for (int i = 1; i < 100; i++) {
String str = "";
if (i % 3 == 0) {
str += "Fizz";
}
if (i % 5 == 0) {
str += "Buzz";
}
if (str.equals("")) {
str = i + "";
}

System.out.println(str);
}
Thread posts: 21
Thread images: 4


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