diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2022-04-11 02:33:25 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2022-04-11 02:33:25 +0800 |
| commit | 57f22b225b9fe44b0144b6c4d6581a05e885c8cf (patch) | |
| tree | 34072096291201f485e6f1465a92f41fecdfc6a9 /challenge-159/java/Moebius.java | |
| parent | 7a083e3ad4201442badb8b6ff67f21cc2ec53469 (diff) | |
| download | perlweeklychallenge-club-57f22b225b9fe44b0144b6c4d6581a05e885c8cf.tar.gz perlweeklychallenge-club-57f22b225b9fe44b0144b6c4d6581a05e885c8cf.tar.bz2 perlweeklychallenge-club-57f22b225b9fe44b0144b6c4d6581a05e885c8cf.zip | |
correct filing again
Diffstat (limited to 'challenge-159/java/Moebius.java')
| -rw-r--r-- | challenge-159/java/Moebius.java | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/challenge-159/java/Moebius.java b/challenge-159/java/Moebius.java deleted file mode 100644 index b52e049ca8..0000000000 --- a/challenge-159/java/Moebius.java +++ /dev/null @@ -1,79 +0,0 @@ -// The Weekly Challenge 159 -// Task 2 Moebius Function -// Usage: java Moebius N - -public class Moebius -{ - public static void main(String[] args) - { - int N = 1; - try { - N = Integer.parseInt(args[0]); - } catch (Exception e) { - System.err.print("Please use a positive integer "); - System.err.println("as your parameter."); - System.exit(0); - } - double[][] complex1 = new double[][] { {1, 0} , {0, 1} }; - double[][] complex2 = new double[][] { {0, 1} , {-1, 0} }; - System.out.println(Math.round(mu(N))); - } - - - public static double mu(int n) - { - double[][] sum = ithRootOfUnityModuloN(1, n); - LOOP: for (int i=2; i<n; i++) - { - for (int s=2; s<n; s++) - { - if ( (i*s) % n == 0 ) - continue LOOP; - } - sum = complexAddition(sum, ithRootOfUnityModuloN(i,n)); - } - return sum[0][0]; - } - - - public static double[][] complexAddition(double[][] c1, double[][] c2) - { - double a = c1[0][0]; - double b = c1[0][1]; - double c = c1[1][0]; - double d = c1[1][1]; - double e = c2[0][0]; - double f = c2[0][1]; - double g = c2[1][0]; - double h = c2[1][1]; - return new double[][] {{ a+e, b+f }, { c+g, d+h }}; - } - - - - public static double[][] complexMultiplication(double[][] c1, double[][] c2) - { - double a = c1[0][0]; - double b = c1[0][1]; - double c = c1[1][0]; - double d = c1[1][1]; - double e = c2[0][0]; - double f = c2[0][1]; - double g = c2[1][0]; - double h = c2[1][1]; - return new double[][] {{a*e+b*g, a*f+b*h}, {c*e+d*g, c*f+d*h}}; - } - - - - public static double[][] ithRootOfUnityModuloN(int i , int n) - { - double realPart = Math.cos(2*Math.PI*i/n); - double imaginaryPart = Math.sin(2*Math.PI*i/n); - double[][] result = new double[][] { - {realPart, imaginaryPart}, - {-imaginaryPart, realPart} - }; - return result; - } -} |
