From 3a4a184c6edee15846c7b030209bba2633990176 Mon Sep 17 00:00:00 2001 From: Leonardo Diaz Date: Mon, 6 Sep 2021 12:02:51 -0300 Subject: [PATCH 1/2] my solution --- src/main/java/payapal/Perfection.java | 42 +++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/payapal/Perfection.java diff --git a/src/main/java/payapal/Perfection.java b/src/main/java/payapal/Perfection.java new file mode 100644 index 0000000..4b9a80a --- /dev/null +++ b/src/main/java/payapal/Perfection.java @@ -0,0 +1,42 @@ +package main.java.payapal; + +public class Perfection { + + private static Perfection perf; + + public synchronized static Perfection getPerf() { + if (perf == null) { + perf = new Perfection(); + } + return perf; + } + + + public static boolean isPerfect(long candidate) { + boolean retVal; + long[] divisors = GetDivisors(candidate); + int sum = 0; + for (int d = 0; d < 1000; d++) + { + sum = sum + divisors[d]; + } + if (sum == candidate) + retVal = true; + return retVal; + } + + + private static long[] GetDivisors(long candidate) { + long[] divisors = new long[]; + int d = 0; + for (long i = 0; i < candidate; i++) { + long foo = candidate / i; + if (foo * i == candidate) { + divisors[d] = i; + d = d + 1; + } + } + return divisors; + } + +} \ No newline at end of file From 577f91e6429e0c3e83251f563f6f6d77470367cf Mon Sep 17 00:00:00 2001 From: Leonardo Diaz Date: Mon, 13 Sep 2021 14:03:52 -0300 Subject: [PATCH 2/2] add readme --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b90d979..ad67389 100644 --- a/README.md +++ b/README.md @@ -1 +1,10 @@ -JavaCodeReview + This class determine if a number is perfection or not. + +Definition of a Perfect Number: +In mathematics a perfect number is defined as an integer which is the sum of its proper +positive divisors; that is, the sum of the positive divisors not including the number itself. +Some examples of perfect numbers are: + +6 = 1 + 2 + 3 +28 = 1 + 2 + 4 + 7 + 14 +496 = 1 + 2 + 4 + 8 + 16 + 31 + 62 + 124 + 248