2

I am currently working on writing a procedure in Maple. What I need to be able to do is factor a number. The few commands I know to help with this are;

ifactor(12); (2)^2(3)

divisors(12); {1, 2, 3, 4, 6, 12}

But what I am wanting is to factor a larger number and have Maple give it to me in pairs. For example

12 - (1,12),(2,6),(3,4)

Annie
  • 31
  • 1

3 Answers3

1
Pairs:= proc(N::posint)
local 
     L:= [numtheory:-divisors(N)[]],
     n:= nops(L),
     k
;
     [seq([L[k],L[n-k+1]], k= 1..iquo(n,2)+irem(n,2))]
end proc;
Carl Love
  • 1,193
1
P:= n -> select(p->(p[1]<=p[2]),[seq([d,n/d], d=numtheory:-divisors(n))]);
Robert Israel
  • 448,999
0

My attempt is very basic in shape than the other good way.

[> with(numtheory);
   a := divisors(12): nops(a):
   for i to nops(a) do
   for j to nops(a) do
      if `and`(a[i]*a[j] = 12, i <= j) then print([a[i], a[j]])
      end if;
   end do;
   end do;


                                 [1, 12]
                                 [2, 6]
                                 [3, 4]
Mikasa
  • 67,374
  • 1
    Our specialist of Maple and GAP among other software is comeback. You're welcome:-) –  Jul 22 '14 at 13:16
  • 1
    Nice to see you my brother. Have good times during this hot Ramadan :-) – Mikasa Jul 22 '14 at 13:18
  • That code is incredibly bad. It does a full quadratic scan of a when half of a linear scan is all that is needed. The code also fails for perfect squares. – Carl Love Jul 22 '14 at 13:20
  • @CarlLove: Rather than starting a sentence with a not good verb incredibly bad, I want to thank you. :-) Please have a look at the edit. However, the OP asked about a practical proc and yours is satisfying it. :-) – Mikasa Jul 22 '14 at 14:30