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

added 88 characters in body
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95

J J, 55 bytes

([:(1+_2-~/\])@I.,.@'@'-|'E|'E.]);&(0-.~,)'\|+'#&>@rxall"1|'\|+'#&>@rxall"1|:

Try it online! Attempt This Online!

-12 after seeing rule change allowing lists of lengths as the output.

original answer outputting art, 78 67 bytes

([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:-.~,)'\|+',.&.>@rxall"1|:

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
│---│----│---│---│|│|│|│|│|│|│|│|│
│ │ │ │ │ │ │ │ │|│|│ │ │
└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
│---│--│------│|│|│|│|│|│|│
└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

J, 55 bytes

([:(1+_2-~/\])@I.,.@'-|'E.]);&(0-.~,)'\|+'#&>@rxall"1|:

Try it online!

-12 after seeing rule change allowing lists of lengths as the output.

original answer outputting art, 78 67 bytes

([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:-.~,)'\|+',.&.>@rxall"1|:

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
│---│----│---│---│|│|│|│|│|│|│|│|│
│ │ │ │ │ │ │ │ │|│|│ │ │
└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
│---│--│------│|│|│|│|│|│|│
└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

J, 55 bytes

([:(1+_2-~/\])@I.,.@'-|'E.]);&(0-.~,)'\|+'#&>@rxall"1|:

Attempt This Online!

-12 after seeing rule change allowing lists of lengths as the output.

original answer outputting art, 78 67 bytes

([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:-.~,)'\|+',.&.>@rxall"1|:

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
│---│----│---│---│|│|│|│|│|│|│|│|│
│ │ │ │ │ │ │ │ │|│|│ │ │
└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
│---│--│------│|│|│|│|│|│|│
└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

added 451 characters in body
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95

J, 78 6755 bytes

([:(1+_2-~/\])@I.,.@'-|'E.]);&(0-.~,)'\|+'#&>@rxall"1|:

Try it online!

-12 after seeing rule change allowing lists of lengths as the output.

original answer outputting art, 78 67 bytes

([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:-.~,)'\|+',.&.>@rxall"1|:

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
│---│----│---│---│|│|│|│|│|│|│|│|│
│ │ │ │ │ │ │ │ │|│|│ │ │
└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
│---│--│------│|│|│|│|│|│|│
└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

J, 78 67 bytes

([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:-.~,)'\|+',.&.>@rxall"1|:

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
│---│----│---│---│|│|│|│|│|│|│|│|│
│ │ │ │ │ │ │ │ │|│|│ │ │
└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
│---│--│------│|│|│|│|│|│|│
└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

J, 55 bytes

([:(1+_2-~/\])@I.,.@'-|'E.]);&(0-.~,)'\|+'#&>@rxall"1|:

Try it online!

-12 after seeing rule change allowing lists of lengths as the output.

original answer outputting art, 78 67 bytes

([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:-.~,)'\|+',.&.>@rxall"1|:

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
│---│----│---│---│|│|│|│|│|│|│|│|│
│ │ │ │ │ │ │ │ │|│|│ │ │
└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
│---│--│------│|│|│|│|│|│|│
└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

deleted 123 characters in body
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95

J, 7878 67 bytes

[:(([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:<@-.~,)'\|+',.&.>@rxall"1|:)];._2

Try it online! Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌──────────────────┬─────────────────┐
│┌───┬────┬───┬───┐│┌─┬─┬─┬─┬─┬─┬─┬─┐│┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
││---│----│---│---│││|│|│|│|│|│|│|│|│││|│|│|│|│|│|│|│|│
│└───┴────┴───┴───┘││ │ │ │|│|│  ││
      │|│|│  │└─┴─┴─┴─┴─┴─┴─┴─┘│
└──────────────────┴─────────────────┘
┌───────────────┬─────────────┐└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
│┌───┬──┬──────┐│┌─┬─┬─┬─┬─┬─┐│┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
││---│--│------│││|│|│|│|│|│|││
│└───┴──┴──────┘│└─┴─┴─┴─┴─┴─┘││|│|│|│|│|│|│
└───────────────┴─────────────┘└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

J, 78 bytes

[:(([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:<@-.~,)'\|+',.&.>@rxall"1|:)];._2

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that J requires boxing for heterogeneous lists, hence the boxed output.

echo f 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f 0 :0
---
| |
--------
||| |
)

Outputs:

┌──────────────────┬─────────────────┐
│┌───┬────┬───┬───┐│┌─┬─┬─┬─┬─┬─┬─┬─┐│
││---│----│---│---│││|│|│|│|│|│|│|│|││
│└───┴────┴───┴───┘││ │ │ │|│|│  ││
│└─┴─┴─┴─┴─┴─┴─┴─┘│
└──────────────────┴─────────────────┘
┌───────────────┬─────────────┐
│┌───┬──┬──────┐│┌─┬─┬─┬─┬─┬─┐│
││---│--│------│││|│|│|│|│|│|││
│└───┴──┴──────┘│└─┴─┴─┴─┴─┴─┘│
└───────────────┴─────────────┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

J, 78 67 bytes

([:('-'<@#~"+1+_2-~/\])@I.,.@'-|'E.]),&(a:-.~,)'\|+',.&.>@rxall"1|:

Try it online!

Note: Regex in J is broken on TIO, so the link above is just for the byte count. I will paste below some output run on my computer on J903.

Also, note that we pre-process the input into lines of text, and that J requires boxing for heterogeneous lists, hence the boxed output.

echo f ];._2 ] 0 :0
--- ----
| |--- | |
---| |
| || |
)
echo f ];._2 ] 0 :0
---
| |
--------
||| |
)

Outputs:

┌───┬────┬───┬───┬─┬─┬─┬─┬─┬─┬─┬─┐
---│----│---│---│|│|│|│|│|│|│|│|│
│ │       │|│|│  
└───┴────┴───┴───┴─┴─┴─┴─┴─┴─┴─┴─┘
┌───┬──┬──────┬─┬─┬─┬─┬─┬─┐
---│--│------│|│|│|│|│|│|│
└───┴──┴──────┴─┴─┴─┴─┴─┴─┘

how

  • The "legs" part is just doing a regex search for repeated pipes \|+ in the transpose of the input, and then converting it back to one pipe per line.

  • The "tabletop" part is slightly more interesting, because we have to account for tables that are pushed up next to each other -- ie, sometimes we can only find the demarcations between tabletops by looking at the legs. J has a built-in ability to search for box-shape strings withing a 2D grid, and so we use E. to find instances of:

    -
    |
    

    within the input. We then do some arithmetic on those found indexes to find the length of all tabletops, and convert those lengths back to ascii strings like -----.

added 781 characters in body
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95
Loading
Source Link
Jonah
  • 34.1k
  • 4
  • 41
  • 95
Loading

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