ASCII वास्तुकार


15

आप महंगे आर्किटेक्चरल प्रोग्राम के लिए पैसे नहीं देना चाहते हैं, इसलिए आप अपना रोल खुद तय करें। आप अपने भवनों को डिजाइन करने के लिए ASCII का उपयोग करने का निर्णय लेते हैं। आपका कार्यक्रम एक विशिष्ट तरीके से स्वरूपित एकल स्ट्रिंग में होगा, और कार्यक्रम भवन का उत्पादन करेगा।

इनपुट

इनपुट में वर्णों की एक पंक्ति होती है। यह केवल अक्षर माना जा सकता है a-j, संख्या 1-9और प्रतीकों -और +

आउटपुट विवरण

प्रत्येक अक्षर के लिए a-j, कार्यक्रम निम्नानुसार एक ऊर्ध्वाधर रेखा का उत्पादन करेगा। हम इसे एक कॉलम कहेंगे।

         .
        ..
       ...
      ****
     *****
    ******
   -------
  --------
 +++++++++
++++++++++
abcdefghij

उदाहरण के लिए, इनपुट abcdefgfedefghgfedcआउटपुट:

             .
      *     ***
     ***   *****
    ***** *******
   ---------------
  -----------------
 ++++++++++++++++++
+++++++++++++++++++

एक पत्र को एक पूर्णांक के साथ पूर्वनिर्मित किया जा सकता है n, जो nस्तंभ के नीचे व्हाट्सएप वर्ण जोड़ देगा । हम इसे एक ऑफसेट कहेंगे। उदाहरण के लिए, Sव्हाट्सएप को नोट करने के लिए, इनपुट 3b2b3bआउटपुट देगा:

+ +
+++
S+S
SSS
SSS

एक पत्र भी एक नकारात्मक पूर्णांक के साथ उपसर्ग किया जा सकता है -m, जो स्तंभ के निचले गैर-व्हाट्सएप वर्णों को हटा देगा (उन्हें व्हाट्सएप से प्रतिस्थापित नहीं करें, उन्हें पूरी तरह से हटा दें)। हम इसे एक टुकड़ा कहेंगे। उदाहरण के लिए, इनपुट आउटपुट:m -1j-2j-3j-4j-5j-6j-7j-8j

.
..
...
*...
**...
***...
-***...
--***...
+--***..

एक ऑफसेट और एक स्लाइस को एक ही लाइन पर लागू किया जा सकता है, लेकिन ऑफसेट को पहले जाना चाहिए। दूसरे शब्दों में, पत्र के साथ उपसर्ग किया जा सकता है n-m, जहां nऑफ़सेट mका आकार है , और स्लाइस का आकार है। उदाहरण के लिए, Sव्हॉट्सएप को नोट करने के लिए, इनपुट '2-4j' आउटपुट करेगा:

.
.
.
*
*
*
S
S

अंत में, +दो स्तंभों के बीच उपयोग किया जाने वाला ऑपरेटर इंगित करता है कि उन्हें अलग-अलग स्तंभों के बजाय एक ही स्तंभ में एक दूसरे के ऊपर ढेर किया जाना चाहिए। उदाहरण के लिए, इनपुट '2-4ja' आउटपुट:

.
.
.
*
*
*
S
S+

जबकि इनपुट 2-4j+aआउटपुट:

+
.
.
.
*
*
*
S
S

यहाँ एक नमूना इनपुट है:

abiehef+ehfhabc

और परिणामी आउटपुट:

      *
      -
  .   -
  . . +. .
  * * +* *
  * * ****
  ********
  --------
  --------  -
 +++++++++ ++
+++++++++++++

किसी तरह का एक पुराना नष्ट महल टॉवर जैसा दिखता है।

यहाँ एक और नमूना इनपुट है:

6b5b+a6b1-2d+3-4f1-2d+-2c+2-4f+1-2d+-2c2-2d+1-4g+1-2c+b+-2c+-4e2-7j+-4g+d+-2c+-4f2-7j+-5h+b+-2c+a+-3f2-7j+-7i+-4e+b+b+a+-4f2-7i+a+-7h+-4f+b+b+a+-4f2-7j+-7h+-4f+a+-7h+a+-7i+-4f2-7j+-7i+-6h+a+-7i+b+-4e3-7i+a+-7h+-4e+a+-7h+b+1-7h3-7j+1-4f+-7h+b+-4f+a3-7j+2-4f+a+-4f+b3-2d+-2d+3-4g+b3-2d+-2d+-2c

और परिणामी आउटपुट:

      ****** +++
     ******+.*++
     ---++.+ ***
    -+-+++..++**
    -+--+++.+++*
    --++++.+..*
      +++++.+**
+++****.******  -
+++*****.**..  --
 +   ***....+..--
      ...+.....--
    --.........--
   ---......
   --

(यह मारियो होना चाहिए था, लेकिन बहुत अच्छा नहीं निकला ...)

यदि विनिर्देश अभी भी स्पष्ट नहीं है, तो मेरे पास पायथन 2.7 में लिखा गया गैर-गोल्फ कार्यान्वयन है। आप इसे चला सकते हैं और विनिर्देश कैसे काम करता है, इसके बारे में जानने के लिए प्रयोग कर सकते हैं। तुम भी मेरे प्रोग्रामिंग कौशल पर हँसने के लिए चुन सकते हैं।

यह कोड-गोल्फ है, इसलिए सबसे छोटी प्रविष्टि जीतती है। अस्पष्ट होने पर टिप्पणियों में प्रश्न पूछें।


दो से अधिक टावरों का स्टैकिंग वैध है? मुझे आपके उदाहरणों में "2c + b + -2c" दिखाई देता है, लेकिन मैं यह नहीं बता सकता कि यदि आपने उन्हें कैसे स्टैक्ड किया है।
21o17 पर AndoDaan

1
@AndoDaan टावर्स का उपयोग करके असीम रूप से स्टैक किया जा सकता है। उदाहरण के लिए a+a+a+a+a, एक दूसरे के शीर्ष पर पाँच से अधिक चिन्ह का उत्पादन होगा।
अनुपस्थित

1
क्या यह codegolf.stackexchange.com/questions/18967/landscapes का डुप्लिकेट नहीं है ?
हावर्ड

@ हॉवर्ड हुह, आप सही कह रहे हैं, ये आश्चर्यजनक रूप से समान हैं (टॉवर को काटने और टावरों को ढेर करने में सक्षम होने के लिए एकमात्र जोड़)।
मार्टिन एंडर

@ हावर्ड हुह। जब आप अपने शीर्षक में टाइप करते हैं तो यह उन अज्ञात प्रश्नों पर दिखाई नहीं देता है। व्हाट्सएप का कार्यान्वयन हालांकि थोड़ा अलग है। मैं अपनी पोस्ट को एक डुप्लिकेट के रूप में चिह्नित करूंगा और देखूंगा कि मॉड्स क्या सोचते हैं।
अनुपम

जवाबों:


10

रूबी, 223 214 बाइट्स

g=$*[0].split(/(?<=[a-j])(?!\+)/).map{|r|r.scan(/(\d*)(-\d+)?([a-j])/).map{|a,b,c|' '*a.to_i+'++--***...'[-b.to_i..c.ord-97]}*''}
puts g.map{|s|s.ljust(g.map(&:size).max).chars.reverse}.transpose.map(&:join).join$/

वह मजेदार था। :)

हालांकि यह काफी स्पष्ट होना चाहिए, मैंने इन चुनौतियों को करने के लिए एक नया तरीका खोजा जहां स्तंभों से तार का निर्माण किया गया है: बस उन्हें पंक्तियों में करें, और सब कुछ में शामिल होने से पहले वर्णों के सरणी को स्थानांतरित करें।

g=$*[0].split(/(?<=[a-j])(?!\+)/)               # Split into columns.
       .map{|r|                                 # For each column
            r.scan(/(\d*)(-\d+)?([a-j])/)       # Split into components.
             .map{|a,b,c|                       # For each component
                ' '*a.to_i+                     # Prepend spaces if any.
                '++--***...'[-b.to_i..c.ord-97] # Select the appropriate slice of the tower.
            }*''                                # Join all components together.
        }
puts g.map{|s|                                  # For each column
            s.ljust(g.map(&:size).max)          # Pad with spaces on the right such that. 
                                                # all columns are the same height.
            .chars.reverse                      # Turn into character array and reverse.
      }
      .transpose                                # Mirror in the main diagonal.
      .map(&:join)                              # Join lines.
      .join$/                                   # Join columns.

अंतिम पंक्ति के विभिन्न शैलियों की कोशिश कर रहा था और साथ आया था puts (0..z=g.map(&:size).max-1).map{|i|g.map{|y|(v=y[z-i])?v:?\ }*''}:। लेकिन ट्रांसजेंड के बिना शायद इतना मज़ा नहीं आता।
vectorized

@bitpwner धन्यवाद, मुझे बाद में इस पर एक नज़र और परीक्षण करना होगा।
मार्टिन एंडर 10

2

कोबरा - 473

मुझे नहीं लगता कि कोबरा कभी इनमें से एक जीतने जा रही है: /

use System.Text.RegularExpressions
class P
    def main
        r=Regex.matches(Console.readLine,r'(?<=^|[a-j])(([^a-j]*[a-j])+?)(?=[^+]|$)')
        z,l=0String[](r.count)
        for m in r.count,for n in'[r[m]]'.split('+'),l[m]+=' '.repeat(int.parse('0[Regex.match(n,r'(?<!-)\d+')]'))+'++--***...'[int.parse('0[Regex.match(n,r'(?<=-)\d+')]'):' abcdefghij'.indexOf(n[-1:])]
        for y in l,if y.length>z,z=y.length
        for x in-z+1:1
            for y in l,Console.write(if(-x<y.length,y[-x],' '))
            print

सभी अच्छे और टिप्पणी:

संपादित करें: बस एहसास हुआ कि यह संदिग्ध रूप से रूबी समाधान के समान है। बड़े मन वाले ऐसा सोचते हैं?

use System.Text.RegularExpressions
class P
    def main
        r=Regex.matches(Console.readLine,r'(?<=^|[a-j])(([^a-j]*[a-j])+?)(?=[^+]|$)')
        # Split into columns
        z,l=0,String[](r.count)
        # Assign the column-array
        for m in r.count
        # Loop through columns
            for n in'[r[m]]'.split('+')
            # Loop through individual letter instructions
            # - within columns
                l[m]+=
                # Add characters to the last column
                    ' '.repeat(int.parse('0[Regex.match(n,r'(?<!-)\d+')]'))+
                    # Any spaces, plus
                    '++--***...'[:' abcdefghij'.indexOf(n[-1:])]
                    # The default column string
                        [int.parse('0[Regex.match(n,r'(?<=-)\d+')]'):]
                        # Sliced to the right length
        for y in l,if y.length>z,z=y.length
        # Determine the maximum length of any column
        for x in-z+1:1
            for y in l
            # Loop through columns so that they rotate to the left
                Console.write(if(-x<y.length,y[-x],' '))
                # Write the character in the current position
            print
            # Insert newlines

2

लुआ - 451

a=arg[1]j='++--***...'I=io.write M=string.match U=string.sub T=table.insert n=''y=0 t={}m=0 for i in a:gmatch('[%-%d]*[a-j]%+?')do b=M(i,'-(%d)')b=b or 0 s=M(U(i,1,1),'%d')s=s or 0 n=n..(' '):rep(s)..U(U(j,1,M(U(i,-2),'[a-j]'):byte()-96),1+b,-1)if U(i,-1,-1)~="+"then T(t,n)m=m<#n and #n or m n=""y=y+1 end end T(t,n)n=''for k,v in pairs(t)do n=#v<m and n..v..(' '):rep(m-#v)or n..v end for i=m,1,-1 do for k=0,m*y-1,m do I(U(n,i+k,i+k))end I'\n'end

कुछ खास नहीं। हालांकि एक बार के लिए फ़ंक्शन के बट-लोड का नाम बदलने में मज़ा आया। मैं बाद में ungolfed कोड संपादित करूँगा।

इसे यहाँ आज़माएँ। नमूना आउटपुट:

SampleOutput


1

पॉवरशेल , 214 212 209 206 200 बाइट्स

-3 बाइट्स धन्यवाद @Veskah

switch -r($args-split'(-?.)'){\+{$c=1}\d{sv('ps'[0-gt$_])$_}[a-j]{if(!$c){$t+=,''}$t[-1]+=' '*$p+-join'++--***...'[-$s..($_[0]-97)];$c=$p=$s=0}}($t|% Le*|sort)[-1]..1|%{-join($t|% *ht $_|% ch*($_-1))}

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

कम गोल्फ वाला संस्करण:

# make table with lines instead columns
switch -r($args-split'(-?.)'){
    \+ {$c=1}
    \d {set-variable ('ps'[0-gt$_]) $_}
    [a-j] {
        if(!$c){$t+=,''}
        $t[-1]+=' '*$p+-join'++--***...'[-$s..($_[0]-97)]
        $c=$p=$s=0
    }
}
# transpose
($t|% Length|sort)[-1]..1|%{
    -join($t|% padRight $_|% chars($_-1))
}

1
रेगेक्स को (-?.)भी काम करना चाहिए
Veskah

बहुत बढ़िया! धन्यवाद।
माज़ी

0

पायथन 3, 268 बाइट्स

import re
q,t=[(p,' '*int(o or 0)+'++--***...'[-int(s or 0):ord(l)-96])for p,o,s,l in re.findall('(\+?)(\d?)(-\d)?(.)',input())],[]
while q:p,s=q.pop(0);t+=[t.pop()+s if p else s]
t=[*zip(*[[*c.ljust(max(map(len,t)))]for c in t])][::-1]
for l in t:print(*l,sep='')

अधिकांशत: अपुष्ट:

# import the regex module
import re

# array to store initial input
q = []
# array to store translated output
t = []

# split string from stdin into column groups, like: ('plus or blank', 'offset or blank', 'slice or blank', 'letter')
# ex: 6b1-2d+a would become:
# [('','6','','b'), ('', '1', '-2', 'd'), ('+', '', '', 'a')]
i = re.findall('(\+?)(\d?)(-\d)?(.)',input())

# iterate through the groups returned by the regex
for p,o,s,l in i:
    # create offset string
    # int() cannot parse '', but empty strings are falsey,
    # so (o or 0) is equivalent to 'parse the string as an int, or return 0 if it is empty'
    offset = ' ' * int(o or 0)

    # get the starting point of the slice
    # since the regex returns the minus, it must be negated after converting the string to an int
    # as before, (s or 0) ensures that the slice is converted to an int properly
    start = -int(s or 0)
    # since 'a' is ordinal 97, this ensures that the end position will be 1-9
    end = ord(l) - 96
    # slice the largest possible column string with the calculated start and end positions
    a = '++--***...'[start:end]
    # add the space offset
    a = offset + a
    # add the plus sting and the column string to the array
    q.append( (p, a) )

# while q is not empty
while q:
    # remove the first item from the list and separate it into a plus variable and a column string
    p, s = q.pop(0)

    # if p is not blank, it is a '+'
    # if p is truthy, remove the last item added and add s to it
    # otherwise just return s
    # append the resulting item to the ongoing list
    t += [t.pop()+s if p else s]

temp = []
for c in t:
    # call len() on all items in t, then return the maximum length
    m = max(map(len, t))
    # left justify c by adding spaces to the right, up to m total characters
    c = c.ljust(m)
    # unpack c into a list
    # this is equivalent to list(c), but shorter
    c = [*c]
    # add the list of characters to the array
    temp.append(c)

t = temp

# t is currently a list of rows, and needs to be rotated so that it displays correctly
# input: 'abcdefghij'
# before:
#
# +
# ++
# ++-
# ++--
# ++--*
# ++--**
# ++--***
# ++--***.
# ++--***..
# ++--***...
#
# after:
#
#  ++++++++++
#   +++++++++
#    --------
#     -------
#      ******
#       *****
#        ****
#         ...
#          ..
#           .
# 
t = [*zip(*t)]
# t is currently upside down, reverse the list
t = t[::-1]

# for each line (currently a list of characters)
for l in t:
    # unpack the list into print as arguments, do not add a space between arguments
    print(*l,sep='')
हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.