一个最出色的证明,对于fi来说太小了!


12

您坐在家里,以最邪恶的方式揉手。这次,我将能够设置社区A-SPIN!我只是声称我已经在这里的本书中证明了这个问题(毫无疑问是可以改进的)……您打开第一个相关页面。你擦那些字...

您当然是邪恶的费马!哈哈,开玩笑。您知道这种情况并非如此。这只是他邪恶的孪生兄弟格式的叙述。这里的格式太懒了,无法将他的“证明”浓缩到边缘。因此,他呼吁你为他做。

目标在给定证明(字符串)和页面(文本块)的情况下,将证明“写”到空白处。

有效的页面规则

当且仅当满足以下要求时,文本块才包含页面:

  • 顶部和底部边框的形式为-{10,}\+$(正则表达式-至少十次,直到a +,然后是行的结尾)。
  • 每条非顶部和底部的行都必须以结尾|。至少会有这样一条线。
  • |每行的最后一行至少要有五个空格。
  • 所有线条的宽度相同。

因此,以下是有效页面(.s用于显示最大边距边界在哪里):

-----------------+
Lorem Ipsum.     |
and other  .     |
latin crud .     |
           .     |
        EOF.     |
-----------------+

这是另一页边距更大的页面:

------------------------+
Hello world!   .        |
How are you, to.        |
day? --Mme. B  .        |
               .        |
------------------------+

您将在给定的字符串的空白处写入内容,并尽可能地保留单词。例如,如果hello适合下一行,请不要在当前行上断开它。

输入/输出

填充文字

Proof: This is a most excellent proof, too small for anyone!
Text:                       ; not a leading newline
------------------------+
Hello world!            |
How are you, to         |
day? --Mme. B           |
                        |
------------------------+
Output: 
------------------------+
Hello world!    This a  |
How are you, to most    |
day? --Mme. B   excellen|
                t proof,|
------------------------+    

Proof: Execute the member as an example to the others!
Text:
------------------------------------------------+
Contrary to popular belief, Lorem               |
Ipsum is not simply random text.                |
It has roots in a piece of classical            |
Latin literature from 45 BC, making             |
it over 2000 years old. Richard                 |
McClintock, a Latin professor at                |
Hampden-Sydney College in Virginia,             |
looked up one of the more obscure               |
Latin words, consectetur, from a                |
Lorem Ipsum passage, and going through          |
the cites of the word in classical              |
literature, discovered the undoubtable          |
source. Lorem Ipsum comes from...               |
------------------------------------------------+
Output:
------------------------------------------------+
Contrary to popular belief, Lorem      Execute  |
Ipsum is not simply random text.       the      |
It has roots in a piece of classical   member as|
Latin literature from 45 BC, making    an       |
it over 2000 years old. Richard        example  |
McClintock, a Latin professor at       to the   |
Hampden-Sydney College in Virginia,    others!  |
looked up one of the more obscure               |
Latin words, consectetur, from a                |
Lorem Ipsum passage, and going through          |
the cites of the word in classical              |
literature, discovered the undoubtable          |
source. Lorem Ipsum comes from...               |
------------------------------------------------+

Proof: Consider supercalifragilisticexpialidocious. Therefore, x.
Output:
-----------------------------------------+
sections 1.10.32 and                     |
1.10.33 of "de Finibus                   |
Bonorum et Malorum"                      |
(The Extremes of Good                    |
and Evil) by Cicero,                     |
written in 45 BC. This                   |
book is a treatise on                    |
the theory of ethics,                    |
very popular during the                  |
Renaissance. The first                   |
line of Lorem Ipsum,                     |
"Lorem ipsum dolor sit                   |
amet..", comes from a                    |
line in section 1.10.32.                 |
-----------------------------------------+
Output: Consider supercalifragilisticexpialidocious. Therefore, x.
-----------------------------------------+
sections 1.10.32 and     Consider        |
1.10.33 of "de Finibus   supercalifragili|
Bonorum et Malorum"      sticexpialidocio|
(The Extremes of Good    us. Therefore, x|
and Evil) by Cicero,     .               |
written in 45 BC. This                   |
book is a treatise on                    |
the theory of ethics,                    |
very popular during the                  |
Renaissance. The first                   |
line of Lorem Ipsum,                     |
"Lorem ipsum dolor sit                   |
amet..", comes from a                    |
line in section 1.10.32.                 |
-----------------------------------------+

Proof: Alex is a bird. All birds can fly. All things that fly are wrong. Ergo, Alex is wrong.
Text:
----------+
Sorry     |    ; 5 spaces. 
----------+
Output:
----------+
Sorry Alex|
----------+

这是一个,因此以字节为单位的最短程序胜出!


排行榜


Codegolf的新手不多,我可以从文件中提取页面并进行证明吗?还是它们必须来自用户I / O?
wnnmaw 2015年

@wnnmaw欢迎编码高尔夫!如果更好,您可以选择从文件中读取。
Conor O'Brien


@Mego不完全是。另外,这还要求您识别“保证金”;该文本一定是合理的,而不仅仅是分裂的。
Conor O'Brien

好吧,感谢您教我有关lorem ipsum的知识。:P
Rɪᴋᴇʀ

Answers:


4

Python 2,334

p=open("f.txt",'r').readlines()
r,S,p=p[0][7:],p[2].strip(),p[3:-1]
import textwrap as t,itertools as i
m,l=max([len(s[:-5].strip()) for s in p]),len(S)-2
P = i.izip_longest(["{} {{:{}}}|".format(s[:m],l-m) for s in p],t.wrap(r,l-m),fillvalue="")
print S
for q in P:
 if not q[0]:break
 print q[0].format(q[1])
print S

样本IO,其内容为,f.txt其后是代码输出

情况1

Proof: This is a most excellent proof, too small for anyone!
Text:                       
------------------------+
Hello world!            |
How are you, to         |
day? --Mme. B           |
                        |
------------------------+

------------------------+
Hello world!    Proof:  |
How are you, to This is |
day? --Mme. B   a most e|
                xcellent|
------------------------+

情况二

Proof: Consider supercalifragilisticexpialidocious. Therefore, x.
Output:
-----------------------------------------+
sections 1.10.32 and                     |
1.10.33 of "de Finibus                   |
Bonorum et Malorum"                      |
(The Extremes of Good                    |
and Evil) by Cicero,                     |
written in 45 BC. This                   |
book is a treatise on                    |
the theory of ethics,                    |
very popular during the                  |
Renaissance. The first                   |
line of Lorem Ipsum,                     |
"Lorem ipsum dolor sit                   |
amet..", comes from a                    |
line in section 1.10.32.                 |
-----------------------------------------+

-----------------------------------------+
sections 1.10.32 and     Consider superca|
1.10.33 of "de Finibus   lifragilisticexp|
Bonorum et Malorum"      ialidocious.    |
(The Extremes of Good    Therefore, x.   |
and Evil) by Cicero,                     |
written in 45 BC. This                   |
book is a treatise on                    |
the theory of ethics,                    |
very popular during the                  |
Renaissance. The first                   |
line of Lorem Ipsum,                     |
"Lorem ipsum dolor sit                   |
amet..", comes from a                    |
line in section 1.10.32.                 |
-----------------------------------------+

情况3

Proof: Alex is a bird. All birds can fly. All things that fly are wrong. Ergo, Alex is wrong.
Text:
----------+
Sorry     |   
----------+

----------+
Sorry Alex|
----------+

当给定的单词与一行的其余部分不符时,您的程序应将其放在下一行。
Conor O'Brien 2015年

您在哪里看到它没有以这种方式执行?
wnnmaw 2015年

在您的第一个示例中,“ excellent”应放在下一行;在第二个示例中,“ superca”也应放在下一行。很抱歉在那里的歧义。
Conor O'Brien 2015年

1
但是“优秀”不适用于下一行,它必须以任何一种方式中断,因此我不认为这与当前编写的规则有何不同。我目前不知道您正在描述的实现代码的任何方式
wnnmaw

2
你有一个点那里,那它如何措辞。完全我的错,您的代码很好。
Conor O'Brien
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.