a-conjecture-of-mine

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

commit 232f6d2a6fe228746645816ef71fb7c2ec674c1c
parent 29609246d206cf41bded94e62e013dc772a0416b
Author: Pablo Escobar Gaviria <gark.garcia@protonmail.com>
Date:   Wed,  5 Feb 2020 14:14:39 -0200

Minor adjustments.

Diffstat:
DExtra/Wasm/.gitignore | 1-
DExtra/Wasm/main.wasm | 0
DExtra/Wasm/main.wat | 75---------------------------------------------------------------------------
MJava/Main.java | 11++++++-----
DJava/bin.jar/conjecture/Main.class | 0
5 files changed, 6 insertions(+), 81 deletions(-)
diff --git a/Extra/Wasm/.gitignore b/Extra/Wasm/.gitignore
@@ -1 +0,0 @@
-test
diff --git a/Extra/Wasm/main.wasm b/Extra/Wasm/main.wasm
Binary files differ.
diff --git a/Extra/Wasm/main.wat b/Extra/Wasm/main.wat
@@ -1,75 +0,0 @@
-(module
-    ;; Check if the is any counterexample in {(x, y) | 0 <= x <= a, 0 <= y <= x}
-    (func (export "counterexempl") (param $a i32) (result i32)
-        (local $b i32)
-
-        (block $break_0     ;; while a != 0
-	    (loop $while_0
-                (br_if $break_0 (i32.eqz (local.get $a)))				
-	        (local.set $b (local.get $a))                           ;; b = a
-
-    	        (block $break_1                                         ;; while b != 0
-	            (loop $while_1
-		        (br_if $break_1 (i32.eqz (local.get $b)))
-			(if (call $test (local.get $a) (local.get $b))                  ;; if test(a, b)
-                            (block (i32.const 1) (return))                              ;; return 1
-                            (block                                                      ;; else
-			        (local.set $b (i32.sub (local.get $b) (i32.const 1)))   ;; b -= 1
-			        (br $while_1)                                           ;; continue
-                            )
-			)
-     		    )
-                )
-    
-	        (local.set $a (i32.sub (local.get $a) (i32.const 1)))   ;; a -= 1
-	        (br $while_0)                                           ;; continue
-	    )
-        )
-
-        (i32.const 0)   ;; return 0
-    )
-
-    ;; Calculates the sums of the digits of a non-negative integer.
-    (func $sum_digits (param $n i32) (result i32)
-        (local $sum i32)
-        (local.set $sum (i32.const 0))
-
-        (block $break
-	    (loop $while	
-	        ;; Break if n == 0i32
-	        (br_if $break (i32.eqz (local.get $n)))
-		
-	        ;; sum += n % 10
-	        (local.set $sum 
-		    (i32.add
-                        (local.get $sum) 
-		        (i32.rem_u (local.get $n) (i32.const 10))
-		    )
-	        )
-
-	        ;; n /= 10
-	        (local.set $n (i32.div_u (local.get $n) (i32.const 10)))
-
-	        ;; Go to `while`
-	        (br $while)
-	    )
-        )
-
-        (local.get $sum)    ;; return sum
-    )
-
-    ;; Checks if (sum_digits(a + b) - (sum_digits(a) + sum_digits(b))) % 9 != 0
-    (func $test (export "test") (param $a i32) (param $b i32) (result i32) 
-        (i32.ne
-            (i32.const 0) 
-	    (i32.rem_s
-		(i32.sub 
-		    (call $sum_digits (i32.add (local.get $a) (local.get $b)))
-		    (i32.add (call $sum_digits (local.get $a)) (call $sum_digits (local.get $b)))
-		) 
-	        (i32.const 9)
-	    )
-	)
-    )
-)
-
diff --git a/Java/Main.java b/Java/Main.java
@@ -1,5 +1,3 @@
-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.
@@ -21,7 +19,7 @@ public class Main {
             } else {
                 System.exit(SUCCESS);
             }
-        } catch (InputMismatchException error) {
+        } catch (Exception error) {
             System.exit(INVALID_INPUT);
         }
 
@@ -42,7 +40,7 @@ public class Main {
     }
 
     private static int[] getSums(int max) {
-        int maxRange = 2 * (max + 1);
+        int maxRange = 2 * max + 1;
         int[] sums = new int[maxRange];
 
         for (int i = 0; i < maxRange; i++)
@@ -51,8 +49,11 @@ public class Main {
         return sums;
     }
 
+    /**
+     * Calculates the sum of the digits of a positive integer.
+     */
     private static int sumDigits(int n) {
-        int num = Math.abs(n), sum = 0;
+        int num = n, sum = 0;
 
         while (num > 0) {
             sum += num % 10;
diff --git a/Java/bin.jar/conjecture/Main.class b/Java/bin.jar/conjecture/Main.class
Binary files differ.