MUMPS (58 56 88 86 88 bytes)
Assuming you can execute this code in an interpreter:
(ANSI M)
r v,! f i=1:1:v d w !
. f j=1:1:v w $s(i#2:$s(j#2=1:"X",1:" "),1:$s(j#2:" ",1:"X"))
We could bring this down to 82 bytes if we allow a new line at the beginning of the output:
r v,! f i=1:1:v w ! f j=1:1:v w $s(i#2:$s(j#2=1:"X",1:" "),1:$s(j#2=1:" ",1:"X"))
Bonus
We can take advantage of the fact that M doesn't have any reserved keywords to give further headache:
s s=8 f f=1:1:s w ! f w=1:1:s w $s(f#2:$s(w#2=1:"X",1:" "),1:$s(w#2=1:" ",1:"X"))
Caché ObjectScript (a superset of ANSI M) (83 bytes):
r v,! f i=1:1:v{f j=1:1:v{w $s(i#2:$s(j#2=1:"X",1:" "),1:$s(j#2=1:" ",1:"X"))} w !}
Explanation:
both cases are essentially the same. Accept input "v" from user. While looping from 1 to v, execute an inner loop such that if i#2 isn't zero, write "X" if j#2 isn't zero and " " in all other cases (i.e. when j#2 is zero). if i#2 is zero, do the opposite. After completing the inner loop, start a new line.
dang, realized I forgot to alternate lines
*added another version of ANSI M and an ObjectScript version
1I was looking for a tag like 'light-weight' for this. – steenslag – 2011-03-07T22:52:27.710
1Whole and complete program, I suppose? – J B – 2011-03-07T22:52:51.260
@J B: Yes. How do I formulate that? Add 'to stdout' to the required output? – steenslag – 2011-03-07T22:59:13.367
1Just say you want a complete program. You might also want to specify command-line arguments, to prevent confusion with function arguments. – J B – 2011-03-07T23:05:52.490
When you say top-right, do you mean top-left? If not, please correct the example output for input 8. – Peter Taylor – 2011-03-08T00:02:44.480
@Peter Taylor: This is.. it is... well , it is corrected. – steenslag – 2011-03-08T00:18:37.200
I assume an input of zero should produce no output? – Shaun Bebbers – 2019-04-11T15:58:16.847