Introduction:
Every workday I read the newspaper in the morning while eating breakfast, and also do some of the puzzles at the back. When I do the word-search puzzles, I (almost) always go over the words in order, and strike them through one by one. The word-searches in the newspaper have two columns of words, and after I finished a column I will also put a vertical strike through it.
Challenge:
Let's do the same as a challenge. Given a list of lists of words and an integer \$n\$ for the amount of words I've already struck through, output the ASCII art representing that.
The words of each inner list will be placed in the same column, where the columns will have two spaces as delimiter (based on the longest word). All the letters in the words that are struck through are replaced with -
, and if an entire column is struck through it's replaced with a vertical |
.
Challenge rules:
|
rules:
- For the position of the
|
, we take the middle of the longest word in the column
- If the longest word has an even length, we take the left character of the two middle characters (e.g.
----
→ -|--
)
- If a word in the column is shorter than the (left-focused) middle of the longest word, pad spaces between this shortest word and the vertical
|
line
- You can assume the list of words will only contain regular ASCII letters (in a casing of your choosing - e.g. all lowercase; all uppercase; or mixed casing)
- You can assume the list of words will all be of equal length, except for the last column which might potentially be shorter
- You can assume there is always at least one word in the list
- You can assume \$0 \leq n \leq W\$ (where \$W\$ is the total amount of words)
- Probably not really relevant, but you can assume the words are in alphabetical order
- Trailing spaces/newlines in the output are optional
- The input-list can be taken in any reasonable format. Could be a list/stream/array; could be taken from STDIN; could be a space-delimited string list; a matrix of characters; etc.
- You're allowed to take the words-input as a list of rows instead of columns. So input
[["A","ABC","DEFGHIJ","FG","KLMN"],["QRSTUVW","QRSTUVWXYZ","ST","Y","YZ"],["Z","ZZZZZ"]]
would be [["A","QRSTUVW","Z"],["ABC","QRSTUVWXYZ","ZZZZZ"],["DEFGHIJ","ST"],["FG","Y"],["KLMN","YZ"]]
instead
Examples:
Input 1:
Words: [["A","ABC","DEFGHIJ","FG","KLMN"],["QRSTUVW","QRSTUVWXYZ","ST","Y","YZ"],["Z","ZZZZZ"]]
n: 0
Output 1:
A QRSTUVW Z
ABC QRSTUVWXYZ ZZZZZ
DEFGHIJ ST
FG Y
KLMN YZ
Input 2:
Words: Same as the previous example
n: 11
Output 2:
- | ----|-- -
---| ----|----- ZZZZZ
---|--- -- |
-- | - |
---| -- |
General rules:
- This is code-golf, so the shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer with default I/O rules, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code (e.g. TIO).
- Also, adding an explanation for your answer is highly recommended.
Test cases:
Input 1:
Words: [["A","ABC","DEFGHIJ","FG","KLMN"],["QRSTUVW","QRSTUVWXYZ","ST","Y","YZ"],["Z","ZZZZZ"]]
n: 0
Output 1:
A QRSTUVW Z
ABC QRSTUVWXYZ ZZZZZ
DEFGHIJ ST
FG Y
KLMN YZ
Input 2:
Words: [["A","ABC","DEFGHIJ","FG","KLMN"],["QRSTUVW","QRSTUVWXYZ","ST","Y","YZ"],["Z","ZZZZZ"]]
n: 11
Output 2:
- | ----|-- -
---| ----|----- ZZZZZ
---|--- -- |
-- | - |
---| -- |
Input 3:
Words: [["A","ABC","DEFGHIJ","FG","KLMN"],["QRSTUVW","QRSTUVWXYZ","ST","Y","YZ"],["Z","ZZZZZ"]]
n: 12
Output 3:
- | ----|-- - |
---| ----|----- --|--
---|--- -- |
-- | - |
---| -- |
Input 3:
Words: [["BACKWARD","DIAGONAL","FIND","HORIZONTAL"],["RANDOM","SEEK","SLEUTH","VERTICAL"],["WIKIPEDIA","WORDSEARCH"]]
n: 0
Output 3:
BACKWARD RANDOM WIKIPEDIA
DIAGONAL SEEK WORDSEARCH
FIND SLEUTH
HORIZONTAL VERTICAL
Input 4:
Words: [["BACKWARD","DIAGONAL","FIND","HORIZONTAL"],["RANDOM","SEEK","SLEUTH","VERTICAL"],["WIKIPEDIA","WORDSEARCH"]]
n: 6
Output 4:
----|--- ------ WIKIPEDIA
----|--- ---- WORDSEARCH
----| SLEUTH
----|----- VERTICAL
Input 5:
Words: [["TEST"]]
n: 1
Output 5:
-|--