a-conjecture-of-mine

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

commit 323eef69cbaedca054ec85106fbc9a92f9fec2ea
parent 3534aeddadee0b3403b2242781c56cda1fa711b9
Author: Pablo Escobar Gaviria <gark.garcia@protonmail.com>
Date:   Tue, 14 Jan 2020 12:59:33 -0200

Formatted the JS, Python, Ruby and Prolog implementations.

Diffstat:
Mscript.js | 4+---
Mscript.pl | 4++--
Mscript.py | 10+++-------
Mscript.rb | 13++++++-------
4 files changed, 12 insertions(+), 19 deletions(-)
diff --git a/script.js b/script.js
@@ -4,9 +4,6 @@
 // For all A and B in N, S(A + B) = S(A) + S(B) - 9k, where k is an interger.
 
 function sumDigits(n) {
-    if (isNaN(n) || !isFinite(n) || !n)
-        throw new TypeError
-
     let parc = Math.abs(n), sum = 0;
 
     while (parc > 0) {
@@ -37,3 +34,4 @@ export function getCounterExp(max) {
 
     return false;
 }
+
diff --git a/script.pl b/script.pl
@@ -26,4 +26,5 @@ iter(A, B) :-
     forall(between(0, B, X), test_pair(A, X)).
 
 conjecture(M) :-
-    forall(between(0, M, X), iter(X, X)).-
\ No newline at end of file
+    forall(between(0, M, X), iter(X, X)).
+
diff --git a/script.py b/script.py
@@ -14,14 +14,9 @@ def sum_digits(n: int) -> int:
     return sum_d
 
 def get_sums(max: int) -> list:
-    output = []
+    return [sum_digits(i) for i in range(2 * max)]
 
-    for i in range(2 * max):
-        output.append(sum_digits(i))
-
-    return output
-
-def get_counterexmpl(max: int) -> bool:
+def counterexempl(max: int) -> bool:
     sums = get_sums(max)
 
     for a in range(max + 1):
@@ -32,3 +27,4 @@ def get_counterexmpl(max: int) -> bool:
                 return True
     
     return False
+
diff --git a/script.rb b/script.rb
@@ -3,7 +3,7 @@
 # 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 interger.
 
-def sumDigits(i)
+def sum_digits(i)
     part = i.abs()
     sum = 0
 
@@ -16,18 +16,18 @@ def sumDigits(i)
     return sum
 end
 
-def getSums(max)
+def get_sums(max)
     output = []
     
     for i in 0..((max + 1) * 2)
-        output << sumDigits(i)
+        output << sum_digits(i)
     end
 
     return output
 end
 
-def get_counterexpl(max)
-    sums = getSums(max)
+def counterexempl(max)
+    sums = get_sums(max)
 
     for a in (0..max)
         for b in (a..max)
@@ -40,4 +40,4 @@ def get_counterexpl(max)
     end
 
     return false
-end-
\ No newline at end of file
+end