wrote magic matrix code