a-conjecture-of-mine

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

commit 6fe7de90c68b2d3cedeb26ccb03c10c60fbc1a87
parent 231a2b0c16af7c8ce001ad8d480f72d0ada6b87c
Author: Pablo Emilio Escobar Gaviria <pablo-escobar@riseup.net>
Date:   Sat, 23 Jan 2021 04:34:25 +1000

Added an APL version

Diffstat:
MMakefile | 3+--
Ascript.apl | 24++++++++++++++++++++++++
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -2,7 +2,7 @@ c-bin:
 	gcc -O2 -o bin/c ./c/main.c
 
 cpp-bin:
-	g++ -O2 -o ./bin/cpp -std=c++11 -pthread ./c++/main.cpp
+	g++ -O2 -o ./bin/cpp -std=c++11 ./c++/main.cpp
 
 elixir-bin:
 	elixirc -o bin/elixir ./elixir/main.ex
@@ -11,7 +11,6 @@ go-bin:
 	cd ./go/
 	go build
 	mv ./go ../bin/go
-	cd ..
 
 haskell-bin:
 	ghc --make -O -o ./bin/haskell ./haskell/Main.hs \
diff --git a/script.apl b/script.apl
@@ -0,0 +1,24 @@
+⍝ This script 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 interger.
+
+⍝ Computes the sum of the digits of a positive integer N
+∇ SUM←SUMDIGITS N
+  SUM←+/10|⌊N÷10⋆(⍳⌊(10⍟N)+1)-1
+∇
+
+⍝ Given a positive integer A, returns 1 if the conjecture holds for all pairs
+⍝ (A, B) with B=1, ..., A and 0 otherwise
+∇ RES←TEST A
+  BS←⍳A
+  SUMSB←SUMDIGITS¨BS
+  SUMSAPLUSB←SUMDIGITS¨(BS+A)
+  RES←∧/0=9|(SUMSAPLUSB-SUMSB+A)
+∇
+
+⍝ Checks if the conjecture holds for all pairs (A, B) with A, B = 1, ..., MAX
+∇ RES←CONJECTUREHOLDSUPTO MAX
+  RES←∧/TEST¨⍳MAX
+∇
+