我忘了毛巾日
如您所知,5月25日被称为“ 毛巾日”,因为毛巾有很多用途。
摘自《银河系旅行者指南》一书的简单摘录(我个人认为这本书是《日常指南》),其中指出:
“毛巾是星际旅行者可以拥有的最有用的东西。部分它具有很大的实用价值。”
如果您需要有关毛巾的更多信息,请检查此SE.scifi答案
挑战
希望您能用一条毛巾作为腿毛做毛巾。
用任何需要两次输入的有效编程语言编写完整的程序或函数
size Integer : #The size
message string : #A sentence
如何用这些值画一条毛巾?
首先使用size
:
根据输入的尺寸画一条毛巾,我们的毛巾采用ASCII技术
width = 12*size
#the line that has the "bar" its always present with different sizes
Width is defined as:
from the first | to the second | has to be equal to size*12 including both ||
<- width->
[===| |====]
| 12 chars || 1 height starts here, just after the "bar"
| SIZE = 1 || 2
| || 3 height = 5*size
| || 4
| || 5 height ends here just before the first line |=======|
|==========|| # the lines with the #
|==========|| # are always fixed
""""""""""""| # it means, every towel
| | # always has this 5 rows
"""""""""""" # no matter the size
其次,给它 message
您必须给它一个信息,什么是一条没有用金线缝好的信息的毛巾?
例子1
input: size=1, message="a simple message can stay with size"
width = 12*size
#the line that has the "bar" it's always present with different sizes
#no words allowed at the bar level
[===| |====]
| a simple || 1 height starts here, just after the "bar"
| message || 2
| can stay || 3 height = 5*size
| with size|| 4
| || 5 height ends here just before the first line |=======|
|==========|| # the lines with the #
|==========|| # are always fixed
""""""""""""| # it means, every towel
| | # always has this 5 rows
"""""""""""" # no matter the size
例子2
input size=2
message="Don't Panic and bring a towel to SE Programming Puzzles and CodeGolf"
The size is 2
That means 24 width and 10 heigth
<- 24 chars width ->
[===| |====]
| Don't Panic and bring|| 1
| a towel to SE || 2
| Programming Puzzles || 3
| and CodeGolf || 4
| || 5
| || 6
| || 7
| || 8
| || 9
| || 10
|======================|| # The lines with the "#"
|======================|| # always present and
""""""""""""""""""""""""| # adapted to
| | # the towel width
"""""""""""""""""""""""" #
接受的答案标准
- 这是代码高尔夫,因此适用常规规则。
规则
您可以确保所有输入字符串都适合大小,因此不能输入
size=1; message="This string is just tooooooooooooooooooooo long to fit the width and height of your towel"
。字符串格式取决于您,例如,如果您想将子字符串居中。
禁止使用断字。
编辑
对于任何混淆,我深表歉意,因为我绘制的ansii毛巾与参数不匹配,为两个示例都添加了PHP脚本,供您检查预期的输出。
也感谢所有投票并考虑了我的第一个挑战的人:D。
给我几分钟时间修复它(刚刚看到了)。发生的事情是我在php上编写了一个程序来画毛巾,但它比我介绍的程序要简单得多,我有一个用于示例的程序,但我忘记对其进行修改。
—
弗朗西斯科·哈恩
@Lynn在两个测试用例中都添加了php ungolfed解决方案,对于任何混淆,我们深表歉意。
—
弗朗西斯科·哈恩
我们可以选择换行的地方吗?
—
Jakob
当行数
—
Francisco Hahn
current line + next word
超过我的毛巾@Jakob所允许的限制时,应添加换行符,这是我发布的PHP脚本所决定的。
我们可以采用适当的文本宽度和/或高度作为参数而不是计算它们吗?
—
JoshM