Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Mathematica 122 (104?)

Mathematica 122 (104?)

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


Under a liberal interpretation of "output", the following (104 chars) will work.

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

triangle


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]

#Mathematica 122 (104?)

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


Under a liberal interpretation of "output", the following (104 chars) will work.

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

triangle


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]

Mathematica 122 (104?)

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


Under a liberal interpretation of "output", the following (104 chars) will work.

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

triangle


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]

re ordering
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106

#Mathematica 122 (104?)

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

f["50 4"]

triangle


Under a liberal interpretation of "output", the following (104 chars) will work.

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

triangle


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]

#Mathematica 122 (104?)

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

f["50 4"]

triangle


Under a liberal interpretation of "output", the following (104 chars) will work.

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]

#Mathematica 122 (104?)

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


Under a liberal interpretation of "output", the following (104 chars) will work.

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

triangle


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]

re ordering
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106

#Mathematica 104122 (104?)

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

GraphicsGrid[{{g["12 1"], Axesg["12 ->3"]}}]

another method

f["50 True])4"]

If input in the form oftriangle


Under a list were permittedliberal interpretation of "output", the following (75104 chars) would suffice:will work.

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

Examples

f["50 4"]

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


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

enter image description here


Another Approach 122 chars

g@s_ := ({w, p} = ToExpression@StringSplit@s; 
 Array[If[Switch[p, 1, # <= (Graphics[Polygon@Delete[{{w + 1 - #2), 2, # <= #2, 30}, # >= #2{0, 40}, # > ({w - #2)], "X", ""] &w}, {w0, w}]) // Grid
GraphicsGrid[{{g["12}, 1"]p], g["12Axes 3"]}}]-> True]

another method


#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


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

enter image description here


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

#Mathematica 122 (104?)

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

f["50 4"]

triangle


Under a liberal interpretation of "output", the following (104 chars) will work.

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]

another approach added
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106
Loading
additional triangles added
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106
Loading
Source Link
DavidC
  • 25.5k
  • 2
  • 53
  • 106
Loading

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