logoalt Hacker News

HarHarVeryFunnyyesterday at 10:31 PM2 repliesview on HN

It seems the first two questions are coding ones, and the second two ("flood fill" and circle drawing) are more thinking ones.

The flood fill color detection one would be fastest with a look up table returning a bitmask of colors contained in the byte, with the Color param also as a bitmask, then the result is just lut[Pixel] & Color.

The circle drawing one only needs you to know basic trig to get from radius and angle (0-360) to (x,y) offset from origin. You could embellish the answer with symmetry and LUTs too, but the problem statement doesn't say anything about efficiency.


Replies

ventanayesterday at 11:22 PM

I don't believe you need trig for that, it actually makes it harder if you try to iterate the angle. I believe the expected solution is to start at (R, 0) which is known belongs to the circle, and go left/top, choosing the pixel closest to the circle on each step, which does not require any floating point arithmetic.

show 2 replies
__syesterday at 10:54 PM

The circle one is fishing for sonething clever. 90s without floats means no trig

show 1 reply