I solved the fifth problem from Euler project in Clojure.
My first approach was not successful:
Even though it could compute the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder,
it didn't work for 1 to 20.
It consumed to much memory.
So I used pen and paper to devise a better approach to solve the problem.
I saw that the numbers from 1 to 10 which multiplied produce 2520 are 9, 8, 7 and 5.
What these numbers have in common is that they all have one prime factor with the highest possible multiplicity in the 1 to 10 range.
This is the code that I derived from those two facts:
which yields the right result.
Update:
As Leo pointed out in his comment, the answer is the least common multiple of the numbers from 1 to 20.
This is the final (more elegant and much simpler than the previous one) solution to the problem:
Record of experiments, readings, links, videos and other things that I find on the long road.
Registro de experimentos, lecturas, links, vídeos y otras cosas que voy encontrando en el largo camino.
Sunday, August 31, 2014
Euler Project: Problem 4 in Clojure
This is my solution in Clojure to the fourth problem from Euler project:
It was nice to practise with for.
It was nice to practise with for.
Books I read (January - August 2014)
January
- Pan, educación, libertad (Ψωμί, παιδεία, ελευθερία), Petros Márkaris
- NW London, Zadie Smith
- 101 cuentos clásicos de la China, Chang Shiru, Ramiro A. Calle
- Mr. Neighborly's Humble Little Ruby Book, Jeremy McAnally
February
- Blankets, Craig Thompson
March
- Practical Object-Oriented Design in Ruby, Sandi Metz
- Modern C++ Programming with Test-Driven Development, Jeff Langr
April
- Learning PHP, MySQL & JavaScript, Robin Nixon
- Measuring the world, Daniel Kehlmann
May
- El hombre que plantaba árboles, (L'homme qui plantait des arbres), Jean Giono
- Extreme Programming Explained, Embrace Change, Kent Beck
- Adiós, Chunky Rice, (Good-bye, Chunky Rice), Craig Thompson
June
- Eloquent Ruby, Russ Olsen
- Implementing Domain-Driven Design, Vaughn Vernon
July
- JavaScript Allongé, Reginald Braithwaite
- JavaScript: The Good Parts, Douglas Crockford
August
- Programming Clojure, (2nd edition), Stuart Halloway and Aaron Bedra
- Introduction to Computing, Explorations in Language, Logic and Machines, David Evans
- JavaScript Allongé, Reginald Braithwaite (2nd time)
- Pan, educación, libertad (Ψωμί, παιδεία, ελευθερία), Petros Márkaris
- NW London, Zadie Smith
- 101 cuentos clásicos de la China, Chang Shiru, Ramiro A. Calle
- Mr. Neighborly's Humble Little Ruby Book, Jeremy McAnally
February
- Blankets, Craig Thompson
March
- Practical Object-Oriented Design in Ruby, Sandi Metz
- Modern C++ Programming with Test-Driven Development, Jeff Langr
April
- Learning PHP, MySQL & JavaScript, Robin Nixon
- Measuring the world, Daniel Kehlmann
May
- El hombre que plantaba árboles, (L'homme qui plantait des arbres), Jean Giono
- Extreme Programming Explained, Embrace Change, Kent Beck
- Adiós, Chunky Rice, (Good-bye, Chunky Rice), Craig Thompson
June
- Eloquent Ruby, Russ Olsen
- Implementing Domain-Driven Design, Vaughn Vernon
July
- JavaScript Allongé, Reginald Braithwaite
- JavaScript: The Good Parts, Douglas Crockford
August
- Programming Clojure, (2nd edition), Stuart Halloway and Aaron Bedra
- Introduction to Computing, Explorations in Language, Logic and Machines, David Evans
- JavaScript Allongé, Reginald Braithwaite (2nd time)
Saturday, August 30, 2014
Interesting Talk: "Test-Driven JavaScript in Practice"
I've just watched this wonderful talk by Christian Johansen:
Thursday, August 28, 2014
Exercism: "Raindrops in Clojure"
I solved the Raindrops problem in Clojure.
This is my solution:
Where I used the code I wrote for the Prime factors kata in Clojure
You can nitpick my solution here or see all the exercises I've done so far in this repository.
This is my solution:
Where I used the code I wrote for the Prime factors kata in Clojure
You can nitpick my solution here or see all the exercises I've done so far in this repository.
Subscribe to:
Posts (Atom)