# C, <s>291</s> 280 bytes # r,x,y,A,C,B,D,a,c,b,d,w,s,t;T(i){return abs(i)<2*w-1;}U(j,k){s+=T(j-k)*T(j)*T(k);t*=T(j-k)*j*k<=0;}main(){for(scanf("%i%i%i%i%i",&a,&b,&c,&d,&w);A=a-x,C=c-x,B=b-y,D=d-y,s=0,t=1,U(A,C),U(B,D),U(A-B,C-D),U(A+B,C+D),putchar((x=++r%21)?".?#x"[!!s+t+(!A*!B+!C*!D)]:10),r<420; y=r/21);} Can be compiled/run using: *gcc laser.c -o laser && echo "10 10 11 10 3" | ./laser* Below, the same code with whitespace and explanatory comments: // Integers... r,x,y,A,C,B,D,a,c,b,d,w,s,t; // Is true if i is in range (of something) T(i){return abs(i)<2*w-1;} // Tests if lasers (horizontal, vertical, diagonal, etc) can/must exist at this point // T(j-k) == 0 iff the laser of this direction can exist // s += 1 iff this laser direction can pass through this point // t *= 1 iff this laser direction must pass through this point U(j,k){ s+=T(j-k)*T(j)*T(k); t*=T(j-k)*j*k<=0; } main(){for( // Read input; p0=(a,b), p1=(c,d) scanf("%i%i%i%i%i",&a,&b,&c,&d,&w); // A, B, C and D represent delta-x and delta-y for each points // e.g.: if we're processing (2,3), and p0=(4,5), A=4-2, B=5-3 A=a-x,C=c-x, B=b-y,D=d-y, // s != 0 iff (x,y) can have some laser through it // t == 1 iff all lasers pass through (x,y) // (!A*!B+!C*!D) == 1 iff (x,y) is either p0 or p1 s=0,t=1,U(A,C),U(B,D),U(A-B,C-D),U(A+B,C+D), putchar((x=++r%21)?".?#x"[!!s+t+(!A*!B+!C*!D)]:10), // End of for r<420; y=r/21); }