Bukti paling bagus, terlalu kecil untuk fi—!


12

Anda duduk di rumah, menggosok tangan Anda dengan cara yang paling jahat. Kali ini, saya akan dapat mengatur komunitas A-SPIN! Saya hanya akan mengklaim bahwa saya telah membuktikan masalah ini (yang tidak diragukan dapat diperbaiki) di dalam buku ini di sini ... Anda membuka halaman yang relevan pertama. Anda menuliskan kata-kata itu ...

Anda, tentu saja, Fermat jahat! Haha hanya bercanda. Anda tahu itu tidak terjadi seperti ini; ini hanyalah narasi tentang saudara kembarnya yang jahat, Format. Format di sini terlalu malas untuk menyingkat "bukti" nya ke margin. Karena itu ia meminta Anda untuk melakukannya untuknya.

Objektif yang diberikan bukti (string), dan halaman (blok teks), "tulis" menjadi margin bukti.

Aturan halaman yang valid

Blok teks berisi halaman jika dan hanya jika memenuhi persyaratan berikut:

  • Batas atas dan bawah adalah dalam bentuk -{10,}\+$(Ekspresi reguler -setidaknya sepuluh kali hingga a +, kemudian akhir baris).
  • Setiap baris non-top dan non-bottom harus diakhiri dengan a |. Akan ada setidaknya satu baris seperti itu.
  • Setidaknya akan ada lima ruang dari yang terakhir |di setiap baris.
  • Semua garis memiliki lebar yang sama.

Jadi, berikut ini adalah halaman yang valid ( .untuk menunjukkan di mana batas margin maksimal adalah):

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

Berikut adalah halaman lain dengan margin yang lebih luas:

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

Anda harus menulis string yang diberikan di margin, mempertahankan kata-kata yang Anda bisa, sejauh yang Anda bisa. Misalnya, jika hellococok pada baris berikutnya, jangan putus pada baris saat ini.

I / Os

Isi teks

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

Ini adalah , jadi program terpendek dalam byte menang!


Papan peringkat


Sedikit baru untuk codegolf, dapatkah saya mengambil halaman dan bukti dari file? Atau apakah mereka harus berasal dari pengguna I / O?
wnnmaw

@wnnmaw selamat datang di kode golf! Jika lebih baik, Anda dapat memilih untuk membaca dari file.
Conor O'Brien


@Mego Tidak cukup. Ini ingin Anda mengenali "margin", sebagai tambahan; teks itu harus dibenarkan, bukan hanya dibagi.
Conor O'Brien

Yah, terima kasih sudah mengajari saya tentang lorem ipsum. : P
Rɪᴋᴇʀ

Jawaban:


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

Contoh IO dengan isi f.txtdiikuti oleh output kode

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

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

Kasus 3

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

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

Ketika diberi kata yang tidak cocok dengan satu baris lainnya, program Anda harus meletakkannya di baris berikutnya.
Conor O'Brien

Di mana Anda melihatnya tidak melakukan hal ini?
wnnmaw

Dalam contoh pertama Anda, "sangat baik" harus diletakkan pada baris berikutnya; dalam contoh kedua Anda, "superca" juga harus diletakkan di baris berikutnya. Maaf atas ambiguitas di sana.
Conor O'Brien

1
Tapi "sangat baik" tidak cocok di baris berikutnya, itu harus melanggar baik jadi saya tidak melihat bagaimana ini tidak sesuai dengan aturan seperti yang saat ini ditulis. Saat ini saya tidak tahu cara untuk mengimplementasikan kode seperti yang sekarang Anda jelaskan
wnnmaw

2
Anda memiliki titik di sana, yang adalah bagaimana worded. Kesalahan saya sepenuhnya, kode Anda baik-baik saja.
Conor O'Brien
Dengan menggunakan situs kami, Anda mengakui telah membaca dan memahami Kebijakan Cookie dan Kebijakan Privasi kami.
Licensed under cc by-sa 3.0 with attribution required.