10
1
In this challenge, you must take two numbers (separated by a space) as input and output an ASCII right triangle, made up of x
s.
The first number will be the width and height of the triangle you should output. The second number will be which corner the right angle will be in. The corners are numbered 1 to 4, starting in the top left and going in English reading order:
1 2
3 4
For example (inputs and their respective triangle outputs):
INPUT | 3 1 | 3 2 | 3 3 | 3 4
------+-----+-----+-----+----
OUT- | xxx | xxx | x | x
PUT | xx | xx | xx | xx
| x | x | xxx | xxx
Your program's output must match these examples exactly for their respective inputs.
The input will always be valid: the first number will be an integer ≥1, and the second number will be 1, 2, 3, or 4.
This is code-golf; shortest code (in character count) wins.
1The more APL I read, the more I realize APL is a parsing nightmare. Wouldn't it have to actually evaluate the
(⍎⍵⌷'functions')
part before it decides how to interpret the whole statement? Consider for example1+(⍵⌷'12+')|40
. It wouldn't even know if|
is monadic or dyadic before⍎
ing that parenthesized portion.The whole abstract syntax tree changes depending on the evaluation. – protist – 2013-11-20T12:13:36.127
I meant
1+(⍎⍵⌷'12+')|40
...will not let me edit. – protist – 2013-11-20T12:58:52.7232
@protist: Fun fact:
– marinus – 2013-11-20T18:11:47.803f ← { [ }
does not give an error!f 1÷0
gives... a domain error! (because of the division by zero). Only when you call the function likef 123
you get syntax error. Behold: http://imgur.com/jtmdi4BBy all the gods!!!! That breaks my heart a little. I have been playing with writing APL interpreters some, and that demonstrates a great evil in the current implementations. hahaha – protist – 2013-11-20T18:59:10.167
It almost seems like functions are put in place routinely by some sort of ugly macro-expansion-like process. It would somewhat indicate in-place text expansion. – protist – 2013-11-20T19:00:44.863
@protist: Yeah, I was rather surprised too when I discovered that the
⍎⍵⌷
thing works. When I wrote this, I thought J-style gerunds would come in very handy and on a whim I tried this. Luckily I don't actually use APL for any "real" programming. The way it works, it's actually impossible to parse a function without knowing what its formal parameters are - so that means it actually has to reparse the function every time you call it! – marinus – 2013-11-20T19:43:26.490@protist: This of course is mitigated by the fact that this only holds for functions that contain
⍎
, and those would have to do parsing on each call anyway. Though considering{ [ }
is not a syntax error I don't think it actually does that optimization. – marinus – 2013-11-20T19:50:21.887