2
$\begingroup$

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)

$\endgroup$

3 Answers 3

1
$\begingroup$
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;
$\endgroup$
1
$\begingroup$
P:= n -> select(p->(p[1]<=p[2]),[seq([d,n/d], d=numtheory:-divisors(n))]);
$\endgroup$
0
$\begingroup$

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]
$\endgroup$
4
  • 1
    $\begingroup$ Our specialist of Maple and GAP among other software is comeback. You're welcome:-) $\endgroup$
    – user63181
    Jul 22, 2014 at 13:16
  • 1
    $\begingroup$ Nice to see you my brother. Have good times during this hot Ramadan :-) $\endgroup$
    – Mikasa
    Jul 22, 2014 at 13:18
  • $\begingroup$ 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. $\endgroup$
    – Carl Love
    Jul 22, 2014 at 13:20
  • $\begingroup$ @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. :-) $\endgroup$
    – Mikasa
    Jul 22, 2014 at 14:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .