# coding: utf-8 # Sieve of Eratosthenes def sieve(a,b): if(abs(a) star2 vector vec = ( starPos[1][0] - starPos[0][0], starPos[1][1] - starPos[0][1] ) div = sieve(vec[0],vec[1]) vec = ( vec[0] / div, vec[1] / div) # enumerate lattice point on the star1--star2 line lattice = [] p = starPos[0] while(0 <= p[0] and W > p[0] and 0 <= p[1] and H > p[1] ): lattice.append(p) p = (p[0]+vec[0], p[1]+vec[1]) p = starPos[0] while(0 <= p[0] and W > p[0] and 0 <= p[1] and H > p[1] ): lattice.append(p) p = (p[0]-vec[0], p[1]-vec[1]) # get 3rd star position for thirdPos in [(x,y) for y in range(H) for x in range(W)]: if not thirdPos in lattice: starPos.append(thirdPos) break # print result sky = [["-" for w in range(W)] for h in range(H)] for i in range(3): sky[starPos[i][1]][starPos[i][0]] = "*" print("\n".join(["".join(s) for s in sky]), "\n")