Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Prime Number implementation

Name: Anonymous 2011-03-20 8:29


def factors(x):
    '''returns the factors for an integer'''
    facts=[]
    for i in range(x+1):
        if i==0:
            continue
        elif x%i==0:
            facts.append(i)
    return facts

def isprime(x):
    y=factors(x)
    if len(y)==2:
        return True
    else:
        return False

Name: Anonymous 2011-03-20 17:40

❨define ❨factors x❩
  ❨do ❨❨i 1 ❨+ i 1❩❩
       ❨r '❨❩ ❨if ❨zero? ❨remainder x i❩❩
                  ❨cons x r❩ r❩❩❩
    ❨❨> i x❩ ❨reverse r❩❩❩❩

❨define ❨prime? x❩
  ❨or ❨= x 1❩
      ❨= ❨length ❨factors x❩❩ 2❩❩❩


CAN YOU SEE THE PARENS? CAN YOU SEE THEM‽

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List