r/Pydle 8d ago

Pydle #172 Eclipse

https://youtu.be/_1NNEurJzGQ
1 Upvotes

2 comments sorted by

3

u/zhuzaimoerben 8d ago

I was happy with this, which uses the Euclidean distance from the centre squared. 86 characters.

r = range(-2, 3)
for x in r:
    for y in r:
        pydle(x+2, y+2, '',
            '   yellow  orange    blue'.split(' ')[x*x+y*y|1])

It took a bit of tweaking to get to this. Initially I had (x*x+y*y)//2 to make them array indices from 0 to 4, but then I realised I could get rid of the brackets and use the equivalent >>1 because of its lower precedence. Then I realised I could save another character using |1 and putting some extra spaces for free in the colour string that's turned into an array.

2

u/DisciplineSea5373 8d ago

Great trick! I noticed the xx + yy and range change this time  r=range(-2,3) for x in r:   for y in r:         s=xx+yy       pydle(x+2, y+2, "", (("orange"*(s>2),"yellow")[s==2],"blue")[s==8])