Restructuring
This commit is contained in:
11
solutions/Generic/99Bottles/desc.yml
Normal file
11
solutions/Generic/99Bottles/desc.yml
Normal file
@ -0,0 +1,11 @@
|
||||
title: FizzBuzz
|
||||
url: http://99-bottles-of-beer.net/
|
||||
|
||||
desc: Generate the lyrics to the song 99 Bottles of Beer as an output.
|
||||
|
||||
solution: See the code...
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
18
solutions/Generic/99Bottles/solve.php
Normal file
18
solutions/Generic/99Bottles/solve.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?
|
||||
for ($beer=99; $beer>=0; $beer--)
|
||||
{
|
||||
if ($beer==0) {
|
||||
echo "No more bottles of beer on the wall, no more bottles of beer.".PHP_EOL;
|
||||
echo "Go to the store and buy some more, 99 bottles of beer on the wall.".PHP_EOL;
|
||||
}
|
||||
elseif ($beer==1) {
|
||||
echo "1 bottle of beer on the wall, 1 bottle of beer.".PHP_EOL;
|
||||
echo "Take one down and pass it around, no more bottles of beer on the wall.". PHP_EOL . PHP_EOL;
|
||||
} elseif ($beer==2) {
|
||||
echo $beer." bottles of beer on the wall, ".$beer." bottles of beer." . PHP_EOL;
|
||||
echo "Take one down and pass it around, ".($beer-1)." bottle of beer on the wall.".PHP_EOL . PHP_EOL;
|
||||
} else {
|
||||
echo $beer." bottles of beer on the wall, ".$beer." bottles of beer." . PHP_EOL;
|
||||
echo "Take one down and pass it around, ".($beer-1)." bottles of beer on the wall.".PHP_EOL . PHP_EOL;
|
||||
}
|
||||
}
|
17
solutions/Generic/FIZZBUZZ/desc.yml
Normal file
17
solutions/Generic/FIZZBUZZ/desc.yml
Normal file
@ -0,0 +1,17 @@
|
||||
title: FizzBuzz
|
||||
url: http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/
|
||||
|
||||
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
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
22
solutions/Generic/FIZZBUZZ/solve.c
Normal file
22
solutions/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" );
|
||||
}
|
||||
}
|
13
solutions/Generic/FIZZBUZZ/solve.php
Normal file
13
solutions/Generic/FIZZBUZZ/solve.php
Normal file
@ -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
solutions/Generic/FIZZBUZZ/solve.rb
Normal file
12
solutions/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
|
BIN
solutions/Generic/Fibonacci/a.exe
Normal file
BIN
solutions/Generic/Fibonacci/a.exe
Normal file
Binary file not shown.
51
solutions/Generic/Fibonacci/solve.c
Normal file
51
solutions/Generic/Fibonacci/solve.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define SIZE 20
|
||||
|
||||
|
||||
|
||||
void add(char *a, char *b, char *result, int size) {
|
||||
int i = 0;
|
||||
for(i=0;i<size;i++) {
|
||||
//We have overflow!
|
||||
if((a[i] + b[i] + result[i] < a[i]) || (a[i] + b[i] + result[i] < b[i])) {
|
||||
result[i+1]++;
|
||||
}
|
||||
result[i]+= a[i] + b[i];
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main( )
|
||||
{
|
||||
unsigned char prev[SIZE];
|
||||
unsigned char current[SIZE];
|
||||
unsigned char next[SIZE];
|
||||
unsigned int i=0;
|
||||
memset(prev,0x00,SIZE);
|
||||
memset(current,0x00,SIZE);
|
||||
memset(next,0x00,SIZE);
|
||||
prev[0]=1;
|
||||
current[0]=1;
|
||||
next[0]=1;
|
||||
|
||||
for(i=2;i<100;i++) {
|
||||
|
||||
add(current,prev,next,SIZE);
|
||||
memcpy(prev,current,SIZE);
|
||||
memcpy(current,next,SIZE);
|
||||
//prev = current;
|
||||
//current = next;
|
||||
int j;
|
||||
for(j=0;j<SIZE;j++) {
|
||||
printf("%d: %i\n",j,current[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<SIZE;i++) {
|
||||
printf("%d: %i\n",i,current[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
solutions/Generic/Fibonacci/solve.exe
Normal file
BIN
solutions/Generic/Fibonacci/solve.exe
Normal file
Binary file not shown.
19
solutions/Generic/HelloWorld/desc.yml
Normal file
19
solutions/Generic/HelloWorld/desc.yml
Normal file
@ -0,0 +1,19 @@
|
||||
title: HelloWorld
|
||||
url: http://en.wikipedia.org/wiki/Hello_world_program
|
||||
|
||||
desc: A "Hello world" program is a computer program that outputs "Hello, world" on a display device.
|
||||
solution: Do i need to say more
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution in Ruby
|
||||
language: ruby
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
||||
solve.js:
|
||||
desc: NodeJS solution
|
||||
language: js
|
7
solutions/Generic/HelloWorld/solve.c
Normal file
7
solutions/Generic/HelloWorld/solve.c
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main( )
|
||||
{
|
||||
printf( "Hello World" );
|
||||
|
||||
}
|
1
solutions/Generic/HelloWorld/solve.js
Normal file
1
solutions/Generic/HelloWorld/solve.js
Normal file
@ -0,0 +1 @@
|
||||
console.log("Hello World");
|
2
solutions/Generic/HelloWorld/solve.php
Normal file
2
solutions/Generic/HelloWorld/solve.php
Normal file
@ -0,0 +1,2 @@
|
||||
<?php
|
||||
echo 'Hello World';
|
1
solutions/Generic/HelloWorld/solve.rb
Normal file
1
solutions/Generic/HelloWorld/solve.rb
Normal file
@ -0,0 +1 @@
|
||||
puts "Hello World"
|
20
solutions/Generic/MultiTable/solve.c
Normal file
20
solutions/Generic/MultiTable/solve.c
Normal file
@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#define SIZE_X 12
|
||||
#define SIZE_Y 12
|
||||
void main()
|
||||
{
|
||||
int x,y;
|
||||
int MemorizeThis[SIZE_X][SIZE_Y];
|
||||
for (x =1; x <= SIZE_X; x++)
|
||||
{
|
||||
for (y = 1; y <= SIZE_Y; y++)
|
||||
{
|
||||
MemorizeThis[x-1][y-1] = x * y;
|
||||
printf("[%03d]", MemorizeThis[x-1][y-1]);
|
||||
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
return;
|
||||
}
|
10
solutions/Generic/Seive/desc.yml
Normal file
10
solutions/Generic/Seive/desc.yml
Normal file
@ -0,0 +1,10 @@
|
||||
title: Sieve of Eratosthenes
|
||||
url: http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
|
||||
|
||||
desc:Generate primes from 2 to 100
|
||||
solution: Do i need to say more
|
||||
|
||||
solutions:
|
||||
solve.c:
|
||||
desc: ANSI C solution (Tested with TCC)
|
||||
language: c
|
22
solutions/Generic/Seive/solve.c
Normal file
22
solutions/Generic/Seive/solve.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void main( )
|
||||
{
|
||||
unsigned char primes[100];
|
||||
int p;
|
||||
int j;
|
||||
memset(&primes, 1, 50 );
|
||||
for( p = 2; p<=10; p++) {
|
||||
if (primes[p]) {
|
||||
for(j = p*p; j <= 100; j+= p){
|
||||
primes[j] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf( "Primes:%d\n", sizeof(primes)) ;
|
||||
for(p=0;p<sizeof(primes);p++) {
|
||||
if(primes[p]) {
|
||||
printf( "%d\n",p);
|
||||
}
|
||||
}
|
||||
}
|
4
solutions/Generic/desc.yml
Normal file
4
solutions/Generic/desc.yml
Normal file
@ -0,0 +1,4 @@
|
||||
title: Generic
|
||||
url: http://google.com
|
||||
|
||||
desc: Various problems that doesn't fit any catagory
|
Reference in New Issue
Block a user