MakeWebGames

# Math/Programming Challenges

## Recommended Posts

Recently I've been looking in to a lot of programming puzzles for fun and I came across one of the versions of FizzBuzz.

Rules

• If a string starts with "f" then you display "Fizz".
• If a string ends with "b" then you display "Buzz".
• If a string starts with "f" and ends with "b" then you display "FizzBuzz".

##### Share on other sites

I made one for PHP. If the line is a divisor of 3 it displays "Fizz", if it's a divisor of 5 it displays "Buzz", and if it's a divisor of both it displays "FizzBuzz".

```for(\$i = 1; \$i <= 100; \$i++){
echo (\$i%3==0 ? (\$i%5==0?"FizzBuzz":"Fizz") : (\$i%5==0?"Buzz": \$i))."\n";
}```
##### Share on other sites

I made one for PHP. If the line is a divisor of 3 it displays "Fizz", if it's a divisor of 5 it displays "Buzz", and if it's a divisor of both it displays "FizzBuzz".
```for(\$i = 1; \$i <= 100; \$i++){
echo (\$i%3==0 ? (\$i%5==0?"FizzBuzz":"Fizz") : (\$i%5==0?"Buzz": \$i))."\n";
}```

Awesome, I was going to try that next, also if you're interested in another one try to generate the Fibonacci Sequence.

Edited by Script47
##### Share on other sites

This is acutally awesome O.o

Nice work :)

##### Share on other sites

Awesome, I was going to try that next, also if you're interested in another one try to generate the Fibonacci Sequence.

I remember writing a Fibonacci thing in highschool. Wow oh wow that was like 15yrs ago...

##### Share on other sites

So, I've been trying to make a random string generator, I've done this in PHP before, it was a lot easier it PHP than in Java, but this is what I came up with, it isn't the best.

```public static String generateString(boolean numbersToo) {
Random rGen = new Random();
String string = "";
String charsAndNums[][] = {{"A" + rGen.nextInt(99), "B" + rGen.nextInt(99), "C" + rGen.nextInt(99), "D" + rGen.nextInt(99), "E" + rGen.nextInt(99), "F" + rGen.nextInt(99), "G" + rGen.nextInt(99), "H" + rGen.nextInt(99), "I" + rGen.nextInt(99), "J" + rGen.nextInt(99), "K" + rGen.nextInt(99), "L" + rGen.nextInt(99), "M" + rGen.nextInt(99), "N" + rGen.nextInt(99), "O" + rGen.nextInt(99), "P" + rGen.nextInt(99), "Q" + rGen.nextInt(99), "R" + rGen.nextInt(99), "S" + rGen.nextInt(99), "T" + rGen.nextInt(99), "U" + rGen.nextInt(99), "V" + rGen.nextInt(99), "W" + rGen.nextInt(99), "X" + rGen.nextInt(99), "Y" + rGen.nextInt(99), "Z" + rGen.nextInt(99)}};

for(int i = rGen.nextInt(10) + 4; i <= rGen.nextInt(26) + 5; i++) {
string += charsAndNums[0][i];
}
return string;
}
```

Any ideas to improve are welcome.

##### Share on other sites

I made one for PHP. If the line is a divisor of 3 it displays "Fizz", if it's a divisor of 5 it displays "Buzz", and if it's a divisor of both it displays "FizzBuzz".
```for(\$i = 1; \$i <= 100; \$i++){
echo (\$i%3==0 ? (\$i%5==0?"FizzBuzz":"Fizz") : (\$i%5==0?"Buzz": \$i))."\n";
}```

Pfft, you n00b!

My attempt in the last couple minutes -- challenge is to beat it.

EDIT: Forums breaks it with smiley codes *ugh*

Edit 2: If my server would have accepted \n instead of <br> I could have chopped another 2 characters *boo*

Edited by Guest
##### Share on other sites

I tried the Fibonacci Sequence before and came up with this.

```public static void fibonacciSequence() {
int x = 2;
int y = 3;

System.out.println(1 + "\n" + 1 + "\n" + 2 + "\n" + 3);

for(int i = 0; i <= 7; i++) {
int z = x + y;
System.out.println(z);
x = y;
y = z;
}
}
```
##### Share on other sites

[MENTION=50378]Guest[/MENTION]: 86 characters; not too bad but I'm sure I can shave a few off that - how about 62 - http://codepad.org/jSBqb1ms

##### Share on other sites

[MENTION=50378]Guest[/MENTION]: 86 characters; not too bad but I'm sure I can shave a few off that - how about 62 - http://codepad.org/jSBqb1ms

Wow haha, good shaving! :D

##### Share on other sites

@Guest: 86 characters; not too bad but I'm sure I can shave a few off that - how about 62 - http://codepad.org/jSBqb1ms

A quote from Skype earlier in relation to this thread;

```I’m thinking only Alan (friend of mine) could do it, but we will see.
```
##### Share on other sites

Haha hawt dayum I didn't even know it can work like that. Heck, I can't even read it right

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

• #### Marketplace

• Discord Chat
• PBBG Directory
×
• Create New...