aboutsummaryrefslogtreecommitdiff
path: root/challenge-169/michael-dicicco/java
diff options
context:
space:
mode:
authorRyan Thompson <rjt-pl@users.noreply.github.com>2022-06-16 17:10:46 -0600
committerGitHub <noreply@github.com>2022-06-16 17:10:46 -0600
commitc92803076d8d8f9fee7bb945e0e268399e32cdd3 (patch)
treef59a55e4a378f42fa80a5b6f13238b12088e7d4b /challenge-169/michael-dicicco/java
parent40198d275c123f30a185aea4da69f2c3b9424dab (diff)
parent7c2fa584618da574d42b1713c3c343423991c781 (diff)
downloadperlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.tar.gz
perlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.tar.bz2
perlweeklychallenge-club-c92803076d8d8f9fee7bb945e0e268399e32cdd3.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-169/michael-dicicco/java')
-rw-r--r--challenge-169/michael-dicicco/java/ch1.java54
-rw-r--r--challenge-169/michael-dicicco/java/ch2.java70
2 files changed, 124 insertions, 0 deletions
diff --git a/challenge-169/michael-dicicco/java/ch1.java b/challenge-169/michael-dicicco/java/ch1.java
new file mode 100644
index 0000000000..d9978ca311
--- /dev/null
+++ b/challenge-169/michael-dicicco/java/ch1.java
@@ -0,0 +1,54 @@
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author mddicicco
+ */
+public class ch1 {
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ List<String> brilliants = new ArrayList<>();
+ for (long i = 4L; i < 300L; i++) {
+ if (isBrilliant(primeFactors(i))){
+ brilliants.add(Long.toString(i));
+ }
+ }
+ System.out.println(String.join(", ", brilliants));
+ }
+
+ public static Boolean isBrilliant(List<Long> factors) {
+ return (factors.size() == 2 && factors.get(0).toString().length() == factors.get(1).toString().length());
+ }
+
+ public static List<Long> primeFactors(long n) {
+ List<Long> output = new ArrayList<>();
+
+ // Print the number of 2s that divide n
+ while (n % 2L == 0L) {
+ output.add(2L);
+ n /= 2L;
+ }
+
+ // n must be odd at this point. So we can
+ // skip one element (Note i = i +2)
+ for (long i = 3L; i <= Math.sqrt(n); i += 2L) {
+ // While i divides n, print i and divide n
+ while (n % i == 0) {
+ output.add(i);
+ n /= i;
+ }
+ }
+
+ // This condition is to handle the case when
+ // n is a prime number greater than 2
+ if (n > 2L) {
+ output.add(n);
+ }
+ return output;
+ }
+
+}
diff --git a/challenge-169/michael-dicicco/java/ch2.java b/challenge-169/michael-dicicco/java/ch2.java
new file mode 100644
index 0000000000..94d53d318c
--- /dev/null
+++ b/challenge-169/michael-dicicco/java/ch2.java
@@ -0,0 +1,70 @@
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author mddicicco
+ */
+public class ch2 {
+ static final double PRECISION = Math.pow(10,12);
+ public static void main(String[] args){
+
+ List<String> achilles_nums = new ArrayList<>();
+
+ for(long i = 72; i < 1801; i++){
+ if(isAchilles(primeFactors(i), i)){
+ achilles_nums.add(Long.toString(i));
+ }
+ }
+ System.out.println(String.join(", ", achilles_nums));
+ }
+ public static Boolean isAchilles(List<Long> factors, Long given){
+ for(Long factor : factors){
+ if(!(given % Math.pow(factor, 2) == 0))
+ return false;
+ }
+
+
+
+ for(long i = 2; i <= 9; i++){
+ double root = Math.round(nthRoot(given, i) * PRECISION)/PRECISION;
+
+ if (Math.floor(root) == root){
+
+ return false;
+ }
+ }
+ return true;
+
+ }
+ public static double nthRoot(double someNumber, double n){
+ return Math.pow(n, ((1.0 / n ) * (Math.log(someNumber) / Math.log(n))));
+ }
+
+ public static List<Long> primeFactors(long n) {
+ List<Long> output = new ArrayList<>();
+
+ // Print the number of 2s that divide n
+ while (n % 2L == 0L) {
+ output.add(2L);
+ n /= 2L;
+ }
+
+ // n must be odd at this point. So we can
+ // skip one element (Note i = i +2)
+ for (long i = 3L; i <= Math.sqrt(n); i += 2L) {
+ // While i divides n, print i and divide n
+ while (n % i == 0) {
+ output.add(i);
+ n /= i;
+ }
+ }
+
+ // This condition is to handle the case when
+ // n is a prime number greater than 2
+ if (n > 2L) {
+ output.add(n);
+ }
+ return output;
+ }
+}