Added solutions to Generic/FizzBuzz

This commit is contained in:
FuryFire 2012-03-01 13:40:45 +01:00
parent 2c7660786d
commit 46c2a0b087
5 changed files with 73 additions and 0 deletions

20
Generic/FIZZBUZZ/desc.yml Normal file

@ -0,0 +1,20 @@
title: FizzBuzz
url: http://projecteuler.net/problem=1
desc: |
The classical coding challenge. 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”.
solution: |
See the code...
solutions:
solve.php:
desc: Basic solution
usage:
language: php
solve.rb:
desc: Basic solution in Ruby
language: ruby
solve.c:
desc: ANSI C solution (Tested with TCC)
language: c

22
Generic/FIZZBUZZ/solve.c Normal file

@ -0,0 +1,22 @@
#include <stdio.h>
int main( )
{
int i = 0;
for(i = 1; i <= 100; i++)
{
if(i % 3 == 0)
{
printf( "Fizz" );
}
if(i % 5 == 0)
{
printf( "Buzz" );
}
if(i % 3 && i % 5)
{
printf( "%d", i );
}
printf( "\n" );
}
}

@ -0,0 +1,13 @@
<?php
for($i=1; $i<=100; $i++) {
if($i % 3 == 0) {
print "Fizz";
}
if($i % 5 == 0) {
print "Buzz";
}
if($i % 3 AND $i % 5) {
print $i;
}
print PHP_EOL;
}

12
Generic/FIZZBUZZ/solve.rb Normal file

@ -0,0 +1,12 @@
(1..100).each do |i|
if(i % 3 == 0)
print "Fizz";
end
if(i % 5 == 0)
print "Buzz"
end
if(i % 3 != 0 and i % 5 != 0)
print i
end
print "\n";
end

6
ProjectEuler/desc.yml Normal file

@ -0,0 +1,6 @@
title: ProjectEuler.net
url: http://projecteuler.net/
desc: |
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.