This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(problem_2). | |
-export([solve/1]). | |
-define(LIMIT, 4000000). | |
%% Normalizing the start value, need to start with an odd value and enter tail recursion | |
solve(Start) when Start rem 2 == 0, Start > 0 -> solve(Start - 1, Start, 0); | |
solve(Start) -> solve(Start, Start + 1, 0). | |
%% guard against the limit and drop out of recursion if we hit it | |
solve(Prev, Next, Sum) when Prev >= ?LIMIT; Next >= ?LIMIT -> Sum; | |
%% Sum even values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Solving this problem: | |
# http://projecteuler.net/problem=2 | |
# Sum: 4,613,732 | |
def fab(a,b, maxlimit): | |
while b < maxlimit: | |
yield b | |
a, b = b, a+b | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace ConsolesTests | |
{ | |
class Program | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(problem_2). | |
-export([s/0]). | |
-define(L, 4000000). | |
s() -> s(1, 2, 0). | |
s(P, N, S) when P >= ?L; N >= ?L -> S; | |
s(P, N, S) -> S1 = case N rem 2 of 0 -> N + S; _ -> S end, s(N, P + N, S1). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(l ,ss = 4000000, proc {|p, n, s| p >= l || n >= l ? s : n.even?? ss[n, n + p, s + n] : ss[n, n + p, s] })[1][1, 2, 0] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sieve(numbers, n): | |
for i in range(n * 2, len(numbers), n): | |
numbers[i] = False | |
def skip_to_next_prime(numbers, n): | |
n += 1 | |
while n < max and not numbers[n]: | |
n += 1 | |
return n |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using Sieve of Eratosthenes | |
# https://en.wikipedia.org/wiki/Generating_primes | |
import sys | |
def main(): | |
num = int(sys.argv[1]) | |
num_list = [[i,True] for i in range(num)] | |
num_list[0][1] = False | |
num_list[1][1] = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace Largest_prime_factor | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace ConsolesTests | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace LargestPrimeFactor | |
{ | |
class Program | |
{ |