a-conjecture-of-mine

An exercise on polyglossy: the same problem solved on multiple languages

commit 23c7444ae60da434cfd3337e1766869eaa087306
parent 323eef69cbaedca054ec85106fbc9a92f9fec2ea
Author: Pablo Escobar Gaviria <gark.garcia@protonmail.com>
Date:   Thu, 16 Jan 2020 09:35:06 -0200

Formated the Kotlin and Java implementations.

Diffstat:
M.gitignore | 2+-
RElixir/digital_sum.ex -> Elixir/main.ex | 0
MIdris/Main.idr | 2+-
AJava/Main.java | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AJava/bin.jar/conjecture/Main.class | 0
DJava/src/conjecture/Main.java | 65-----------------------------------------------------------------
DKotlin/Kotli.iml | 13-------------
AKotlin/bin.jar | 0
RKotlin/src/main.kt -> Kotlin/main.kt | 0
MREADME.md | 40+++++++++++++++++++++++++++++++---------
10 files changed, 98 insertions(+), 89 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -3,9 +3,9 @@
 *.img
 *.IMG
 *.beam
+*.ja*.jarr
 bin
 build
 *.un~
-Statistics
 Latex
 Cuda
diff --git a/Elixir/digital_sum.ex b/Elixir/main.ex
diff --git a/Idris/Main.idr b/Idris/Main.idr
@@ -12,7 +12,7 @@ main : IO Int
 main = do
     args <- getArgs
         
-    case head' args >>= Just . readDec of
+    case readDeci <$> head' args of
       Just [(max, "")] =>
         if counter' max then exitFailure else exitSuccess
       _ => exitInvalidInput
diff --git a/Java/Main.java b/Java/Main.java
@@ -0,0 +1,65 @@
+package conjecture;
+
+// The following program is a simple test for the following conjecture:
+
+// Let S: N -> N be the sum of the digits of a positive integer.
+// For all A and B in N, S(A + B) = S(A) + S(B) - 9k, where k is an integer.
+
+import java.util.InputMismatchException;
+
+public class Main {
+    private static final int SUCCESS = 0;
+    private static final int FAIL = 1;
+    private static final int INVALID_INPUT = 2;
+
+    public static void main(String[] args) {
+        try {
+            int max = Integer.parseInt(args[0]);
+
+            if (counterexample(max)) {
+                System.exit(FAIL);
+            } else {
+                System.exit(SUCCESS);
+            }
+        } catch (InputMismatchException error) {
+            System.exit(INVALID_INPUT);
+        }
+
+    }
+
+    private static Boolean counterexample(int max) {
+        int[] sum = getSums(max);
+
+        for (int a = 0; a <= max; a++)
+            for (int b = a; b <= max; b++) {
+                int diff = sum[a + b] - (sum[a] + sum[b]);
+
+                if (diff % 9 != 0)
+                    return true;
+            }
+
+        return false;
+    }
+
+    private static int[] getSums(int max) {
+        int maxRange = 2 * (max + 1);
+        int[] sums = new int[maxRange];
+
+        for (int i = 0; i < maxRange; i++)
+            sums[i] = sumDigits(i);
+
+        return sums;
+    }
+
+    private static int sumDigits(int n) {
+        int num = Math.abs(n), sum = 0;
+
+        while (num > 0) {
+            sum += num % 10;
+            num /= 10;
+        }
+
+        return sum;
+    }
+}
+
diff --git a/Java/bin.jar/conjecture/Main.class b/Java/bin.jar/conjecture/Main.class
Binary files differ.
diff --git a/Java/src/conjecture/Main.java b/Java/src/conjecture/Main.java
@@ -1,64 +0,0 @@
-package conjecture;
-
-// The following program is a simple test for the following conjecture:
-
-// Let S: N -> N be the sum of the digits of a positive integer.
-// For all A and B in N, S(A + B) = S(A) + S(B) - 9k, where k is an integer.
-
-import java.util.InputMismatchException;
-
-public class Main {
-    private static final int SUCCESS = 0;
-    private static final int FAIL = 1;
-    private static final int INVALID_INPUT = 2;
-
-    public static void main(String[] args) {
-        try {
-            int max = Integer.parseInt(args[0]);
-
-            if (getCounterexample(max)) {
-                System.exit(FAIL);
-            } else {
-                System.exit(SUCCESS);
-            }
-        } catch (InputMismatchException error) {
-            System.exit(INVALID_INPUT);
-        }
-
-    }
-
-    private static Boolean getCounterexample(int max) {
-        int[] sum = getSums(max);
-
-        for (int a = 0; a <= max; a++)
-            for (int b = a; b <= max; b++) {
-                int diff = sum[a + b] - (sum[a] + sum[b]);
-
-                if (diff % 9 != 0)
-                    return true;
-            }
-
-        return false;
-    }
-
-    private static int[] getSums(int max) {
-        int maxRange = 2 * (max + 1);
-        int[] sums = new int[maxRange];
-
-        for (int i = 0; i < maxRange; i++)
-            sums[i] = sumDigits(i);
-
-        return sums;
-    }
-
-    private static int sumDigits(int n) {
-        int num = Math.abs(n), sum = 0;
-
-        while (num > 0) {
-            sum += num % 10;
-            num /= 10;
-        }
-
-        return sum;
-    }
-}-
\ No newline at end of file
diff --git a/Kotlin/Kotli.iml b/Kotlin/Kotli.iml
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="JAVA_MODULE" version="4">
-  <component name="NewModuleRootManager" inherit-compiler-output="true">
-    <exclude-output />
-    <content url="file://$MODULE_DIR$">
-      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
-    </content>
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="library" name="KotlinJavaRuntime" level="project" />
-  </component>
-</module>-
\ No newline at end of file
diff --git a/Kotlin/bin.jar b/Kotlin/bin.jar
Binary files differ.
diff --git a/Kotlin/src/main.kt b/Kotlin/main.kt
diff --git a/README.md b/README.md
@@ -2,18 +2,30 @@
 An exercise on _polyglossy_. The same problem solved on multiple languages.
 
 # The Problem - Mathematicians Version
-Let <img src="https://latex.codecogs.com/svg.latex?S:&space;\mathbb{N}\rightarrow&space;\mathbb{N}"/> be the sum of the digits of a positive integer in a _[base 10 positional number system](https://en.wikipedia.org/wiki/Positional_notation)_. We have:
+Let 
+<img src="https://latex.codecogs.com/svg.latex?S:&space;\mathbb{N}\rightarrow&space;\mathbb{N}"/> 
+be the sum of the digits of a positive integer in a 
+_[base 10 positional number system](https://en.wikipedia.org/wiki/Positional_notation)_. 
+We have:
 
 <img src="https://latex.codecogs.com/svg.latex?\forall&space;a,&space;b&space;\in&space;\mathbb{N},&space;S_{a&space;&plus;&space;b}&space;\equiv&space;S_a&space;&plus;&space;S_b&space;\;\(\textup{mod}\;&space;9&space;\)"/>
 
-This conjecture can be generalized for any _positional number system_. Check out `proof.pdf` for more information.
+This conjecture can be generalized for any _positional number system_. 
+Check out `proof.pdf` for more information.
 
 # The Problem - Programmers Verison
 
-Let `S(n: uint) -> uint` be the sum of the digits of `n` in _[base 10](https://en.wikipedia.org/wiki/Decimal)_. Then, for all `a` and `b` of type `uint`, `S(a + b) - ( S(a) + S(b) ) % 9 == 0`.
+Let `S(n: uint) -> uint` be the sum of the digits of `n` in 
+_[base 10](https://en.wikipedia.org/wiki/Decimal)_. Then, for all `a` and `b` 
+of type `uint`, `S(a + b) - ( S(a) + S(b) ) % 9 == 0`.
 
 # Performance
-The conjecture was [proved by exhaustion](https://en.wikipedia.org/wiki/Proof_by_exhaustion) for the interval <img src="https://latex.codecogs.com/svg.latex?[0,&space;10^4]"/> in multiple language implementations. The performance of each language was then avaliated as the following _(*)_:
+
+The conjecture was 
+[proved by exhaustion](https://en.wikipedia.org/wiki/Proof_by_exhaustion) for 
+the interval <img src="https://latex.codecogs.com/svg.latex?[0,&space;10^4]"/> 
+in multiple language implementations. The performance of each language was then 
+avaliated as the following _(*)_:
 
 |Language      |Milliseconds|
 |--------------|------------|
@@ -49,7 +61,9 @@ The following algorithm should be used:
 for a between 0 and MAX:
     for b between 0 and a:
         check if the conjecture holds for the pair (a, b)
-        if it fails, exit the process with exit code 1
+        
+        if it fails:
+            exit the process with exit code 1
 
 exit the process with exit code 0 
 ```
@@ -70,9 +84,11 @@ addapted to the following:
 for i between 0 and NPROCESSES:
     lauch a process running counterexample(start=i)
 
-for i between 0 and NPROCESSES:
-    wait for the i-th process to signal it's results
-    if the process signals a counterexample was found, exit the main process with exit code 1
+for each opened process:
+    wait for the process to signal it's results
+    
+    if the process signals a counterexample was found:
+        exit the main process with exit code 1
 
 exit the main process with exit code 0
 ```
@@ -83,7 +99,9 @@ The algorith for the `counterexample` routine should be the following:
 for a between 0 and MAX by steps of NPROCESSES:
     for b between 0 and a:
         check if the conjecture holds for the pair (a, b)
-        if it fails, signal to the main process that a counterexample was found
+
+        if it fails:
+            signal to the main process that a counterexample was found
 
 signal to the main process that no counterexample was found
 ```
@@ -92,3 +110,7 @@ This scheme ensures computations are envenlly distributed across processes.
 Note that the routine should only signal wheter or not a counterexample was 
 found.
 
+### Caching
+
+TODO
+