a-conjecture-of-mine

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

script.apl (768B)

 1 ⍝ This script is a simple test for the following conjecture:
 2 
 3 ⍝ Let S: N -> N be the sum of the digits of a positive integer.
 4 ⍝ For all A and B in N, S(A + B) = S(A) + S(B) - 9k, where k is an interger.
 5 
 6 ⍝ Computes the sum of the digits of a positive integer N
 7 ∇ SUM←SUMDIGITS N
 8   SUM←+/10|⌊N÷10⋆(⍳⌊1+10⍟N)-1
 910 
11 ⍝ Given a positive integer A, returns 1 if the conjecture holds for all pairs
12 ⍝ (A, B) with B = 1, ..., A and 0 otherwise
13 ∇ RESULT←TEST A ; BS ; SUMSBS ; SUMSAPLUSBS
14   BS←⍳A
15   SUMSBS←SUMDIGITS¨BS
16   SUMSAPLUSBS←SUMDIGITS¨BS+A
17   RESULT←∧/0=9|SUMSAPLUSBS-SUMSBS+A
1819 
20 ⍝ Checks if the conjecture holds for all pairs (A, B) with A, B = 1, ..., MAX
21 ∇ RESULT←CONJECTURE MAX
22   RESULT←∧/TEST¨⍳MAX
2324