拆分莎士比亚剧本


13

威廉·莎士比亚先生写了戏剧。很多戏剧。在这个包含他的每一份作品的tarball中,他的每一部戏都是一个长文件。
需要将其拆分为场景以进行舞台制作。由于参与者不耐烦,因此您的代码需要尽可能短。

任务:

您的任务是编写一个程序或函数,以将该文件中包含的播放拆分为多个单独的文件,并从依次编号1,其中每个包含一个场景。您应该保留所有空格和标题。

输入:

输入将通过播放stdin,或将文件名作为参数。你可以选择。该剧将如下所示:

 TITUS ANDRONICUS


    DRAMATIS PERSONAE


SATURNINUS  son to the late Emperor of Rome, and afterwards
    declared Emperor.

BASSIANUS   brother to Saturninus; in love with Lavinia.

TITUS ANDRONICUS    a noble Roman, general against the Goths.

MARCUS ANDRONICUS   tribune of the people, and brother to Titus.


LUCIUS  |
    |
QUINTUS |
    |  sons to Titus Andronicus.
MARTIUS |
    |
MUTIUS  |


Young LUCIUS    a boy,
[...]
ACT I



SCENE I Rome. Before the Capitol.


    [The Tomb of the ANDRONICI appearing; the Tribunes
    and Senators aloft. Enter, below, from one side,
    SATURNINUS and his Followers; and, from the other
    side, BASSIANUS and his Followers; with drum and colours]

SATURNINUS  Noble patricians
[...]
ACT I



SCENE II    A forest near Rome. Horns and cry of hounds heard.


    [Enter TITUS ANDRONICUS, with Hunters, &c., MARCUS,
    LUCIUS, QUINTUS, and MARTIUS]

TITUS ANDRONICUS    The hunt is up, the morn is bright and grey,
    The fields are
[...]
ACT II



SCENE I Rome. Before the Palace.


    [Enter AARON]

AARON   Now climbeth Tamora
[...]

输出:

输出应如下所示:

ACT I



场景I罗马。在国会大厦之前。


    [ANDRONICI的坟墓现身;论坛报
    和参议员高高在上。在下面从一侧输入,
    SATURNINUS及其追随者;并且,从另一个
    方面,BASSIANUS及其追随者;鼓和颜色]

SATURNINUS贵族贵族...
ACT I



场景II罗马附近的一片森林。听到了号角和猎犬的叫声。


    [与Hunters,&c。,MARCUS一起输入TITUS ANDRONICUS,
    LUCIUS,QUINTUS和MARTIUS]

TITUS ANDRONICUS狩猎结束了,早晨是明亮的灰色,
    领域是...
ACT II



场景I罗马。在宫殿之前。


    [输入AARON]

亚伦现在爬上塔莫拉...

等等

stdout用您选择的分隔符输出到编号文件或流(返回函数)中。

奖金:

  • 10%如果将Act 1之前的位保存到file中0。注:如果Act 1之前的位为空,则不得中断。
  • 15%如果可以同时使用stdin和输入文件路径参数
  • 20%如果可以同时输出到文件和stdout/返回。
  • 如果可以制作最小的SPL程序,则可获得200声望此赏金已授予。

排行榜

这是一个堆栈片段,用于按语言生成常规排行榜和获胜者概述。

为了确保您的答案显示出来,请使用以下Markdown模板以标题开头。

# Language Name, N bytes

N您提交的文件大小在哪里。如果您提高了分数,可以将旧分数保留在标题中,方法是将它们打掉。例如:

# Ruby, <s>104</s> <s>101</s> 96 bytes

如果您想在标头中包含多个数字(例如,因为您的分数是两个文件的总和,或者您想单独列出解释器标志罚分),请确保实际分数是标头中的最后一个数字:

# Perl, 43 + 2 (-p flag) = 45 bytes

您还可以将语言名称设置为链接,然后该链接将显示在页首横幅代码段中:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table><script>var QUESTION_ID=68997,OVERRIDE_USER=43394;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?([\d\.]+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;</script>


16
对于第一份有效的莎士比亚编程语言论文,我将给予+200的悬赏。
2016年

3
来吧,每个人都知道CodeGolf并不快。为什么不说“压缩包已经很满了,所以您的代码应该尽可能短”?
J_F_B_M 2016年

1
@trichoplax产品。我以为那是每个人的做法!在笔记本中
划掉


2
@cat-保持打开状态;我敢肯定,莎士比亚的解决方案比我的解决方案小。我的胖子就像一只大的大猫和一只猫的总和一样胖。
罗伯特·弗雷泽

Answers:


38

莎士比亚编程语言1.2.1930 895 887 - 10(%)= 798.3字节

G.Ajax,a.Puck,a.Page,a.Ford,a.Act I:a.Scene I:a.[Enter Ajax and Puck]Puck:Open thy mind.Ajax:Open thy mind.[Exit Puck][Enter Page]Ajax:Open thy mind.SCENE II:b.[Exeunt][Enter Puck and Ajax]Ajax:Am I as fat as the sum of the cube of a big big cat and a cat?Puck:If not,let us return to scene III.Am I as fat as the sum of you and a big cat?[Exit Puck][Enter Page]Page:If not,let us return to scene III.Am I as fat as the sum of the sum of the cube of a big big cat and a big big big big cat and a big big cat?[Exit Page][Enter Ford]Ajax:If not,let us return to scene III.You is a big big big big big big cat.Speak thy mind.Scene III:c.[Exeunt][Enter Ajax and Puck]Puck:Speak thy mind.You is as fat as I.[Exit Ajax][Enter Page]Page:You is as fat as I.Puck:Open thy mind.Is you as fat as a hog?[Exit Page][Enter Ajax]Puck:If not,let us return to Scene II.Speak thy mind.Ajax:Speak thy mind.

脱手并用鲨鱼语重写:

Four Gentlemen of Verona.

Ajax, a master code-golfer with years of experience.
Puck, a young Java programmer and a strong believer in object-oriented design patterns.
Page, a rapscallion of ill repute.
Ford, a car manufacturer.

Act I: A one-act masterpiece.

Scene I: In which many minds are opened, possibly via the consumption of psychadelic drugs.
[Enter Ajax and Puck]
Puck: Open thy mind.
Ajax: Open thy mind.
[Exit Puck]
[Enter Page]
Ajax: Open thy mind.

SCENE II: In which things are compared.
[Exeunt]
[Enter Puck and Ajax]
Ajax: Am I as hairy as the sum of the cube of a furry purple chihuahua and a summer's day?
Puck: If not, let us proceed to scene III. Am I as half-witted as the sum of you and a cunning squirrel?
[Exit Puck]
[Enter Page]
Page: If not,let us proceed to scene III. Am I as delicious as the sum of the sum of the cube of a warm healthy hamster and a proud handsome charming noble nose and a big old aunt?
[Exit Page]
[Enter Ford]
Ajax: If not, let us proceed to scene III. You are the cube of a tiny small pony. Speak thy mind.

Scene III: In which minds are spoken.
[Exeunt]
[Enter Ajax and Puck]
Puck: Speak thy mind. You are as smelly as I.
[Exit Ajax]
[Enter Page]
Page: You are as oozing as I.
Puck: Open thy mind. Are you as disgusting as a Microsoft?
[Exit Page]
[Enter Ajax]
Puck: If not,let us return to Scene II. Speak thy mind.
Ajax:Speak thy mind.

在类似C的伪代码中:

Scene_I:
    Ajax = getchar()
    Puck = getchar()
    Page = getchar()
Scene_II:
    if(Ajax != 'A')
        goto Scene_III
    if(Puck != 'C')
        goto Scene_III
    if(Page != 'T')
        goto Scene_III
    Ford = '@'
    putchar(Ford)
Scene_III:
    putchar(Ajax)
    Ajax = Puck
    Puck = Page
    Page = getchar()
    if(Page != -1)
        goto Scene_II
    putchar(Ajax)
    putchar(Puck)

要求输入文件包含至少3个字符。使用“ @”作为分隔符,并将结果报告给标准输出。我拿了10%的奖金,因为第一个场景之前的部分将在第一个“ @”之前,就像上面MartinBüttner的解决方案一样。

它的工作方式是,如果连续看到三个字符“ ACT”,则放置一个“ @”。注意,这意味着它将把“ ENACTED”转换为“ EN @ ACTED”。可以花几百个字节来解决这个问题,但是幸运的是,给定播放中的每个“ ACT”(至少我检查过的几个)似乎都是场景的开始。

使用上面链接的1.2.1 SPL测试。我不确定它是否可以在网络解释器上运行。用于测试的脚本是:

#!/bin/bash
set -e
SCRIPT_DIR=`dirname "$0"`
cd "$SCRIPT_DIR"
spl/bin/spl2c <splits.spl >splits.c
gcc -O2 -Wall -Wno-unused -I./spl/include -L./spl/lib -lm -lspl -o splits splits.c
./splits <measureforemeasure >measure.split.txt

跳过语法后,SPL的“深奥”部分就是在“舞台”上改组变量(通常,您一次只希望在舞台上有两个字符)以及表示常数。分布中有6个重要的导入词列表:正形容词,中性形容词,负形容词,正名词,中性名词和负名词。一个正/中性名词(例如,李子或石墙)为1,一个负/名词(例如调情ir或Microsoft)为-1。正/中性形容词(即绣花或无底的形容词)将数字乘以2,而负形容词(即肥肾或无父的形容词)乘以-2。可悲的是,单词列表非常有限,每个单词列表只有10-20个条目。

在我的下一次会议上,我将建议我们将所有生产代码移至莎士比亚,因为它比Scala更具表现力。


2
尽可能多地打高尔夫球。请!
wizzwizz4 2016年

1
天哪,我没想到有人会这样!我会在24小时内授予该奖项,我会尽快:)

2
@ wizzwizz4-绝对;当我没有实际工作要做时,我会试一试:-)。就像是由吟游诗人本人写的那样,它会简洁明了
罗伯特·弗雷泽

2
现在,我可以雇用谁在舞台上表演?
2016年

3
@cat-找三个对自己的体重没有把握的人,给他们看一张猫的照片。
罗伯特·弗雷泽

12

视网膜,9-10%= 8.1字节

字节数假定为ISO 8859-1编码。

¶ACT 
=$0

=在每行的前面插入一个(作为定界符),ACT以换行符开头,后跟一个空格。

在线尝试!(但是由于输入的大小,您必须自己复制输入。)


祝贺您回答69000(根据share-link)。
J_F_B_M 2016年

@J_F_B_M邮政69000。这是问题答案。
wizzwizz4 2016年

4

awk,51 * .9 * .85 * .8 = 31.2

拆分为多个文件。输出以stdout分隔=

/^ACT/{f++;$0="="$0}{system("echo \""$0"\">>"f*1)}1

+1现在您需要做的就是输出所有文件,stdout并用一个特定的字符分隔,就可以了!
wizzwizz4 2016年

做完了 有了奖金,它的长度几乎相同。
Rainer P.

+2 ... +2 ........ +2 .........否。系统不允许它:-(不过,我建议使用字符分隔它们这是更不常见的,如¬或|。
wizzwizz4


3

Perl,66-10%-20%= 47.52字节

BEGIN{open(S,">0");}++$?,open(S,">$?"),print"=\n"if/^ACT/;print S

为该-p选项添加了一个。


1

Ruby,30-10%-15%= 23.715 22.95字节

在上分割输入$。提供15%的奖金是因为Ruby重定向$<到指向ARGV默认情况下传入的文件(如果提供的话),否则提供文件STDIN

-1字节通过使用gsub类似于@Downgoat ES6解决方案的方法,但我仍然在希望ACT仅出现在ACT标签而不是其他任何单词内的希望,只是因为

$><<$<.read.gsub("ACT","$ACT")

另外,我的41.004(最初为67)字节的解决方案也可以输出文件。与Ruby相比,该each命令可能仅在该命令中唯一一次加星标map,因为each返回的结果是在运行其块后返回纯净的数组map

i=-1;$><<$<.read.split(/(?=ACT)/).each{|s|open("#{i+=1}",?w)<<s}*?$
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.