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

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Vectorized operators for ASCII art

For many ASCII art challenges, it is useful to generate two different patterns to superpose them later. Vectorized operators can be very helpful to achieve different types of superpositions.

One useful property of operator vectorization is that the operator is only executed once for each element of the shorter string/array, while the elements of the larger one that do not have counterparts remain untouched.

  • .e<

The minimum operator e< work for pairs of strings, characters, arrays and integers; it pops two items from the stack and pushes the lower on e back.

Since a space has a lower code point than all other printable ASCII characters, .e< can be used to "erase" parts of a generated pattern:

 "\/\/\/\/\/" " " .e<
 e# This pushes " \/\/\/".

For a full example, see my answer to Me Want Honeycomb Me Want Honeycomb.

  • .e>

The maximum operator e> works as the minimum operator, with the opposite result.

Again, because of the low code point of the space, .e> can be used to insert a pattern of printable characters in a block of spaces:

 [[" " " " " " " "] [" " " " " " " "]][["+" "" "-" ""]["" "*" "" "/"]] ..e>
 e# This pushes [["+" " " "-" " "] [" " "*" " " "/"]].

For a full example, see my answer to Seven Slash Display Seven Slash Display.

  • .e&

The logical AND operator e& pushes its left argument if it is falsy and its right argument otherwise.

If neither pattern contains falsy elements, this can be used to inconditionally impose one pattern over another one:

 "################" " * * * *" .e&
 e# This pushes " * * * *########".

For a full example, see my answer to Print the American Flag! Print the American Flag!.

  • .e|

The logical OR operator e| can be used as above, with reversed argument order:

 " * * * *" "################" .e|
 e# This pushes " * * * *########".

Vectorized operators for ASCII art

For many ASCII art challenges, it is useful to generate two different patterns to superpose them later. Vectorized operators can be very helpful to achieve different types of superpositions.

One useful property of operator vectorization is that the operator is only executed once for each element of the shorter string/array, while the elements of the larger one that do not have counterparts remain untouched.

  • .e<

The minimum operator e< work for pairs of strings, characters, arrays and integers; it pops two items from the stack and pushes the lower on e back.

Since a space has a lower code point than all other printable ASCII characters, .e< can be used to "erase" parts of a generated pattern:

 "\/\/\/\/\/" " " .e<
 e# This pushes " \/\/\/".

For a full example, see my answer to Me Want Honeycomb.

  • .e>

The maximum operator e> works as the minimum operator, with the opposite result.

Again, because of the low code point of the space, .e> can be used to insert a pattern of printable characters in a block of spaces:

 [[" " " " " " " "] [" " " " " " " "]][["+" "" "-" ""]["" "*" "" "/"]] ..e>
 e# This pushes [["+" " " "-" " "] [" " "*" " " "/"]].

For a full example, see my answer to Seven Slash Display.

  • .e&

The logical AND operator e& pushes its left argument if it is falsy and its right argument otherwise.

If neither pattern contains falsy elements, this can be used to inconditionally impose one pattern over another one:

 "################" " * * * *" .e&
 e# This pushes " * * * *########".

For a full example, see my answer to Print the American Flag!.

  • .e|

The logical OR operator e| can be used as above, with reversed argument order:

 " * * * *" "################" .e|
 e# This pushes " * * * *########".

Vectorized operators for ASCII art

For many ASCII art challenges, it is useful to generate two different patterns to superpose them later. Vectorized operators can be very helpful to achieve different types of superpositions.

One useful property of operator vectorization is that the operator is only executed once for each element of the shorter string/array, while the elements of the larger one that do not have counterparts remain untouched.

  • .e<

The minimum operator e< work for pairs of strings, characters, arrays and integers; it pops two items from the stack and pushes the lower on e back.

Since a space has a lower code point than all other printable ASCII characters, .e< can be used to "erase" parts of a generated pattern:

 "\/\/\/\/\/" " " .e<
 e# This pushes " \/\/\/".

For a full example, see my answer to Me Want Honeycomb.

  • .e>

The maximum operator e> works as the minimum operator, with the opposite result.

Again, because of the low code point of the space, .e> can be used to insert a pattern of printable characters in a block of spaces:

 [[" " " " " " " "] [" " " " " " " "]][["+" "" "-" ""]["" "*" "" "/"]] ..e>
 e# This pushes [["+" " " "-" " "] [" " "*" " " "/"]].

For a full example, see my answer to Seven Slash Display.

  • .e&

The logical AND operator e& pushes its left argument if it is falsy and its right argument otherwise.

If neither pattern contains falsy elements, this can be used to inconditionally impose one pattern over another one:

 "################" " * * * *" .e&
 e# This pushes " * * * *########".

For a full example, see my answer to Print the American Flag!.

  • .e|

The logical OR operator e| can be used as above, with reversed argument order:

 " * * * *" "################" .e|
 e# This pushes " * * * *########".
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Vectorized operators for ASCII art

For many ASCII art challenges, it is useful to generate two different patterns to superpose them later. Vectorized operators can be very helpful to achieve different types of superpositions.

One useful property of operator vectorization is that the operator is only executed once for each element of the shorter string/array, while the elements of the larger one that do not have counterparts remain untouched.

  • .e<

The minimum operator e< work for pairs of strings, characters, arrays and integers; it pops two items from the stack and pushes the lower on e back.

Since a space has a lower code point than all other printable ASCII characters, .e< can be used to "erase" parts of a generated pattern:

 "\/\/\/\/\/" " " .e<
 e# This pushes " \/\/\/".

For a full example, see my answer to Me Want Honeycomb.

  • .e>

The maximum operator e> works as the minimum operator, with the opposite result.

Again, because of the low code point of the space, .e> can be used to insert a pattern of printable characters in a block of spaces:

 [[" " " " " " " "] [" " " " " " " "]][["+" "" "-" ""]["" "*" "" "/"]] ..e>
 e# This pushes [["+" " " "-" " "] [" " "*" " " "/"]].

For a full example, see my answer to Seven Slash Display.

  • .e&

The logical AND operator e& pushes its left argument if it is falsy and its right argument otherwise.

If neither pattern contains falsy elements, this can be used to inconditionally impose one pattern over another one:

 "################" " * * * *" .e&
 e# This pushes " * * * *########".

For a full example, see my answer to Print the American Flag!.

  • .e|

The logical OR operator e| can be used as above, with reversed argument order:

 " * * * *" "################" .e|
 e# This pushes " * * * *########".

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