1,⁴Ṭị⁾+-W,`
ṣ⁶µḊṖs⁴_6¤j⁾--;@Ḣ;Ṫḟ0s⁴_©4¤µ€ẎŒṖK€€µL€>®ẸµÐḟṪ;€⁶x®¤ḣ€®s⁵_2¤Zz⁶x®¤j@€€⁾| ,U¤j@€¢ẎY
3つの引数を取り、完全なプログラムは、( 、text
、width
)height
のページを印刷しています。
オンラインでお試しください! NB 60秒の制限内でOPから例を実行するには非効率です。
(97バイトページ間の空白行が実際に必要な場合は)
どうやって?
1,⁴Ṭị⁾+-W,` - Link 1, make header & footer: no arguments
⁴ - program's 2nd argument, width
1 - literal one
, - pair = [1,width]
Ṭ - untruth = [1,0,0,...,0,0,1] (a 1 at index 1 and index width; 0 elsewhere)
⁾+- - literal list of characters = "+-"
ị - index into (1-based & modular) = "+--...--+"
W - wrap = ["+---...--+']
` - use as both arguments of the dyad:
, - pair = [["+---...--+'],["+---...--+']]
ṣ⁶µḊṖs⁴_6¤j⁾--;@Ḣ;Ṫḟ0s⁴_©4¤µ€ẎŒṖK€€µL€>®ẸµÐḟṪ;€⁶x®¤ḣ€®s⁵_2¤Zz⁶x®¤j@€€⁾| ,U¤j@€¢ẎY
- Main link. This is long so splitting it up into parts like so:
ṣ⁶µ "A" µ€ "B" µ "C" µÐḟ "D"
ṣ⁶ - split 1st argument (text) at spaces
µ "A" µ€ - for €ach resulting word do "A" (get hyphenated parts)
"B" - do "B" (all ways to partition those joining with spaces)
µÐḟ - filter discard if:
µ "C" - do "C" (any parts are too long)
"D" - do "D" (format the resulting list into the page-format)
"A" = ḊṖs⁴_6¤j⁾--;@Ḣ;Ṫḟ0s⁴_©4¤ - Hyphenate: list, word e.g. "Something"
Ḋ - dequeue "omething"
Ṗ - pop "omethin"
¤ - nilad followed by link(s) as a nilad
⁴ - program's 2nd argument e.g. 9 (width)
6 - literal six 6
_ - subtract 3
s - split into chunks ["ome","thi","n"]
⁾-- - literal list of characters "--"
j - join "ome--thi--n"
Ḣ - head (word) "S"
;@ - concatenate (sw@p arguments) "Some--thi--n"
Ṫ - tail (word) "g"
; - concatenate "Some--thi--ng"
ḟ0 - filter out zeros (tail yields 0 for words of length 1)
¤ - nilad followed by link(s) as a nilad:
⁴ - program's 2nd argument 9
4 - literal four 4
_ - subtract 5
© - copy to register & yield 5
s - split into chunks ["Some-","-thi-","-ng"]
"B" = ẎŒṖK€€ - Line arrangements: list of lists of hyphen-parts / single words
Ẏ - flatten by one (make a list of words and hyphen-parts
- e.g. [["Not"],["hyph-","-ena-","-ted"]] -> ["Not","hyph-","-ena-","-ted"]
ŒṖ - partition e.g. [1,2,3]->[[[1],[2],[3]],[[1],[2,3]],[[1,2],[3]],[[1,2,3]]]
K€€ - join with spaces for €ach for €ach e.g. ["one","two"]->"one two"
"C" = L€>®Ẹ - Any part too long?: one of the list of lines from "B"
L€ - length of €ach
® - recall from the register (width minus 4)
> - greater than (vectorises) - 1 if so 0 if not
Ẹ - any truthy? (1 if any too long)
"D" = Ṫ;€⁶x®¤ḣ€®s⁵_2¤Zz⁶x®¤j@€€⁾| ,U¤j@€¢ẎY - Format as pages: list of valid arrangements
Ṫ - tail (last valid partition is greediest)
¤ - nilad followed by links as a nilad:
⁶ - literal space character
® - recall from register (width minus 4)
x - repeat elements
;€ - concatenate to €ach
® - recall from register (width minus 4)
ḣ€ - head €ach to index
¤ - nilad followed by links as a nilad:
⁵ - program's 3rd argument, height
2 - literal two
_ - subtract
Z - transpose
¤ - nilad followed by link(s) as a nilad:
⁶ - literal space character
® - recall from register (width minus 4)
x - repeat elements
z - transpose with filler (repeated spaces)
¤ - nilad followed by link(s) as a nilad:
⁾|<space> - literal list of characters = "| "
U - upend = " |"
, - pair = ["| "," |"]
j@€€ - join for €ach for €ach (sw@p arguments)
¢ - call last link (1) as a nilad
j@€ - join for €ach (sw@p arguments)
Ẏ - flatten by one
Y - join with line feeds
- implicit print