You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

factor

factor(number)
number positive integer, real
COPY/// factor(number)
//  
//  Returns a ds_list containing the prime factors of a given integer.
//
//      number      positive integer, real
//
/// GMLscripts.com/license
{
    var num,dsid,check;
    num = argument0;
    dsid = ds_list_create();
    check = 2;
    while (sqr(check) <= num) {
          if (num mod check == 0) {
              ds_list_add(dsid,check);
              num = num div check;
          }else{
              check += 1;
          }
    }
    if (num != 1) {
        ds_list_add(dsid,num);
    }
    return dsid;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw