Revision 056aa64c-222d-44da-a04c-397860b13c86 - Code Golf Stack Exchange

#Mathematica 104

 f@s_ := ({w, p} = ToExpression@StringSplit@s; 
 Graphics[Polygon@Delete[{{w, 0}, {0, 0}, {w, w}, {0, w}}, p], Axes -> True])

If input in the form of a list were permitted, the following (75 chars) would suffice:

 f[{w_, p_}] := 
 Graphics[Polygon@Delete[{{w, 0}, {0, 0}, {w, w}, {0, w}}, p], Axes -> True]

**Examples**

 f["50 4"]

![triangle][1]

----------

 GraphicsGrid[{{f["3 1"], f["3 2"]}, {f["3 3"], f["3 4"]}}]

![enter image description here][2]


----------

Another Approach 122 chars
--------------------------

 g@s_ := ({w, p} = ToExpression@StringSplit@s; 
 Array[If[Switch[p, 1, # <= (w + 1 - #2), 2, # <= #2, 3, # >= #2, 
 4, # > (w - #2)], "X", ""] &, {w, w}]) // Grid


 GraphicsGrid[{{g["12 1"], g["12 3"]}}]

![another method][3]


 [1]: https://i.sstatic.net/lcJ83.png
 [2]: https://i.sstatic.net/EYp2O.png
 [3]: https://i.sstatic.net/tRgnH.png

AltStyle によって変換されたページ (->オリジナル) /