उनके पत्रों के साथ शब्दों को रेखांकित करें


14

किसी शब्द को "रेखांकित" करने के लिए वर्तमान चुनौती के प्रयोजनों के लिए इसका अर्थ है कि इसे अपने पत्रों के साथ क्रमिक रूप से घेरना, पिछले एक के साथ शुरू करना, और अंत में मूल शब्द को रिक्त स्थान के साथ केंद्र में बदलना है:

       oooooo 
       onnnno 
on ->  on  no 
       onnnno
       oooooo

कार्य:

शब्दों की एक सूची को देखते हुए, केवल लोअरकेस और / या बड़े अक्षरों से मिलकर, प्रत्येक शब्द को रेखांकित करते हैं और क्षैतिज रूप से एक दूसरे के बगल में सभी परिणामी ब्लॉकों को प्रदर्शित करते हैं, जो एकल स्थान के स्तंभ द्वारा अलग-अलग होते हैं, जो ब्लॉक के केंद्रों पर लंबवत संरेखित होते हैं।

आप एक पूर्ण कार्यक्रम, या एक फ़ंक्शन लिख सकते हैं।

इनपुट:

शब्दों की एक सूची, या यदि आप पसंद करते हैं - एक स्थान- या अन्य प्रतीक- सीमांकित स्ट्रिंग

आउटपुट:

उल्लिखित शब्दों के लिए ब्लॉकों का ASCII प्रतिनिधित्व। प्रमुख / अनुगामी व्हाट्सएप की अनुमति है।

परीक्षण के मामलों:

Input 1: ["code", "golf"] (or "code golf")
Output 1:

    cccccccccccc gggggggggggg
    cooooooooooc goooooooooog
    coddddddddoc gollllllllog
    codeeeeeedoc golfffffflog
    code    edoc golf    flog
    codeeeeeedoc golfffffflog
    coddddddddoc gollllllllog
    cooooooooooc goooooooooog
    cccccccccccc gggggggggggg

Input 2: ["I", "am", "just", "a", "man"]  (or "I am just a man")
Output 2: 

           jjjjjjjjjjjj
           juuuuuuuuuuj     mmmmmmmmm
    aaaaaa jussssssssuj     maaaaaaam
III ammmma justtttttsuj aaa mannnnnam
I I am  ma just    tsuj a a man   nam  
III ammmma justtttttsuj aaa mannnnnam
    aaaaaa jussssssssuj     maaaaaaam 
           juuuuuuuuuuj     mmmmmmmmm 
           jjjjjjjjjjjj

जीत मापदंड:

प्रत्येक भाषा में बाइट्स में सबसे छोटा कोड जीतता है। यदि आप अपने कोड और दृष्टिकोण की व्याख्या / व्याख्या करते हैं तो मैं बहुत सराहना करूंगा।


क्या हम मान सकते हैं कि कम से कम एक शब्द है?
पुरकाकूदरी

@ Pietu1998 हां, हमेशा कम से कम एक शब्द होना चाहिए
गैलेन इवानोव

1
@ केविन क्रूज़सेन ट्रांसपोज़?
गैलन इवानोव

जवाबों:


7

कैनवस , 22 20 बाइट्स

l *;±21*{;l└*e⟳} ]r⤢

यहाँ यह कोशिश करो!

स्पष्टीकरण:

{                 ]    map over the inputs
 l *                     array of length spaces - the canvas of the current word
    ;                    get the word back on top
     ±                   reverse it
      21*                repeat each character twice
         {      }        for each character
          ;l└              push the height of the item below (the canvas)
             *             repeat the character that many times vertically
              e            and encase the canvas in that char column
               ⟳           and rotate it clockwise for encasing the next time
                 ∙      push another space as the separator of words
                   r   center the words
                    ⤢  and transpose the final output (as everything was built vertically)

5

चारकोल , 35 बाइट्स

FA«≔LιθMθ↑Fθ«B⁻׳θ⊗κ⊕⊗⁻θκ§ικ↘»M⊕⊗θ→

इसे ऑनलाइन आज़माएं! लिंक कोड के वर्बोज़ संस्करण के लिए है। स्पष्टीकरण:

FA«

इनपुट सूची पर लूप करें।

≔Lιθ

वर्तमान शब्द की लंबाई प्राप्त करें।

Mθ↑

परिणामी रूपरेखा के ऊपरी बाएँ कोने में जाएँ।

Fθ«

प्रत्येक वर्ण के लिए एक बार लूप करें।

B⁻׳θ⊗κ⊕⊗⁻θκ§ικ

उचित ऊँचाई, चौड़ाई और वर्ण का एक बॉक्स बनाएँ।

↘»

अगले बॉक्स के ऊपरी बाएँ कोने में जाएँ।

M⊕⊗θ→

अगली रूपरेखा पर जाएं।


4

हास्केल , 188 183 174 171 167 बाइट्स

-9 -13 बाइट्स लाइकोनी के लिए धन्यवाद ।

e=[]:e
c#a=k c<$>k(c<$a!!0)a
k c s=c:s++[c]
f w=foldr(#)[p w]w
p=(' '<$)
s w=unlines.map unwords.foldr(zipWith(:))e$until(\a->all((p a>=).p)$f<$>w)(k=<<p.head)<$>f<$>w

इसे ऑनलाइन आज़माएं!


\a->and[p a>=p x|x<-f<$>w]हो सकता है \a->all((p a>=).p)$f<$>wऔर k c=(++[c]).(c:)हो सकता है k c s=c:s++[c]
लकोनी

3

पायथ, 34 33 बाइट्स

Jsm+;uCjR*2HG_.iddm\ dQjCm.[lJd;J

इसे ऑनलाइन आज़माएं।

अतिरिक्त व्हाट्सएप का एक पूरा गुच्छा बाहर निकालता है, लेकिन इसे चुनौती द्वारा अनुमति दी जाती है।

व्याख्या

  • m… इनपुट में Qप्रत्येक शब्द के लिए निम्नलिखित है :dQ

    • m\ dशब्द को मैप करता है x => " ", अनिवार्य [" ", ..., " "]रूप से सूची को उतने ही आइटम के साथ बनाता है जितना शब्द में अक्षर होते हैं।
    • .iddशब्द के अक्षरों को दो बार दोहराते हुए, शब्द को खुद से जोड़ता है। _इस स्ट्रिंग को उलट देता है। wordबन जाता है ddrrooww
    • uGरिक्त स्थान के साथ = के साथ शुरू होता है , और इसमें प्रत्येक अक्षर के साथ निम्नलिखित लागू होता है H:
      • *2H चरित्र को दो बार दोहराता है।
      • jR... पात्रों की जोड़ी के बीच Gमें प्रत्येक स्ट्रिंग रखता है G
      • Cस्वैप पंक्ति और स्तंभ। जब इन तीन चरणों को एक ही वर्ण के साथ दो बार किया जाता है H, तो यह Gउस वर्ण की रेखाओं को रेखांकित करता है ।
    • अब हमारे पास उल्लिखित शब्द के लिए कॉलम हैं d+;एक अंतरिक्ष स्तंभ प्रस्तुत करता है।
  • sप्रत्येक शब्द के लिए कॉलम की सरणी को समतल करता है, और Jइसे चर में बचाता है J
  • m... Jआउटपुट के प्रत्येक कॉलम के लिए निम्न कार्य करता है:
    • .[lJd;स्तंभों के दोनों किनारों को रिक्त स्थान के साथ पैड करें ताकि स्तंभ की लंबाई स्तंभों की संख्या के बराबर हो। स्तंभों को लंबवत रूप से संरेखित करने के लिए यह हमेशा पर्याप्त पैडिंग है।
  • Cस्तंभों को पंक्तियों में बदल देता है और jपंक्तियों को नए सिरे से जोड़ता है।

वैकल्पिक समाधान, 33 बाइट्स

j.tsm.[L\ l+dsQ+;uCjR*2HG_.iddm\ 

इसे ऑनलाइन आज़माएं।

ध्यान दें कि एक अनुगामी स्थान है। ज्यादातर समान एल्गोरिथ्म, शीर्ष पर केवल पैड कॉलम को छोड़कर और फिर अंतरिक्ष भरने के साथ स्थानांतरित करता है।


3

आर , 189 बाइट्स

function(x,S=32,`+`=rbind,`*`=cbind)cat(intToUtf8(Reduce(`+`,Map(function(s,K=utf8ToInt(s),o=S-!K){for(i in rev(K))o=i+i*o*i+i
for(j in(0:(max(nchar(x))-nchar(s)))[-1])o=S*o*S
o+S},x))+10))

इसे ऑनलाइन आज़माएं!

DigEmAll और चैट में खुद के बीच एक सहयोग ।

function(x){
 S <- 32			# space
 `+` <- rbind			# alias for rbind
 `*` <- cbind			# alias for cbind
 outlineWord <- function(s){	# function to construct the outline for each word
  chars <- utf8ToInt(s)		# convert to code points
  output <- S - !chars		# replace each char with 32 (space)
  for(i in rev(chars))
   o <- i + i * o * i + i	# o <- rbind(i,cbind(i,o,i),i)
  for(j in(0:(max(nchar(x))-nchar(s)))[-1])
   o <- S * o * S		# pad with spaces
   o + S}			# return with an additional row of spaces between words
 outlines <- Map(outlineWord,x)	# apply outlineWord to each element of x
 outlines <- Reduce(`+`,outlines)# reduce by rbind
 outlines <- outlines+10	# add row of newlines
 cat(intToUtf8(outlines))	# convert back to strings and print
}

187 एक स्पष्ट उर्फ ​​के साथ
जे। डो।

@ जे। यह सामुदायिक विकी है इसलिए इसे संपादित करने के लिए स्वतंत्र महसूस करता हूं :-)
Giuseppe



1

05AB1E , 46 बाइट्स

εg©;ò<Uyη央∍«®>∍}y𫩪®Xиª˜».º.∊}¶«».C.B€SζJ»

इसके बारे में बहुत खुश नहीं है, लेकिन मुझे खुशी है कि यह काम कर रहा है।

इसे ऑनलाइन आज़माएं या सभी परीक्षण मामलों को सत्यापित करें

स्पष्टीकरण:

ε                             # Map `y` over the (implicit) input-list
 g                            #  Take the length of the current item
  ©                           #  Store it in the register (without popping)
   ;                          #  Halve it
    ò                         #  Ceil and cast to integer at the same time
     <                        #  Decrease it by 1
      U                       #  Pop and store it in variable `X`
 yη                           #  Take the prefixes of the current string `y`
   ε       }                  #  Map over these prefixes:
    ¤                         #   Take the last character of the string
     ®×                       #   Increase it to a size equal to the length from the register
       «                      #   Append it to the current prefix
        ®>                    #   Take the length from the register, and add 1
                             #   Shorten the string to that size
 y                            #  Push the string `y` again
  ð«                          #  Append a space
    ©                         #  Store it in the register (without popping)
     ª                        #  Append it at the end of the list of modified prefixes
      ®                       #  Push the string with space from the register again
       Xи                     #  Repeat it `X` amount of times
         ª                    #  Append them to the list
          ˜                   #  Flatten to remove the empty appended list if `X` was 0
           »                  #  Join by newlines
            .º.∊              #  Intersect mirror both horizontally and vertically
                }             # Close outer map
                 ¶«           # Append a newline after each (for the space delimiters)
                   »          # Join everything by newlines
                    .C        # Centralize it horizontally
                              # (too bad a centralize vertically isn't available..)
                      .B      # Split on newlines again
                        S    # Convert each line to a list of characters
                          ζ   # Zip, swapping rows/columns (with space filler by default)
                           J  # Join the loose characters of every line to a string again
                            » # Join the lines by newlines (and output implicitly)
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.