JPhrases/Arithmetic

From J Wiki
Jump to navigation Jump to search

8D. Arithmetic

d0=: [: >: #: Add 1 to cyclic counter y with upper limit x
d1=: +//. Sum items of y corresponding to keys x
d2=: +//. {~ 'abcde'"_ i. ~.@[ Sum y according to keys x from key set 'abcde'. (substitute your ordered keyset for 'abcde')
d3=: +. Greatest common divisor of x and y
m4=: >:@i.@(>./) |/ ] 1 thru max y residues of y
m5=: 0: = m4 Locate positive integers <: y dividing y
d6=: +"1 Add x to each row of y
d7=: + Add list x to each column of table y
d8=: + Add list y to each column of table x
d9=: *. Least common multiple of x and y