Friday, June 30, 2017

Minimum Perimeter of Rectangle


import java.util.stream.Stream;

public class MinimumRectanglePerimeter {
     public static void main(String[] args) {
          System.out.println(perimeter(30));
     }

     public static int perimeter(int area) {
          return Stream.iterate((int) Math.sqrt(area), n -> n - 1).filter(n -> area % n == 0).map(n -> 2 * (n + area / n)).findFirst().get();
     }
}


Output:
22

No comments:

Post a Comment