Tex Alıntılar (UVa 272)


17

Bir dize verildiğinde, tüm sol-çift tırnakları iki backtick ve tüm sağ-çift tırnakları iki tek tırnak içine alın.

Sol tırnak işaretleri bir fiyat teklifi başlatan tırnaklar anlamına gelir. Sağ tırnak işaretleri, bir alıntıyı bitiren tırnaklar anlamına gelir. Tırnak işaretleri iç içe olamaz. Dizede çift sayıda çift tırnak bulunduğunu varsayabilirsiniz.

Örnekler

Giriş:

"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"

Çıktı:

``To be or not to be,'' quoth the Bard, ``that
is the question''.
The programming contestant replied: ``I must disagree.
To `C' or not to `C', that is The Question!''

Sol çift tırnak işaretleri ve sağ çift tırnak işaretleri nelerdir?
zamirim monicareinstate

1
@someone Sol çift tırnak, bir fiyat teklifi başlatan tırnaklardır. Sağ çift tırnak, bir teklifi bitiren tırnaklardır.
Radyoaktif

Alıntılar iç içe geçebilir mi?
zamirim monicareinstate

@someone Hayır. Yapamazlar.
Radyoaktif

3
@ LegionMammal978 "Alıntılar yuvalanabilir mi?" ... "Birisi Hayır. Yapamazlar."
Jonathan Allan

Yanıtlar:


18

Okunamaz , 789777 bayt

X6 yerine X34 değişkeni kullanılarak -12 bayt.

' '' '' ''' "" ' '' ' ' '''' ' ' '''' ' ' '''' ' ' '''' ' ' '''' ' ' ''''" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" '" " ' '''" " ' '''" " ' '' ' ' '' '' '''' ' ' '''' ' ' '''' '''" " ' '''" "' "" ' '''" "" "" "" ' ''' "" "' '' '' ' ' '''' '' ''" ' '' "' '' '' '' '' '' ' '' ''' "" "" "" ' ''' "" ' ''' "" " ' '' '' '' ' ' '''' '''" "" " ' '' '' "" ' ''' "" ' '' ' ' '' '' '' ' ' '' ' ' '' '''' '' '''' '' '' '''' "'"" ' '''" "" ' '' ''' "" "" "" ' ''' "" ' ''' "" " ' '' '' '' '''" "" "" "" ' ''' "" ' ''' "" " ' '' '' '''" " ' '''" "" ' '' '' '' ''' "" "" "" " ' '' ' ''' "" "' '' '' '' ''" ' '' '' '' ' ' '''' "' '' "'" ' '' '' ''"' ''"'" ' '' '' '' '' "' '' '' '' ' ' '' '' '' ' ' '''' '''' '' ' ' '' '' '''' "" "" "" ' ''' "" " ' '' '' '' '''" "" '"' '' '' '' ' ' '''' ' ' '''' "'" "" ' '' ''' "" "" "" ' '' '' '' ' ' '''' ''' "" "' ' ' '''' ' ' ''''"'"" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" ' ''' "" '" " ' '''" " ' '''" " ' '''" " ' '''" " ' '''" " ' '''" " ' '''" " ' '''" "' "" ' '''" "' '' '' '' ' ' '''' ' ' ''''"' '' "

Çevrimiçi deneyin!

Dil adına yapılan geleneksel anma başına değişken genişlikli yazı tipinde görüntülenir.

Bu meydan okuma için Okunamaz öğrendim, çünkü iş için en iyi araç olduğu açıktır. Okunamayan'da izin verilen tek karakterler vardır 've "bu yüzden kesinlikle "içine girmeyi gerektiren bir meydan okuma için mükemmel şekilde uygundur ''. Öyle değil mi?

Açıklama:

'""""""'""'""" assign to X2
'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""" 34 (double quote sign)
'""""""'""'""'""'""'""" assign to X5
'""'""'""'""'""'"""""""'""'""" X2+5 (apostrophe sign)
'"""""'""'""""""'"""'"""""""""" while (1+ (assign to X1 a value read from stdin, or -1 if stdin is empty) != 0)
 '"""" do 2 things
 '""""""'""'""'""'""" assign to X4
 '"""""""'""'""" the value of X2
 AND
 '"""" do 2 things
 '""""""'""'""'""" assign to X3
 '"""""""'""" the value of X1
 AND
 '"""" do 2 things
 '"""""'"""""""'""'""'""'""" while(X4 != 0)
  '"""" do 2 things
  '""""""'""'""'""'""" assign to X4
  '""""""""'"""""""'""'""'""'""" X4-1
  AND
  '""""""'""'""'""" assign to X3
  '""""""""'"""""""'""'""'""" X3-1
 end while
 AND
 '"""""""""'"""""""'""'""'""" if(X3 != 0)
  '"'"""""""'""" print X1
 else
  '" print the output of
  '"""""""""'"""""""'"""""""'""'""" if(X34 !=0)
   '"""" do 2 things
   '""""""'"""""""'""'"""'""""""""'""" assign X34=0
   AND
   '"'"""""""'""'""'""'""'""" print X5
  else
   '"""" do 2 things
   '""""""'"""""""'""'"""'""" assign X34=1
   AND
   '"'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'"""""""'""'""'""'""'""" print X5+57
 end if
end while

(X34'e yapılan çağrılar, X5 = 34 olduğundan aslında X (X5) çağrılarıdır.)


1
Bir quoty meydan okuma bir alıntı dil LOL
HighlyRadioactive

5

Retina , 13 bayt

Retina'yı hızlı bir şekilde öğreniyorum çünkü bir nedenden dolayı Japt kazanmayı sevmiyorum ve bir C # çözümü zaten düzenli ifadeler kullanacak gibi hissediyorum. Retina cevabı olduğunu biliyorum, ama bunu oluştururken kullanmadım ve yine de buldum.

#2$`"
``
"
''

Çevrimiçi deneyin!


1
Japt için neden nefret ?! : p
Shaggy




4

Japt , 12 bayt

Japt sadece (veya belki de bir hata) bir sınırlaması için 11 olurdu.

r'"ȲîT°g"`'

Dene

r'"ȲîT°g"`'     :Implicit input of string
r'"              :Replace double quotes
   È             :Pass each match through a function
    ²            :  Duplicate
     î           :  Replace each character with
      T°         :    Postfix increment T (initially 0)
        g"`'     :    Index into "`'" with wrapping

Burada kullanamayacağınız çok kötü Q: \
Oliver

@Oliver, yapabilirim (ve aslında yaptım); Sadece benim ,de ihtiyacım var .
Shaggy

Ben sadece kullanamadı çok kötü demek Qyerine'"
Oliver

4

TeX, 54 32 bayt

TeX tırnak değiştirme meydan okuma için elbette bir TeX sürümüne de ihtiyacımız var!

\catcode`"13\def"#1"{``#1''}...\bye

... girdi dizesidir, bu nedenle bayt sayısına eklenmez.


1
Neden daha basit değil \def"#1"{``#1''}? (veya \long\defbir paragraf sınırını aşmak için bir fiyat teklifi bekliyorsanız)
Phelype Oleinik

1
Bunu düşünmediğim bariz nedenlerden dolayı :-)
siracusa

2

Kömür , 23 bayt

WS⊞υι⭆⪪⪫υ¶¦"⎇κ⁺ײ§'`κιι

Çevrimiçi deneyin! Bağlantı, kodun ayrıntılı versiyonudur. Zorlu giriş biçimini önlemek için 8 bayt içerir. Açıklama:

WS⊞υι

Boş bir satıra ulaşılana kadar giriş satırlarını toplayın.

⪫υ¶¦

Yeni satır karakterlerindeki satırlara katılın.

⪪..."

Girişi tırnaklara ayırın.

⭆...

Her parçayı eşleyin ve sonuçları örtük yazdırma için birleştirin.

⎇κ...ι

İlk kısmı değiştirmeden bırakın.

⁺ײ§'`κι

Uygun teklifin önüne, iki katına.


Bir Kömür çözümü bekliyordum. Güzel!
Radyoaktif

2

R , 40 bayt

cat(scan(,"",,,'"',""),sep=c("``","''"))

Çevrimiçi deneyin!

Dize girdisini okur, her birinde ayırır, "dizeler vektörü verir. Daha sonra bu telleri, çift geri tepmeler ve çift kesme işaretleri arasında ayırıcılar olarak değiştirerek, gerektiğinde geri dönüştürerek yapıştırın.

Birisi muhtemelen bir regex dayalı daha kısa bir R cevap gönderecektir ... Yine de, bu cevap R daha tipik, sanırım.

Parçanın açıklaması scan(,"",,,'"',""):

scan(, # empty first parameter: read from STDIN
  "",  # type of input is a string
  ,    # default 3rd parameter nmax
  ,    # default 4th parameter n
  '"', # separate on character "
  "")  # do not treat any characters as quotations marks (necessary to handle ' in the input)

2

Perl 6 , 23 bayt

{S:g/\"(.*?)\"/``$0''/}

Çevrimiçi deneyin!

Lanet olsun, bariz çözüm daha kısa. Alıntılanan her bir parçayı, uygun tırnak işaretleri içeren bir sürümle değiştirir.

Perl 6 , 24 bayt

{S:g{\"}=<`` ''>[$++%2]}

Çevrimiçi deneyin!

İki karakter kümesi arasında dönüşümlü olarak her bir çift tırnak işareti yerine geçer.


1

Retina , 15 bayt

"
""
Y`"`\`\`''

Çevrimiçi deneyin! Sıkıcı Retina 0.8.2 cevabını 1 bayt olarak dışar. Açıklama:

"
""

Tüm alıntıları çoğaltın.

Y`"`\`\`''

Tırnak işaretlerini periyodik olarak çift tırnak ve tek tırnak işareti ile değiştirin.

Tamlık için sıkıcı 16 bayt Retina 0.8.2 cevabı:

s`"(.*?)"
``$1''

Çevrimiçi deneyin!




1

Labyrinth, (43?) 53 bytes

396"
 } "",)@
  ~"  (
 "~ 3_:
""" 4
" .;-
=   ;
..::;

Try it online!

A golfed version of this, much simpler, 92 byte program:

3 """
9 " ",)@
}96 " (
    " :_34-;;
    "     ; :
   """"""". :
   "        .
   """"""""=.

If we don't need to handle input containing the zero byte then 43 bytes:

39}9
@  6
`,""
`  "
: ."=..
_ ;   "
34-;;::


1

(GNU) sed, 38 33 30 bytes

-4 by removing the -n flag and implicitly printing on n, -1 by reusing previous /expression/, thanks @Cowsquack. -3 by using implicit branch-to-end.

:a
s/"/``/;T
:b
s//''/;ta
n;bb

Try it online! Try it online! Try it online!

Some pretty basic label jumping. This can probably be golfed by a byte or two.

:a          # label a
s/"/``/;T   # replace " -> ``. If unsuccessful, move to next line
:b          # label b
s//''/;ta   # replace " (implicit) -> ''. If successful, jump to a (w/o reading new line)
n;bb        # read in the next line, but jump to label b. 

1
Btw typically the flags used are specified in the header. You can golf a byte using codegolf.stackexchange.com/a/167295/41805, in addition some of the branching logic can be removed. Then making the solution work without the -n flag should save a bit more. (And of course there is the trivial sed -z solution which I presume you to have intentionally avoided)
Kritixi Lithos

Alright, I dug back into man sed for a bit and got to 30. Feel free to let me know anything I missed, you've got the golf experience on this lang. (Oh, -z is new to me, but I agree. I'll stay without it.)
GammaFunction

Nicely done, I am always glad to see a sed answer
Kritixi Lithos

1

05AB1E, 15 bytes

'"¡ā¨„'`sè2×.ιJ

Try it online!

No regexes in 05AB1E, so we split on ", make a list of alternating `` and '', then interleave the two.


1
Ok, looks like I don't have to fix and undelete my answer. ;)
Kevin Cruijssen

1

Haskell, 67 60 58 bytes

(#0)
('"':x)#n=["``","''"]!!n++x#(1-n)
(a:b)#n=a:b#n
x#n=x

Try it online!

The relevant function is (#0).

Since I originally thought the question also required us to convert single quotes here is a version that handles both:

Haskell, 125 bytes

(#(1<0,1<0))
('"':x)#(m,n)=last("``":["\""|m])++x#(not m,n)
('\'':x)#(m,n)=last('`':['\''|n]):x#(m,not n)
(a:x)#n=a:x#n
x#n=x

Try it online!


"\"" should be "''" (two apostrophes)
siracusa

@siracusa Thanks, I assumed since you can use " in tex you could use it here.
Post Rock Garf Hunter

1

QuadR, 14 bytes

"(.*?)"
``\1''

Try it online!

Simple find/replace using @Adám's wrapper for Dyalog APL's ⎕Replace function.

How:

"(.*?)"  PCRE, finding anything between two double quotes and assigning it to group 1
``\1''   Transformation string, replacing the match with ``group_1''.


0

Jelly, 13 bytes

ṣ”"µJḊ⁾`'ṁḤż@

A full program.

Try it online!

How?

ṣ”"µJḊ⁾`'ṁḤż@ - Main Link: list of characters, T   e.g. ..."hi" - she "said"...
 ”"           - character '"'                           '"'
ṣ             - split (T) at ('"')                      ["...","hi"," - she ","said","..."]
   µ          - (call that X) start a new monadic chain
    J         - range of length (of X)                  [1,2,3,4,5]
     Ḋ        - dequeue                                 [2,3,4,5]
      ⁾`'     - list of characters                      ["`","'"]
         ṁ    - mould like                              ["`","'","`","'"]
          Ḥ   - double                                  ["``","''","``","''"]
           ż@ - (with reversed @rguments) zip (with X)  [["...","``"],["hi","''"],[" - she ","``"],["said","''"],["..."]]
              - implicit (smashing) print               ...``hi'' - she ``said''...



0

Stax, 11 bytes

û╩↕H£ñ╟Uzay

Run and debug it

Procedure:

  1. Take all input, newlines and all.
  2. Regex replace '"' with a block that produces alternating outputs of pairs of backticks and foreticks(?)

0

Java 8, 40 bytes

s->s.replaceAll("\"([^\"]+)\"","``$1''")

Try it online.

Explanation:

s->                             // Method with String as both parameter and return-type
  s.replaceAll("\"([^\"]+)\"",  //  Replace all these matches,
               "``$1''")        //  with this replacement 

Regex explanation:

 "([^"]+)"                      // MATCH:
 "                             "//  A literal "
   [^"]+                       "//  Followed by 1 or more non-" characters
  (     )                       //  (captured in capture group 1)
         "                     "//  Followed by a literal " again

``$1''                          // REPLACEMENT:
``                              //  Literal ``
  $1                            //  Followed by the match of capture group 1
    ''                          //  Followed by a literal ''

0

Wren, 91 bytes

Fn.new{|n|
var c=1
for(i in n.split("\"")[1..-1])System.write(((c=-~c)%2==0?"``":"''")+i)
}

Try it online!

Explanation

Fn.new{|n| // New anonymous function
var c=1    // Set the index counter as 1
for(i in n.split("\"")                                                 // For each over n splitted with quotes
                      [1..-1])                                         // Get rid of the first quote
                              System.write(                          ) // Output this to the console
                                           (
                                            (c=-~c)                    // Increment the counter
                                                   %2==0?"``"          // If that's divisible by 2, output a backquote
                                                             :"''"     // Otherwise, output a frontquote
                                                                  )+i  // Join the result with i
}

0

GolfScript, 35 34 bytes

1:c;{.34={;c)2%:c'""'"``"if}""if}%

Try it online!

Explanation

1:c;                                # Set 1 to the current item counter

    {                            }% # Map for every character in the input:
     .34=                      if   #     If the character isn't the quote,
                             ""     #         Just leave it alone
         {                  }       #     Otherwise:
          ;                         #         Remove the copy of the input
           c):c                     #         Increment the counter
                2%        if        #         If the counter isn't divisible by 2, 
                  '""'              #             Output the double-quote
                      "``"          #         Otherwise: Output the double backtick
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.