aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-156/cheok-yin-fung/perl/ch-1.pl1
-rw-r--r--challenge-159/java/Moebius.java79
-rw-r--r--challenge-159/julia/ch-2.jl28
-rw-r--r--challenge-159/perl/ch-1.pl45
-rw-r--r--challenge-159/perl/ch-2.pl63
5 files changed, 0 insertions, 216 deletions
diff --git a/challenge-156/cheok-yin-fung/perl/ch-1.pl b/challenge-156/cheok-yin-fung/perl/ch-1.pl
index 24941c76d7..fd7163fb4d 100644
--- a/challenge-156/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-156/cheok-yin-fung/perl/ch-1.pl
@@ -37,4 +37,3 @@ for my $k (2..$ub) {
say join ", ", @pern_num[0..$N-1];
-
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;
- }
-}
diff --git a/challenge-159/julia/ch-2.jl b/challenge-159/julia/ch-2.jl
deleted file mode 100644
index a726b3b3f0..0000000000
--- a/challenge-159/julia/ch-2.jl
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-function irn(i,n)
- return cos(2π*i/n)+sin(2π*i/n)im
-end
-
-
-
-function möbius(n)
- if n==1
- return 1
- end
- if n==2
- return -1
- end
- primitive_roots=Any[]
- push!(primitive_roots, irn(1, n))
- for i in 2:n-1
- for s in 2:n-1
- if (i*s)%n==0
- @goto label1
- end
- end
- push!(primitive_roots, irn(i,n))
- @label label1
- end
- return round(Int,real(sum(primitive_roots)))
-end
diff --git a/challenge-159/perl/ch-1.pl b/challenge-159/perl/ch-1.pl
deleted file mode 100644
index d6500f2c5f..0000000000
--- a/challenge-159/perl/ch-1.pl
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/perl
-# The Weekly Challenge 159
-# Task 1 Farey Sequence
-
-# https://en.wikipedia.org/wiki/Farey_sequence#Next_term
-
-use v5.22.0;
-use warnings;
-use POSIX;
-
-my $N = $ARGV[0] if defined($ARGV[0]);
-
-say farey($N) if defined($ARGV[0]);
-
-
-
-sub farey {
- my $n = $_[0];
- die "The parameter should be a positive integer." if $n==0;
- my ($g, $h) = ([0,1], [1, $n]);
- my @terms;
- do {
- push @terms, "".join("/", $g->@*);
- my ($a, $b) = $g->@*;
- my ($c, $d) = $h->@*;
- my ($p, $q) = (
- $c*floor (($n+$b)/$d) - $a,
- $d*floor(($n+$b)/$d) - $b
- );
- ($g, $h) = ($h, [$p, $q]);
- } while (!($h->[0] == 1 && $h->[1] == 1));
- push @terms, join("/", $g->@*), join("/", $h->@*);
- return join(", ",@terms) . ".";
-}
-
-
-
-use Test::More tests => 3;
-ok(
- "0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1."
- eq farey(5), "Example 1");
-ok(
- "0/1, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 2/5, 3/7, 1/2, 4/7, 3/5,"
- . " 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 1/1." eq farey(7), "Example 2");
-ok("0/1, 1/4, 1/3, 1/2, 2/3, 3/4, 1/1." eq farey(4), "Example 3");
diff --git a/challenge-159/perl/ch-2.pl b/challenge-159/perl/ch-2.pl
deleted file mode 100644
index 0d58c1eeb4..0000000000
--- a/challenge-159/perl/ch-2.pl
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/perl
-# The Weekly Challenge 159
-# Task 2 Moebius Function
-# Usage: ch-2.pl $N
-use v5.22.0;
-use warnings;
-use Math::Complex;
-use List::Util qw/any/;
-use POSIX;
-
-use constant PI => 2*acos(0);
-
-
-if (defined($ARGV[0])) {
- my $N = $ARGV[0];
- say "mu($N) = ", mo($N);
-}
-
-
-sub irn {
- my $i = $_[0];
- my $n = $_[1];
- return Math::Complex->make(
- cos 2*PI*$i/$n, sin 2*PI*$i/$n
- );
-}
-
-
-
-sub mo {
- my $n = $_[0];
- return 1 if $n == 1;
- return -1 if $n == 2;
- my $sum = irn(1, $n);
- for my $i (2..$n-1) {
- next if any { ($i*$_) % $n == 0} (2..$n-1);
- $sum += irn($i, $n);
- }
- # say "# intermediate sum: ", Re($sum), "\n\n";
- return floor(Re($sum)+0.5);
-}
-
-
-
-use Test::More tests => 18;
-ok mo(2) == -1, "test for 2";
-ok mo(5) == -1, "Example 1";
-ok mo(10) == 1, "Example 2";
-ok mo(20) == 0, "Example 3";
-ok mo(22) == 1, "test for 22";
-ok mo(41) == -1, "test for 41";
-ok mo(42) == -1, "test for 42";
-ok mo(43) == -1, "test for 43";
-ok mo(44) == 0, "test for 44";
-ok mo(45) == 0, "test for 44";
-ok mo(46) == 1, "test for 46";
-ok mo(47) == -1, "test for 47";
-ok mo(48) == 0, "test for 48";
-ok mo(49) == 0, "test for 49";
-ok mo(50) == 0, "test for 50";
-ok mo(3276) == 0, "test for 3276";
-ok mo(3277) == 1, "test for 3277";
-ok mo(3278) == -1, "test for 3278";