Find smallest perimeter with given area


pics = 18 factors = [] ps = [] pfs = [] flen = len(factors)-1 for i in range(1, pics+1): if pics % i == 0: factors.append(i) for i in range (0, int(len(factors)/2)): f1 = factors[i] f2 = factors[flen-i] #print (str(f1) + "*" + str(f2)) t = f1 + f2 + f1 + f2 ps.append (t) pfs.append(str(f1) + "," + str(f2)) lpl = ps.index(min(ps)) pc = pfs[lpl] pcvs = pc.split(",") pcv1 = int(pcvs[0]) pcv2 = int(pcvs[1]) #print (pc) print ("Way 1:") for x in range (0, pcv1): for y in range (0, pcv2): print ("x", end ="") print("") print("Way 2:") for x in range (0, pcv2): for y in range (0, pcv1): print ("x", end ="") print("") print ("Perimeter = " + str(ps[lpl]))

Loading Please Wait...