kanenas.net

Tag: Programming

FizzBuzz questions & coding for fun!

by kanenas.net on Jul.02, 2010, under PHP, Programming, Tech

Two days ago I was reading in RethinkDB’s blog the “Will the real programmers please stand up?” which took me to the blogpost of Coding Horror “Why Can’t Programmers.. Program?”.

After reading these two articles I had the idea to start a FizzBuzz coding section just for fun (CfF - Coding for Fun).
So today’s FizzBuzz question is…

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Below is my solution written in php.

<?php
echo '<h2>Coding For Fun</h2>';
$three = 3;
$five = 5;
$fifteen =15;

for ($i=1; $i<=100; $i++){
	if (($i%$three === 0) && ($i%$five === 0)) {
		echo 'FizzBuzz<br />';
	} elseif ($i%$three === 0) {
		echo 'Fizz<br />';
	} elseif ($i%$five === 0) {
		echo 'Buzz<br />';
	} else {
		echo $i . '<br />';
	}
}

echo '<br />==============<br /><br />';

for ($i=1; $i<=100; $i++){
	if ($i%$fifteen === 0) {
		echo 'FizzBuzz<br />';
	} elseif ($i%$three === 0) {
		echo 'Fizz<br />';
	} elseif ($i%$five === 0) {
		echo 'Buzz<br />';
	} else {
		echo $i . '<br />';
	}
}
?>

Yes… it took me 10 minutes :(
Can i stand up?!
;)

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...
  • Share/Bookmark
Leave a Comment :, , , , more...

Cholesterol Levels 2010 (= Greek Easter)

by kanenas.net on Apr.07, 2010, under News, PHP, Programming


See the photos as a slide-show in Flickr.com.

<?php
// Set your Cholesterol Level before executing the script!
// Uncomment the next line.
// $Cholesterol = 240;

if (!isset($Cholesterol) || $Cholesterol=='') {
	echo 'This is good!';
} else {
	if ($Cholesterol<200) {
		echo 'Desirable level. Low risk for coronary heart disease.';
	} elseif ($Cholesterol>=200 && $Cholesterol<240) {
		echo 'Borderline high!';
	} else {
		echo '<strong>DANGER!</strong> High blood cholesterol!';
	}
}
?>

;)

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading ... Loading ...

  • Share/Bookmark
1 Comment :, , , , , , , , , , , , , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!