ASCIIアーキテクト


15

高価な建築プログラムにお金を払いたくないので、自分でロールバックすることにします。ASCIIを使用して建物を設計することにしました。プログラムは、特定の方法でフォーマットされた単一の文字列を受け取り、プログラムは建物を出力します。

入力

入力は1行の文字で構成されます。文字のみを含むと想定できますa-j、数字1-9、記号-などを+

出力の説明

各文字a-jについて、プログラムは次のように垂直線を出力します。これを列と呼びます。

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

たとえば、入力abcdefgfedefghgfedcは次を出力します。

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

文字の前に正の整数を付けると、列の下nn空白文字が追加されます。これをオフセットと呼びます。たとえば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つの列の間で使用される演算子は、別々の列ではなく、同じ列で互いの上に積み重ねる必要があることを示します。たとえば、入力「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

そして結果の出力:

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

(マリオのはずだったが、あまり良くなかった...)

仕様がまだ明確でない場合は、ゴルフ以外の実装があります、Python 2.7で書かれたがあります。それを実行し、実験して、仕様がどのように機能するかを感じてください。また、私のプログラミングスキルを笑うこともできます。

これはコードゴルフなので、最短のエントリーが勝ちです。不明な場合はコメントで質問してください。


3つ以上のタワーの積み重ねは有効ですか?あなたの例の1つに「2c + b + -2c」がありますが、それがあなたがそれらを積み重ねた方法であるかどうかはわかりません。
AndoDaan

1
@AndoDaan Towersは、+を使用して無限にスタックできます。たとえば、a+a+a+a+a5つのプラス記号を重ねて出力します。
アブサン14

1
これはcodegolf.stackexchange.com/questions/18967/landscapesの複製ではありませんか?
ハワード14

@Howard Huh、あなたは正しいです、これらは驚くほど似ています(唯一の追加はタワーを切断し、タワーを積み重ねることができることです)。
マーティンエンダー14

@Howard Huh。タイトルを入力するときに表示される類似の質問には表示されませんでした。ただし、空白の実装は少し異なります。投稿に重複としてフラグを付け、MODがどう思うかを確認します。
アブサン14

回答:


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:?\ }*''}。しかし、おそらく転置なしではそれほど楽しくはありません。
ベクトル化さ

@bitpwnerありがとう、これを後で見て、テストします。
マーティン・エンダー

2

コブラ-473

私はコブラがこれらの1つに勝つとは思わない:/

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

素敵でコメントあり:

編集:これは、Rubyソリューションに似ているように見えます。偉大な心は同じように考える?

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

特にない。一度だけ関数の大量の名前を変更するのは楽しかったです。未使用のコードは後で編集します。

ここで試してみてください。サンプル出力:

SampleOutput


1

PowerShellの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

驚くばかり!ありがとう。
mazzy

0

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