3 Commits

Author SHA1 Message Date
50dd110717 Add task 2020-07-02 21:28:38 +02:00
09b610492c Add task 2020-06-27 19:10:32 +02:00
29447f9773 Create new branch 2020-06-27 19:10:25 +02:00
8 changed files with 49 additions and 270 deletions

View File

@@ -1,35 +0,0 @@
#include <stdio.h>
int fib(int a) {
if(a==0){
return 0;
}else if(a==1){
return 1;
} else {
return (fib(a-1) + fib(a-2));
}
}
int main()
{
int count = 0;
int result = 0;
while(1){
int x = fib(count);
if(x>4000000){
printf("%d", result);
break;
}
if(x%2==0){
result = result + x;
}
count = count+1;
}
}

View File

@@ -0,0 +1,29 @@
const MAX_LIMIT = 4000000
function fibonacci(index) {
if (index === 0) return 0;
let A = 0;
let B = 1;
for (let i = 0; i < (index - 1); i++) {
let C = A + B;
A = B;
B = C;
}
return B;
}
let sum = 0;
let currentNum = 0;
let i = 0;
while (currentNum < MAX_LIMIT) {
currentNum = fibonacci(i);
if (currentNum % 2 === 0) {
sum += currentNum;
}
i++;
}
console.log(sum);

View File

@@ -1,120 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int isPrime(int n){
for(int i=2;i<sqrt(n);i++){
if(n%i==0){
return 0;
}
}
return 1;
}
/*Returns amount of primes between 0 and n*/
int amountPrimes(int n){
int x=0;
for (int i = 2; i < n; i++)
{
if (isPrime(i)){
x+=1;
}
}
return x;
}
/*Returns array with primes between 0 and n*/
int * primesIn(int n){
int x = amountPrimes(n);
int * primes;
primes = malloc(sizeof(int)*x);
x=0;
for (int i = 2; i < n; i++)
{
if (isPrime(i)){
primes[x]=i;
x+=1;
}
}
return primes;
}
/*Factorial of n*/
long fact(int n){
if (n==1){
return 1;
} else {
return n*fact(n-1);
}
}
/*Retrieves the amount of factors in a number*/
int factoramount(int n){
if (isPrime(n)){
return 1;
} else {
for
}
}
/*Returns array with factors of n*/
int * factorize(int n){
int x = amountPrimes(n);
int * primes;
primes = malloc(sizeof(int)*x);
if(isPrime(n)) {
} else {
for (size_t i = 2; i < n; i++)
{
if (i%j==0)
{
}
}
}
}
int main(){
int * primes = primesIn(100);
for (size_t i = 0; i < amountPrimes(100); i++){
printf("Prime: %d\n", *(primes+i));
}
int * factCounter[amountPrimes(100)]
for (size_t i = 1; i < 100; i++){
}
long x = fact(100);
//SUM OF DIGITS OF X
printf("%ld\n", x);
}

View File

@@ -0,0 +1,20 @@
function primeFactorsOf(n) {
let k = 2;
let factors = [];
while (n >= k**2) {
if (n % k === 0) {
factors.push(k)
n = n/k;
} else {
k++;
}
}
factors.push(n);
return factors;
}
const SPECIAL_NUM = 600851475143;
const factorsOfSpecialNum = primeFactorsOf(SPECIAL_NUM);
console.log(Math.max.apply(null, factorsOfSpecialNum));

View File

@@ -1,35 +0,0 @@
#include <stdio.h>
#include <math.h>
int isPrime(long n){
for(int i=2;i<sqrt(n);i++){
if(n%i==0){
return 0;
}
}
return 1;
}
int main()
{
long count=1;
int big=0;
long number=600851475143;
while(count<number){
if(isPrime(count)){
//printf("Prime: %ld \n", count);
if (number%count==0){
printf("New big: %ld \n", count);
big=count;
}
}
count+=1;
}
return 0;
}

View File

@@ -1,39 +0,0 @@
#include <stdio.h>
#include <string.h>
int main(){
int biggest = 0;
for (int i = 100; i < 1000; i++)
{
for (int j = 100; j < 1000; j++)
{
int x=i*j;
int z=x;
int y=0;
while (x != 0)
{
y = y * 10;
y = y + x%10;
x = x/10;
}
//printf("%d - %d\n", y, z);
if (y==z & y>biggest){
biggest = z;
}
}
}
printf("%d\n", biggest);
return 0;
}

View File

@@ -1,13 +0,0 @@
#include <std.io>
int main{
long a=0
for(int i=0;i<=1000;i++){
a+=(i^i);
}
printf("%ld", a);
}

View File

@@ -1,28 +0,0 @@
#include <stdio.h>
int main(){
int x=5;
while(1){
for (int i = 2; i <= 20; i++)
{
if (x%i!=0){
break;
}
if(i==20){
printf("%d\n", x);
return 0;
}
}
x+=1;
}
return 0;
}