中世の正書法


9

仕事

あなたの仕事は、テキストを中世の正書法に変換することです。

細部

  1. jiおよびJに変換されIます。
  2. uそしてU言葉の初めにに変換されますvV、それぞれ。
  3. vV単語の先頭以外の場所uUそれぞれに変換されます。
  4. sſ単語の終わりまたは前に別のがない限り、(U + 017F)に変換されsます。

スペック

  • 単語は、で一連の文字として定義されabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZます。
  • すべての単語には少なくとも2つの文字が含まれます。
  • 入力は、印刷可能なASCII文字(U + 0020-U + 007E)のみで構成されます。
  • 連続して2つ以上発生することはありませんs。つまりsss、入力の部分文字列にはなりません。

テストケース

個別の単語:

Input       Output
------------------------
Joy         Ioy
joy         ioy
Universe    Vniuerſe
universe    vniuerſe
Success     Succeſs
successfull ſucceſsfull
Supervise   Superuiſe
supervise   ſuperuiſe
Super-vise  Super-viſe
I've        I've
majors      maiors
UNIVERSE    VNIUERSE
0universe   0vniuerſe
0verify     0verify
I0ve        I0ve
_UU_          _VU_
_VV_          _VU_
ss_         ſs_

段落全体:

Input:  Christian Reader, I have for thy use collected this small Concordance, with no small labour. For being to comprise much in little roome, I was to make choyse of the most principall and usefull places, and to rank them under such words as I thought most essentiall and materiall in the sentence, because the scant roome allotted unto me, would not permit that I should expresse them under every word in the verse, as it is the manner in large Concordances.

Output: Chriſtian Reader, I haue for thy vſe collected this ſmall Concordance, with no ſmall labour. For being to compriſe much in little roome, I was to make choyſe of the moſt principall and vſefull places, and to rank them vnder ſuch words as I thought moſt eſsentiall and materiall in the ſentence, becauſe the ſcant roome allotted vnto me, would not permit that I ſhould expreſse them vnder euery word in the verſe, as it is the manner in large Concordances.

最後のテストケースの出力のSHA-256ハッシュは次のとおりです。

5641899e7d55e6d1fc6e9aa4804f2710e883146bac0e757308afc58521621644

免責事項

Medievallの正書法は、それほど重要ではありません。異なる正書法を使って古い本を読む場合は、問題はありません。


1
「出力ではofの代わりにfを使用できます。」したがって、バイト数が増えるため、basicallyを使用するインセンティブは基本的にありません。
16

1
@Fatalizeフェアポイント。それを削除しました。
Leaky Nun

@LeakyNunその後ſ、1バイトとしてカウントできますか?
R. Kap

ſが使用されなかった場合、一部のアルゴリズムではffがfsに変更される形で実際にインセンティブがあります
Destructible Lemon

1
すべきではないSuper-viseになりますかSuper-viſe
R. Kap

回答:


3

SED、144の140の 111バイト

NoOneIsHereのおかげで29バイトを節約

-r -e'y/j/i/g;y/J/I/g;s/ u/ v/g;s/ U/ V/g;s/^u/v/g;s/^U/V/g;s/([^s])s(\w)/\1ſ\2/g;s/(\w)v/\1u/g;s/(\w)V/\1U/g'

1
あなたは勇敢で勇敢な魂です。
アレクサンダー-モニカを復活させる

1だけを使用して、多くのバイトをカットできます-e;中間のステートメントを使用します。
NoOneIsHere

あなたがそれができるとは知りませんでした。ありがとう!!
ライリー

2

Python 3(128 126バイト)

import re;lambda k:re.sub("(?<!s)s(?=[a-zA-Z])",'ſ',re.sub("(?i)j|(?<![a-z])u|(?<=[a-z])v",lambda c:chr(ord(c.group())^3),k))

chr(ord(c.group())^3)単一文字の文字列をxorするのは過度に感じますが、おそらく本物のPythonistaがゴルフを提案できます。しかし、それはすることが非常に便利です^3で十分に交換するi <-> ju <-> v

注意:Python 3を必要とする唯一のことは、Unicode文字です:Python 2は不平を言いNon-ASCII character '\xc5' <snip> but no encoding declaredます。


数字とアンダースコアを含む単語の定義を使用しているため\b\b使用しないでください。
Leaky Nun

@LeakyNun、うーん。修正を探している間に、テストケースを追加していただけませんか?
Peter Taylor

@ R.Kap。(?i)
Peter Taylor

@PeterTaylor待って、それは何をしますか?
R. Kap

@ R.Kap、正規表現で大文字と小文字を区別しません。
Peter Taylor


1

パイソン3.5、124 116 111 118 125 144 142バイト。

import re;lambda k:re.sub("J|j|(?<![a-zA-Z])[uU]|(?<=[a-zA-Z])[Vv]|(?<!s)s(?=[a-zA-Z])",lambda g:dict(zip('jJuUvVs','iIvVuUſ'))[g.group()],k)

まあ、これは正規表現に最適な仕事のようです!


1
J|j代わりに使用できます[Jj]
Leaky Nun

1

JavaScript(ES6)、154

parseIntを使用してアルファベット文字を識別する。注:さりげなく、幸運にもparseInt('undefined',36)|00未満

s=>[...s].map((c,i)=>((n=v(c))-19?n==31&p>9?'uU':n!=30|p>9?c=='s'&s[i-1]!=c&v(s[i+1])>9?'?':c+c:'vV':'iI')[p=n,c<'a'|0],p=0,v=c=>parseInt(c,36)|0).join``

ゴルフが少ない

s=>
  [...s].map(
  (c,i)=>
  ((n=v(c))-19
  ?n==31&p>9
    ?'uU'
    :n!=30|p>9
      ?c=='s'&s[i-1]!=c&v(s[i+1])>9
        ?'ſ'
        :c+c
      :'vV'
  :'iI')[p=n,c<'a'|0],
  p=0,
  v=c=>parseInt(c,36)|0
).join``

テスト

F=
s=>[...s].map((c,i)=>((n=v(c))-19?n==31&p>9?'uU':n!=30|p>9?c=='s'&s[i-1]!=c&v(s[i+1])>9?'ſ':c+c:'vV':'iI')[p=n,c<'a'|0],p=0,v=c=>parseInt(c,36)|0).join``

out=(a,b,c)=>O.textContent+=a+'\n'+b+'\n'+c+'\n\n'

ti='Christian Reader, I have for thy use collected this small Concordance, with no small labour. For being to comprise much in little roome, I was to make choyse of the most principall and usefull places, and to rank them under such words as I thought most essentiall and materiall in the sentence, because the scant roome allotted unto me, would not permit that I should expresse them under every word in the verse, as it is the manner in large Concordances.'
to='Chriſtian Reader, I haue for thy vſe collected this ſmall Concordance, with no ſmall labour. For being to compriſe much in little roome, I was to make choyſe of the moſt principall and vſefull places, and to rank them vnder ſuch words as I thought moſt eſsentiall and materiall in the ſentence, becauſe the ſcant roome allotted vnto me, would not permit that I ſhould expreſse them vnder euery word in the verſe, as it is the manner in large Concordances.'
r=F(ti)
out(to==r?'OK':'KO',ti,r)

test=`Joy         Ioy
joy         ioy
Universe    Vniuerſe
universe    vniuerſe
Success     Succeſs
successfull ſucceſsfull
Supervise   Superuiſe
supervise   ſuperuiſe
Super-vise  Super-viſe
I've        I've
majors      maiors
UNIVERSE    VNIUERSE
0universe   0vniuerſe
0verify     0verify
I0ve        I0ve
_UU_          _VU_
_VV_          _VU_
ss_         ſs_`
.split('\n').map(t=>{
  var [i,o]=t.split(/\s+/),r=F(i)
  out(o==r?'OK':'KO',i,r)
})
#O {width:90%; overflow:auto; white-space: pre-wrap}
<pre id=O></pre>


1

JavaScript(ES6)、111バイト

s=>s.replace(/[a-z]+/gi,w=>w.replace(/j|J|^u|^U|\Bv|\BV|ss|s(?!$)/g,c=>"iIvVuUſ"["jJuUvVs".search(c)]||"ſs"))

説明:JavaScript regexpには後読みがないため、代わりに文字列を単語に分割します。これにより^\Bを負の文字と正の文字の後読みとして使用できます。ssは、最初の文字のみを置き換えるか、両方の文字列にc余分なs文字を追加して、一致する部分文字列を使用するよりもバイトが少ない、少し厄介な置換式を使用して、個別に照合することで処理されます。


c=>"iIvVuUſ"["jJuUvVs".search(c)]||"ſs"いいです。👍🏻–
ジョーダン

0

CJam(89 88バイト)

{32|_'`>\'{<*}:A;SqS++3ew{_1="jJuUvVs"#[-4_{_0=A!3*}_{_0=A3*}_{_)A\0='s=>268*}W]=~f^1=}%

オンラインデモ

CJamに正規表現がない理由は理解できませんでしたが、ここにないので、それらを使用しないソリューションがあります。


0

Ruby、85 + 1 = 86バイト

ruby -ppフラグ用に+1バイト)で実行します。stdinで入力を受け取ります。

gsub(/j|(?<=^|[^a-z])u|(?<=[a-z])v|(?<=^|[^s])s(?=[a-z])/i){$&.tr"jJsUuVv","iIfVvUu"}

ideoneでテストを実行します(ideoneにフラグを付けることができないため、そこにラムダでラップされています):http ://ideone.com/AaZ8ya

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.