Monday, 1st September 2008
BizzBuzz
New layout (yet again), but i lost the old posts :(
Filed under: miscellaneous
Its 3 o'clock on the last day of my week off from work, and what did I do on the week off? Programming, so I took a week off from my programming job and did more programming!!. Oh well.
This is not a real post it more of a system test, testing the new features of the site. To do this I have desided to post some Bizz buzz codes (wiki Bizzbuzz page),
Players generally sit in a circle. The player designated to go first says the number "1", and each player thenceforth counts one number in turn. However, any number divisible by three is replaced by the word bizz and any divisible by five by the word buzz. Numbers divisible by both become bizz buzz. A player who hesitates or makes a mistake is either eliminated or must pay a forfeit, such as taking a drink.
Simple yes? Fun for programmers and alcoholics alike :D
The following are code samples, that can be used to solve the BizzBuzz Game, these are not the best answer to the problem, just a quick and dirty response.
Delphi/Pascal
Function BizzBuzz(const endOfTheGame:integer):String;
var output:string; i:integer;
begin
for i:= 1 to endOfTheGame do
begin
if ( ((i mod 3) = 0) and ((i mod 5) = 0)) then
begin
output := output + 'BizzBuzz' + chr(13);
end
else if ((i mod 3) = 0) then
begin
output := output + 'Bizz' + chr(13);
end
else if ((i mod 5) = 0) then
begin
output := output + 'Buzz' + chr(13);
end
else
output := output + intToStr(i) + chr(13);
end;
result := output;
end;
PHP
function BizzBuzz($endOfTheGame=100);
{
$output ='';
for ($i= 1;$i <= $endOfTheGame; $i++)
{
if ( (($i % 3) == 0) && (($i % 5) == 0)) then
{
$output .= $output + 'BizzBuzz' + chr(13);
}
elseif (($i % 3) == 0) then
{
$output .= $output + 'Bizz' + chr(13);
}
elseif (($i % 5) == 0) then
{
$output .= $output + 'Buzz' + chr(13);
}
else
$output .= $i + chr(13);
}
return = $output;
}
Posted by Re0sless





re0sless Writes Monday, 1st September 2008 12:00:00am
Welcome to http://re0sless.rogueideas.co.uk , please feel free to leave comments and/or grief :P
The above code was just a quirk test of prettify, I may try to re-factor it when I have a minute.