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 99c8e7eb58c50ede69165d42feedf15e8a6e7ca7 Mon Sep 17 00:00:00 2001 From: Leonardo Diaz Date: Mon, 20 Sep 2021 14:20:55 -0300 Subject: [PATCH 2/2] by facundo --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b90d979..7eb9b5f 100644 --- a/README.md +++ b/README.md @@ -1 +1,8 @@ -JavaCodeReview +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 \ No newline at end of file