Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,156,693 members, 7,831,150 topics. Date: Friday, 17 May 2024 at 02:33 PM

Lets Start A Thread For Solving Problems From Projecteuler.net - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Lets Start A Thread For Solving Problems From Projecteuler.net (1970 Views)

Solving Real Problems / An Amazing Tool For Solving Math Problems / Algorithm For Solving Systems Of Linear Equations (2) (3) (4)

(1) (Reply) (Go Down)

Lets Start A Thread For Solving Problems From Projecteuler.net by Ogbeozioma: 6:44pm On Aug 13, 2014
I just discovered a website ( projecteuler.net ) that contains 500 Mathematics problems that can best be solved using computer programs. I tried solving a couple of them. I got some right but I discovered one Exciting thing about these problems, they are structured to determined the ability of the programmer to structure Algorithms in an efficient method(solving the problem in minimum time). When I wrote the program to solve question 3 I discovered that my computer was using up to an hour to solve it.
Please go to the site and post an efficient solution to any of the problems in any language of your choice. This is for the benefit of some of us who are beginners in programming. I am a beginner in csharp.
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by Celebrimbor(m): 11:18pm On Dec 10, 2015
oboy, how far you don go for the solving and learning?
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by DonSegmond(m): 1:04am On Dec 11, 2015
Solutions in Prolog

Problem 1
multipleOfM(M,N):-
0 is mod(N, M).

divisibleBy3or5(N):-
(multipleOfM(3,N) ; multipleOfM(5,N)).


range(F,F,[F]).
range(From, To, [From|L]):-
From < To,
F1 is From + 1,
range(F1, To, L).

start(R2):-
range(1,999,L),
include(divisibleBy3or5, L, R),
sum_list(R,R2).


Problem 2
:- dynamic stored/1.
memo(Goal) :- ( stored(Goal) -> true ; Goal, assertz(stored(Goal)) ).

fib(0, A, _, A).
fib(N, A, B, F):-
N1 is N - 1,
Sum is A + B,
fib(N1, B, Sum,F).
fib(0,1).
fib(N,F):-
N > 0,
N1 is N+1,
fib(N1, 0, 1, F).

%add A to B only if B is even and return the result, else return A
addIfEven(A, B, Res):-
(0 is mod(B, 2) ->
Res is A + B; Res = A).

%count's upward from 0 to infinity
%get fib of count and if the result is less than the limit
%add it else return the total so far
sumUpWhileBelow(Limit,Cnt,TotalEvenFib,R):-
FibCnt is Cnt+1,
memo(fib(FibCnt,FibRes)),
(FibRes =< Limit ->
(addIfEven(TotalEvenFib,FibRes, NewTotal),
sumUpWhileBelow(Limit,FibCnt,NewTotal,R))
;
fin(TotalEvenFib,R)
).
fin(R,R).

sumUpWhileBelow(N,R):-
sumUpWhileBelow(N,0,0,R).


Problem 3

:-use_module(library(clpfd)).

% solves the problem, but super fucking slow. Bleep!
factors(N, L):-
findall(X, (X in 1..N, 0 #= N rem X, indomain(X)), L).

prime(P):-
factors(P, L), L = [1, P].

solve(N, LargestPrimeFactor):-
factors(N, Factors), include(prime, Factors, Primes), max_member(LargestPrimeFactor, Primes).


Problem 4
solve(R):-
findall(P, get_palindromes(P), PalindromeList),
max_list(PalindromeList, R).
get_palindromes(N):-
between(100,999,I),
between(I,999,J),
N is I * J,
palindrome(N).

palindrome(N):-
number_codes(N, A),
reverse(A, B),
A = B.

Re: Lets Start A Thread For Solving Problems From Projecteuler.net by Ogbeozioma: 6:12pm On Dec 11, 2015
Celebrimbor:
oboy, how far you don go for the solving and learning?

I have solved about 40 of the questions and these have taught me alone about mathematics and it has improved my problem solving skills... working on a couple more. Aiming for 50 nw.

what about u?
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by Ogbeozioma: 6:30pm On Dec 11, 2015
DonSegmond:
Solutions in Prolog





nice job man but I think it's better to post pseudocode and algorithm to your solution rather than the actual code so people who do not know your language can also benefit from ur solution.
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by Celebrimbor(m): 11:48pm On Dec 12, 2015
Ogbeozioma:

I have solved about 40 of the questions and these have taught me alone about mathematics and it has improved my problem solving skills... working on a couple more. Aiming for 50 nw.
what about u?
wow nice. i have solved 10. so you are the oziomajnr on the ranking??
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by Ogbeozioma: 6:58am On Dec 13, 2015
Celebrimbor:
wow nice. i have solved 10. so you are the oziomajnr on the ranking??


yeah I'm oziomajnr, but do u guys know the number1 guy? themark626 and the number 2 guy ope. The number 3 guy is my classmate.
I saw ur post on discreet mathematics hw far have u gone?
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by Celebrimbor(m): 12:22pm On Dec 13, 2015
Ogbeozioma:


yeah I'm oziomajnr, but do u guys know the number1 guy? themark626 and the number 2 guy ope. The number 3 guy is my classmate.
I saw ur post on discreet mathematics hw far have u gone?
nope. but i would like to know him too. As for my discrete mathematics growth, well i stopped for a long time but i picked it up recently and am currently studying the principles of counting. i never really thought it was important until recently. by the way i go by the name Celebrimbor on the ranking.
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by themark626: 8:01am On Dec 04, 2016
Hi guys. I just found this thread. How active are you guys on Project Euler?
Re: Lets Start A Thread For Solving Problems From Projecteuler.net by kudaisi(m): 8:39am On Dec 04, 2016

1 Like

(1) (Reply)

Quadratic Equation Solver for Android / I Want To Learn Programming On My Own, Where Do I Start? / Java Developers Learning Community Abuja

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.