Since Java has introduced lambda, writing code has become a breeze especially when it comes to expressing what you want to computer to do rather than how to do it. The following is a question from Project Euler and is solved using lambdas in Java8.

It exactly matches the list of 3 things that we made to solve the problem. It iterates from 2 to 10000 and checks if the number is amicable and adds it, without the boilerplate. This style when applied to enterprise level applications makes them low maintenance and one can easily map the code to requirements.

Let d(n) be defined as the sum of proper divisors ofn(numbers less thannwhich divide evenly inton). If d(a) =band d(b) =a, wherea≠b, thenaandbare an amicable pair and each ofaandbare called amicable numbers. For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. Evaluate the sum of all the amicable numbers under 10000.

A simple brute force solution is to check every number from 2 to 10000 and if its an amicable number then add it to sum. Listing it in steps you are basically doing 3 things:

- Take numbers from 2 to 10000
- If number is amicable
- Add it

It exactly matches the list of 3 things that we made to solve the problem. It iterates from 2 to 10000 and checks if the number is amicable and adds it, without the boilerplate. This style when applied to enterprise level applications makes them low maintenance and one can easily map the code to requirements.

Really nice blog,i enjoyed your infomations. Thank you and i will expect more in future.

ReplyDeleteJAVA Training in Chennai

Java training institute in chennai

Selenium Training in Chennai

Hadoop Training in Chennai

Python Training in Chennai

Software testing training in chennai

JAVA Training in Chennai

Java Training in Velachery