a-conjecture-of-mine

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

commit d9480e685948028ac01c435376232acb2b44d931
parent 6fe7de90c68b2d3cedeb26ccb03c10c60fbc1a87
Author: Pablo Emilio Escobar Gaviria <pablo-escobar@riseup.net>
Date:   Sat, 23 Jan 2021 07:49:10 +1000

Minor changes the APL implementation

Diffstat:
M.gitignore | 1+
MMakefile | 41+++++++++++++++++++++++++----------------
Mscript.apl | 14+++++++-------
3 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,3 +1,4 @@
 *.beam
 *.jar
+.apl.history
 bin
diff --git a/Makefile b/Makefile
@@ -1,29 +1,31 @@
-c-bin:
+.PHONY: all c cpp elixir go haskell java kotlin ocaml rust wasm mercury
+
+all: c cpp elixir go haskell java ocaml rust wasm
+
+c:
 	gcc -O2 -o bin/c ./c/main.c
 
-cpp-bin:
+cpp:
 	g++ -O2 -o ./bin/cpp -std=c++11 ./c++/main.cpp
 
-elixir-bin:
+elixir:
 	elixirc -o bin/elixir ./elixir/main.ex
 
-go-bin:
-	cd ./go/
-	go build
-	mv ./go ../bin/go
+go:
+	cd ./go/ && go build && mv ./go ../bin/go
 
-haskell-bin:
+haskell:
 	ghc --make -O -o ./bin/haskell ./haskell/Main.hs \
 	  && rm ./haskell/*.o ./haskell/*.hi
 
-java-bin:
+java:
 	javac ./java/Main.java
 	jar cfe ./bin/java.jar Main ./java/Main.class && rm ./java/*.class
 
-kotlin-bin:
+kotlin:
 	kotlinc ./kotlin/main.kt -d ./bin/kotlin.jar
 
-ocaml-bin:
+ocaml:
 	ocamlfind                  \
 		ocamlopt                 \
 		-thread                  \
@@ -33,13 +35,20 @@ ocaml-bin:
 		-linkpkg ./ocaml/main.ml \
 	  && rm ./ocaml/*.cmi ./ocaml/*.cmx ./ocaml/*.o
 
-rust-bin:
+rust:
 	rustc -v -O -o ./bin/rust ./rust/main.rs
 
-wasm-bin:
+wasm:
 	wat2wasm ./wasm/main.wat -o ./bin/wasm.wasm
 
-mercury-bin:
-	mmc mercury/main.m -o bin/mercury
-	rm bin/*.o bin/*.c
+mercury:
+	cd mercury && mmc main.m -o bin/mercury
+	rm mercury/*.o mercury/*.c
+
+proof.pdf: proof.tex
+	xelatex -halt-on-error proof.tex 
+	ls ./*.* \
+		| sed -E '/\.(aux|bak|bbl|blg|log|nav|out|xml|snm|toc)$$/!d' \
+		| sed "s/\(.*\)/'\1'/" \
+		| xargs -r rm
 
diff --git a/script.apl b/script.apl
@@ -5,20 +5,20 @@
 
 ⍝ Computes the sum of the digits of a positive integer N
 ∇ SUM←SUMDIGITS N
-  SUM←+/10|⌊N÷10⋆(⍳⌊(10⍟N)+1)-1
+  SUM←+/10|⌊N÷10⋆(⍳⌊1+10⍟N)-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
+∇ RESULT←TEST A
   BS←⍳A
-  SUMSB←SUMDIGITS¨BS
-  SUMSAPLUSB←SUMDIGITS¨(BS+A)
-  RES←∧/0=9|(SUMSAPLUSB-SUMSB+A)
+  SUMSBS←SUMDIGITS¨BS
+  SUMSAPLUSBS←SUMDIGITS¨BS+A
+  RESULT←∧/0=9|SUMSAPLUSBS-SUMSBS+A
 ∇
 
 ⍝ Checks if the conjecture holds for all pairs (A, B) with A, B = 1, ..., MAX
-∇ RES←CONJECTUREHOLDSUPTO MAX
-  RES←∧/TEST¨⍳MAX
+∇ RESULT←CONJECTURE MAX
+  RESULT←∧/TEST¨⍳MAX