Найкращий доказ, занадто малий для фі-!


12

Ти сидиш вдома, розтираючи руки в самий злий спосіб. Цього разу я зможу встановити спільноту A-SPIN! Я просто стверджую, що я довів цю проблему (яка, без сумніву, неможлива) всередині цієї книги тут ... Ви відкриваєте першу відповідну сторінку. Ви скребте ці слова ...

Ти, звичайно, злий Фермат! Ха-ха, просто жартую. Ви знаєте, що не сталося так; це лише розповідь про його злого близнюка, Формат. Формат тут занадто ледачий, щоб конденсувати його «доказ» у запасі. Тому він закликав вас зробити це за нього.

Завдання Дано доказ (рядок) та сторінку (текстовий блок), "записати" у поле доказу.

Дійсні правила сторінки

Текстовий блок містить сторінку, якщо і лише якщо вона відповідає таким вимогам:

  • Верхня та нижня межі мають форму -{10,}\+$(Регулярний вираз -принаймні десять разів до a +, потім кінець рядка).
  • Кожен не верхній і нижній рядок повинен закінчуватися символом a |. Буде хоча б одна така лінія.
  • У |кожному рядку буде щонайменше п’ять пробілів від останнього .
  • Всі лінії однакової ширини.

Отже, наведена нижче сторінка - це дійсна сторінка ( .s - для показу максимальної межі поля):

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

Ось ще одна сторінка з більш широким полем:

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

Ви повинні написати заданий рядок в полі, зберігаючи слова, які ви можете, наскільки це можливо. Наприклад, якщо helloпідходить для наступного рядка, не розбивайте його на поточний рядок.

I / Os

Текст наповнювача

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|
----------+

Це , тому найкоротша програма в байтах виграє!


Таблиця лідерів


Маленьке нове в кодегольфі, чи можу я забрати сторінку та доказ із файлів? Або вони повинні надходити від вводу-виводу користувача?
— wnnmaw

@wnnmaw Ласкаво просимо до коду гольфу! Якщо краще, ви можете прочитати з файлу.
— Conor O'Brien


@Mego Не зовсім. Крім того, ви хочете, щоб ви визнали "маржу"; цей текст повинен був бути виправданим, а не просто розбитим.
— Conor O'Brien

Ну, дякую, що ви навчали мене про lorem ipsum. : P
— Rɪᴋᴇʀ

Відповіді:


4

Пітон 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|
------------------------+

Випадок 2

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

Де ви бачите, що це не працює таким чином?
— wnnmaw

У вашому першому прикладі "відмінно" слід поставити на наступний рядок; у вашому другому прикладі "superca" також слід поставити на наступний рядок. Вибачте за неоднозначність там.
— Conor O'Brien

1
Але "відмінно" не вписується в наступний рядок, він повинен розійтися в будь-якому випадку, тому я не бачу, як це суперечить правилам, як вони написані на даний момент. Наразі я не знаю жодного способу реалізації коду, як ви зараз описуєте
— wnnmaw

2
Ви маєте там точку, саме так це написано. Моя вина цілком, ваш код добре.
— Conor O'Brien
Використовуючи наш веб-сайт, ви визнаєте, що прочитали та зрозуміли наші Політику щодо файлів cookie та Політику конфіденційності.
Licensed under cc by-sa 3.0 with attribution required.