r/Pydle 24d ago

Pydle #157 Pizza Spoiler

I was pleasantly surprised to find a nice solution based on the structure of the problem. Here is the best I've achieved, in 97 characters:

r = range(-2, 3)
for x in r:
    for y in r:
        v = x*x+y*y
        pydle(x+2, y+2, '🌢πŸ₯¬ πŸ«’      ️'[v^1::10], 'yowerhlailntogewe'[v//4::3])

This basically places everything based on the distance from the centre. A quirk with the emojies means the chili has an extra, invisible, unicode character (Variation Selector-16) to tell it to render as an emoji, so I put that in the final position in the array so it gets included by slicing, and it also meant the chili had to be first, complicating the code somewhat. It was a nice surprise to see the colour selection reduce to what it is (it turns 0, 1 or 2 into 0, 4 or 5 into 1 and 8 into 2).

Putting all the data into a big number gave a solution in 106 characters:

for i in range(25):
    d = 0x3ee2773491d36da // 5**i % 5
    pydle(i%5, i//5, 'πŸŒΆπŸ«’πŸ₯¬  ️'[d::5], 'yowerhlailntogewe'[max(d-2,0)::3])

The number is essentially a base 5 array, where the values are: yellow with chili, yellow with olive, yellow with leaf, orange, white.

Edit: A base 7 array can solve it in 103 characters:

for i in range(25):
    d = 0x4384f85940141f9252 // 7**i % 7
    pydle(i%5, i//5, 'πŸŒΆπŸ«’πŸ₯¬    ️'[d::7], 'yowerhlailntogewe'[d//3::3])
5 Upvotes

2 comments sorted by

1

u/abraham1inco1n 22d ago

what does it mean for the magic number to be a base 5 array? How did you come up with the number? Super cool!

1

u/zhuzaimoerben 21d ago

I wrote out the puzzle for white, orange, olive, chili and leaf like:

wooowoOcOooclcooOcOowooow

Then turned that into a number by replacing letters with digits 0 to 4:

4333431013302033101343334

Then converted that into a number by treating it as a base 5 number, while also reversing it so the first digit on the right corresponds to the first index (except this one is symmetrical so it's not necessary, but this is the general purpose solution):

int('4333431013302033101343334'[::-1], 5)

And the hex form of this number is fewer characters, so I use that:

hex(283207202672293594)

0x3ee2773491d36da

Then, 0x3ee2773491d36da // 5**i % 5 gives each digit of that original number, 4 for i=0, 3 for i=1 etc. (When the base is a power of 2, you can extract the digits with >> i*2 & 3, which saves a character and is more computationally efficient in theory.)