Added a few generic problems\nSolved Euler027

This commit is contained in:
FuryFire
2016-02-23 15:55:26 +01:00
parent a6355b2629
commit 2a2623a652
19 changed files with 352 additions and 0 deletions

BIN
Generic/Fibonacci/a.exe Normal file

Binary file not shown.

51
Generic/Fibonacci/solve.c Normal file
View 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
Generic/Fibonacci/solve.exe Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
console.log("Hello World");

View 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
Generic/Seive/desc.yml Normal file
View 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
Generic/Seive/solve.c Normal file
View 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);
}
}
}