LDR/Bulb problem

Sorry, I dont find your code very comprehensible; (language issue)
and it seems very complicated for such a simple task.

It would be useful to document it at a higher level (eg pseudocode)
eg measure light level & average it to match a range 0 - 1023
apply some hysteresis so the light doesnt flicker
turn light on or off depending on result.