Fizz Buzz Bizz Fuzz

28Jun13

In the twelve months from March 2013 to March 2014, I programmed solutions to the problems posted on the Contest Coding blog run by Lewis Cornwall, solving 33 problems (out of 47) and achieving a position of 4th on the leaderboard (out of 23).

As that blog has now been discontinued, I’m posting here the solutions I programmed to those problems.

Fizz Buzz Bizz Fuzz

Print the integers from 1 to 100, but for the multiples of 3, print “Fizz” instead and for multiples of 5, print “Buzz”. If the number contains a 3 (for example 23), print “Bizz” and if the number contains a 5, print “Fuzz” (if it contains multiple 3s or 5s, just print one “Bizz” or “Fuzz”). If the number contains more than one of these attributes, print every word (for example 33 prints “FizzBizz”, as 33 is both a multiple of 3 and contains the digit 3).

Solution and answer (Fizz Buzz Bizz Fuzz.pas):

{$R+}
program Fizz_Buzz_Bizz_Fuzz( output );
{
Solution and answer for problem "Fizz Buzz Bizz Fuzz" (28th June 2013) of http://ContestCoding.WordPress.com/

1
2
FizzBizz
4
BuzzFuzz
Fizz
7
8
Fizz
Buzz
11
Fizz
Bizz
14
FizzBuzzFuzz
16
17
Fizz
19
Buzz
Fizz
22
Bizz
Fizz
BuzzFuzz
26
Fizz
28
29
FizzBuzzBizz
Bizz
Bizz
FizzBizz
Bizz
BuzzBizzFuzz
FizzBizz
Bizz
Bizz
FizzBizz
Buzz
41
Fizz
Bizz
44
FizzBuzzFuzz
46
47
Fizz
49
BuzzFuzz
FizzFuzz
Fuzz
BizzFuzz
FizzFuzz
BuzzFuzz
Fuzz
FizzFuzz
Fuzz
Fuzz
FizzBuzz
61
62
FizzBizz
64
BuzzFuzz
Fizz
67
68
Fizz
Buzz
71
Fizz
Bizz
74
FizzBuzzFuzz
76
77
Fizz
79
Buzz
Fizz
82
Bizz
Fizz
BuzzFuzz
86
Fizz
88
89
FizzBuzz
91
92
FizzBizz
94
BuzzFuzz
Fizz
97
98
Fizz
Buzz

Solution programmed in Pascal using Metrowerks CodeWarrior IDE 2.1 (Discover Programming Edition); solution took ~4s to run on a 80MHz PowerPC 601.
}
var
  i : 1..100;
  b : boolean;
begin
  for i := 1 to 100 do begin
    b := false;
    if i mod 3 = 0 then begin
      write( 'Fizz' );
      b := true
    end;
    if i mod 5 = 0 then begin
      write( 'Buzz' );
      b := true
    end;
    if ( i mod 10 = 3 ) or ( i div 10 mod 10 = 3 ) then begin
      write( 'Bizz' );
      b := true
    end;
    if ( i mod 10 = 5 ) or ( i div 10 mod 10 = 5 ) then begin
      write( 'Fuzz' );
      b := true
    end;
    if not b then
      writeln( i )
    else
      writeln
  end
end.
Advertisements


No Responses Yet to “Fizz Buzz Bizz Fuzz”

  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: