changed file and folder names to a sane scheme

This commit is contained in:
ikselven 2017-07-12 00:08:34 +02:00
parent c19129e6dd
commit b725343392
34 changed files with 44 additions and 0 deletions

2
e0010/euler0010.R Normal file
View file

@ -0,0 +1,2 @@
library(numbers)
sum(as.numeric(Primes(1L, 2000000L)))

10
e0010/euler0010.bash Executable file
View file

@ -0,0 +1,10 @@
#!/usr/bin/bash
# I have yet to see this script coming to an end...
declare -i primeSum=0
for num in {2..2000000}; do
[[ "$(factor $num | cut -d " " -f2)" != $num ]] || primeSum=$(( $primeSum + $num ))
done
echo "$primeSum"

48
e0010/euler0010.cpp Normal file
View file

@ -0,0 +1,48 @@
// This solution needs the GNU MP Bignum library
// g++ euler10.cpp -o euler10 -lgmpxx -lgmp
#include <gmpxx.h>
#include <cmath>
#include <vector>
#include <iostream>
void sieve(std::vector<int>& primes, int const limit) {
if (limit < 2) {
return;
} else if (limit < 3) {
primes.push_back(2);
return;
}
primes.push_back(2);
primes.push_back(3);
for (int num = 5; num <= limit; num += 2) {
int sqrtnum = (int) std::sqrt(num);
bool isPrime = true;
for (auto primeIt = ++primes.begin(); primeIt != primes.end() && *primeIt <= sqrtnum; ++primeIt) {
if (num % *primeIt == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push_back(num);
}
}
}
int main(void) {
constexpr int limit = 2000000;
constexpr int PRIMELIMIT = limit - 1;
std::vector<int> primes;
sieve(primes, PRIMELIMIT);
mpz_class sum = 0;
for (auto primeIt = primes.begin(); primeIt != primes.end(); ++primeIt) {
sum += *primeIt;
}
std::cout << sum << std::endl;
return EXIT_SUCCESS;
}

36
e0010/euler0010.js Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/node
function getPrimeList(max) {
if (typeof max !== 'number' || max < 2) {
return [];
} else if (max===2) {
return [2];
}
let primes = [2];
for(i=3; i<=max; i++) {
let isPrime = true;
for(prime of primes) {
if (i % prime === 0) {
isPrime = false;
break;
}
}
if (isPrime) {
primes.push(i);
}
}
return primes;
}
console.time();
let primeList = getPrimeList(2000001);
console.timeEnd();
console.log("Found "+primeList.length+" prime numbers.");
console.time();
let primeSum = primeList.reduce( (sum, element) => sum + element);
console.timeEnd();
console.log(primeSum);

12
e0010/euler0010.rkt Normal file
View file

@ -0,0 +1,12 @@
#lang racket
(require math/number-theory)
(define (primes it limit prim)
(if (equal? it limit)
prim
(if (prime? it)
(primes (+ it 1) limit (cons it prim))
(primes (+ it 1) limit prim))))
(apply + (primes 1 2000000 (list)))