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.

Aivivu chuyên vé máy bay, tham khảo

ReplyDeleteve may bay di my gia re

vietnam airlines quốc tế

vé máy bay từ đức về sài gòn

giá vé máy bay từ moscow về hà nội

giá vé máy bay từ anh về việt nam

lịch bay từ pháp về việt nam

danh sách khách sạn cách ly tại quảng ninh

Aivivu chuyên vé máy bay, tham khảo

ReplyDeletegiá vé máy bay đi Mỹ khứ hồi

lịch bay từ mỹ về việt nam

vé máy bay vietjet từ nhật về việt nam

đặt vé máy bay từ đức về việt nam

vé máy bay giá rẻ từ Canada về Việt Nam

đặt vé máy bay từ hàn quốc về việt nam

giá khách sạn cách ly ở việt nam