สร้างบันได ASCII


28

ได้รับการป้อนข้อมูลของจำนวนเต็มnและม.เอาท์พุทบันได ASCII ของความยาว nและขนาดเมตร

นี่คือบันได ASCII ของความยาว 3 และขนาด 3:

o---o
|   |
|   |
|   |
+---+
|   |
|   |
|   |
+---+
|   |
|   |
|   |
o---o

นี่คือบันได ASCII ที่มีความยาว 5 และขนาด 1:

o-o
| |
+-+
| |
+-+
| |
+-+
| |
+-+
| |
o-o

นี่คือบันได ASCII ที่มีความยาว 2 และขนาด 5:

o-----o
|     |
|     |
|     |
|     |
|     |
+-----+
|     |
|     |
|     |
|     |
|     |
o-----o

จะเฉพาะเจาะจง:

  • ความยาว ( n ) หมายถึงจำนวนสี่เหลี่ยมที่บันไดสร้างขึ้น

  • ขนาด ( m ) หมายถึงความกว้างและความสูงของการตกแต่งภายในของ - นั่นคือไม่นับ "เส้นขอบ" - แต่ละตาราง

  • แต่ละตารางประกอบด้วยพื้นที่ภายในเต็มไปด้วยช่องว่างล้อมรอบด้วย -s ที่ด้านบนและด้านล่าง|s ด้านซ้ายและขวาและ+s ที่ทั้งสี่มุม

  • เส้นขอบระหว่างสแควร์สรวมเข้าด้วยกันดังนั้นสองบรรทัดในหนึ่งแถวที่ +--...--+รวมกันเป็นหนึ่ง

  • oมุมบันไดทั้งหมดจะถูกแทนที่ด้วยตัวอักษร

  • คุณสามารถเลือกที่จะออกบรรทัดใหม่ต่อท้าย

ความยาวของบันได ( n ) จะเป็น≥ 2 เสมอและขนาด ( m ) จะเป็น≥ 1 เสมอ

อินพุตสามารถใช้เป็นสตริง whitespace- / คั่นด้วยเครื่องหมายคอมม่าอาร์เรย์ / list / etc. หรือสองฟังก์ชัน / command line / etc ข้อโต้แย้ง การโต้เถียงสามารถทำได้ในลำดับที่สะดวกที่สุด / นักกอล์ฟที่สุด

เนื่องจากนี่คือรหัสที่สั้นที่สุดเป็นไบต์จะเป็นผู้ชนะ

เคล็ดลับ: ตัวอย่างข้างต้นสามารถใช้เป็นกรณีทดสอบได้


เราจะต้องใช้ความยาวก่อนจากนั้นขนาด?
RK

@RK คุณสามารถรับได้ตามความสะดวก
Doorknob

1
จะมีการขึ้นบรรทัดใหม่นำหรือไม่
Conor O'Brien

1
@ CᴏɴᴏʀO'Bʀɪᴇɴเอ่อ ... ฉันจะไปโดยไม่ทำอย่างนั้น
Doorknob

1
Okay: P มันคุ้มค่ากับการยิง
Conor O'Brien

คำตอบ:


4

Pyth, 34 ไบต์

.NjjNm*QTvz*2YjC:M++J"+|o"m"- -"QJ

ชุดทดสอบ

รับอาร์กิวเมนต์ขึ้นบรรทัดใหม่คั่นบน STDIN

ใช้ฟังก์ชั่นตัวช่วย:ซึ่งสร้างสตริงแนวตั้งแต่ละประเภทจากสามตัวอักษรจากนั้นทำซ้ำตามความจำเป็นสลับตำแหน่งและเข้าร่วมในการขึ้นบรรทัดใหม่


11

ทับทิม, 71

->m,n{h=0;(?o+?+*(n-1)+?o).chars{|c|puts [?|+' '*m+?|]*h,c+?-*m+c;h=m}}

ungolfed ในโปรแกรมทดสอบ

f=->m,n{
  h=0                             #The number of | above the 1st rung is 0
  (?o+?+*(n-1)+?o).chars{|c|      #Make a string of all the rung ends o++...++o and iterate through it
    puts [?|+' '*m+?|]*h,         #draw h vertical segments |  ...  |
      c+?-*m+c                    #and a rung with the correct ends
    h=m                           #The number of | above all rungs except the 1st is m
  }
}


f[gets.to_i,gets.to_i]

ดูเหมือนจะมีปัญหาเล็กน้อยกับรุ่นแข็งแรงเล่นกอล์ฟที่จำเป็น;หลังจากพื้นที่จำเป็นหลังจากที่h=0 putsแต่คุณคะแนนเติบโตเพียง 1 putsตัวละครที่มีพื้นที่พิเศษก่อน
จัดการ

@ การจัดการโอ๊ะขอบคุณคงที่ ฉันไม่รู้ว่าเกิดอะไรขึ้นฉันต้องตีกอล์ฟและไม่ทำงานหลังจากนั้น
เลเวลริเวอร์เซนต์

9

CJam, 43 42 ไบต์

ฉันไม่ได้ประณามคะแนน แต่ฉันไม่ใช่เดนนิสใช่มั้ย

q~:Z;'-'o{[\Z*1$N]}:X~['-_'+X\'|XZ*]@*1>1$

อินพุตคือรายการที่คั่นด้วยช่องว่าง 2 รายการ ความยาวก่อน

2 3
o---o
|   |
|   |
|   |
+---+
|   |
|   |
|   |
o---o

คำอธิบาย

q~:Z;'-'o{[\Z*1$N]}:X~['-_'+X\'|XZ*]@*1>1$
q~                                         e# read input
  :Z;                                      e# Record the size in Z and discard
     '-'o{[\Z*1$N]}:X~                     e# Create the initial line (and final). also creates a shorcut to do this later
           \                               e# Capture two arguments
            Z*                             e# The separator is repeated size times
              1$                           e# Repeat the first argument
                N                          e# Add newline
                                           e# X is a function to create line in a ladder
                      ['-_'+X\'|XZ*]       e# Design the repeating part
                                    @*     e# Repeat the pattern n times
                                      1>   e# Discard the initial
                                        1$ e# Since the final line is same than the initial, we just write it.
                                           e# Implicit printing

1
ฉันชอบที่คุณพูดมันเป็นคำถาม "ฉันไม่ใช่เดนนิส ... ใช่มั้ย"
undergroundmonorail

7

JavaScript (ES6), 89

... ทำซ้ำทำซ้ำทำซ้ำ ...

(n,m,R=x=>x.repeat(m),b=R(`|${R(' ')}|
`),d=`o${c=R('-')}o
`)=>d+R(b+`+${c}+
`,m=n-1)+b+d

ทดสอบ

F=(n,m,R=x=>x.repeat(m),b=R(`|${R(' ')}|
`),d=`o${c=R('-')}o
`)=>d+R(b+`+${c}+
`,m=n-1)+b+d

// Less golfed
U=(n,m)=>
{
  var R=x=>x.repeat(m),
      a=R(' '),
      b=R(`|${a}|\n`);
      c=R('-'),
      d=`o${c}o\n`;
  m=n-1;
  return d+R(b+`+${c}+\n`)+b+d
}

function test() {
  var i=I.value.match(/\d+/g)
  if (i) O.textContent=F(+i[0],+i[1])
  console.log(i,I.value)
}  
 
test()
N,M: <input id=I value="3,5" oninput=test()>
<pre id=O></pre>


ฉันไม่รู้ว่าdocument.getElementById('elem').จะถูกแทนที่ด้วยelem.! +1 สำหรับสิ่งนี้ แต่โปรดคุณช่วยชี้ให้เห็นเอกสารบางอย่างเกี่ยวกับเรื่องนี้
F. Hauri

2
@ F.Hauri มันทำงานได้ในเกือบทุกเบราว์เซอร์ แต่ควรหลีกเลี่ยง (ยกเว้นเมื่อเข้ารหัสเพื่อความสนุกสนาน) ข้อมูลและลิงก์stackoverflow.com/questions/3434278/…
edc65

6

C #, 1412 ไบต์

... ความพยายามในการใช้ CodeGolf ครั้งแรกของฉันไม่น่าจะชนะ แต่ก็ใช้งานได้เช่นกัน

using System;

namespace Ascii_Ladders
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = 0;
            int m = 0;

            Console.Write("Please enter Height: ");
            n = int.Parse(Console.ReadLine());
            Console.Write("Please Enter Width: ");
            m = int.Parse(Console.ReadLine());

            Console.Write("o");
            for (int i = 0; i < m; i++)
            {
                Console.Write("-");
            }
            Console.WriteLine("o");

            for (int k = 0; k < n; k++)
            {
                for (int i = 0; i < m; i++)
                {
                    Console.Write("|");
                    for (int j = 0; j < m; j++)
                    {
                        Console.Write(" ");
                    }
                    Console.WriteLine("|");
                }
                if (k != n - 1)
                {
                    Console.Write("+");
                    for (int i = 0; i < m; i++)
                    {
                        Console.Write("-");
                    }
                    Console.WriteLine("+");
                }
            }

            Console.Write("o");
            for (int i = 0; i < m; i++)
            {
                 Console.Write("-");
            }
            Console.WriteLine("o");

            Console.ReadKey();
        }
    }
}

9
ยินดีต้อนรับสู่ Programming Puzzles & Code Golf! คุณมีจำนวนมากของช่องว่างในรหัสของคุณที่คุณสามารถลบที่จะลดลงรหัสของคุณถ้าคุณต้องการความช่วยเหลือเพิ่มเติมกอล์ฟรหัสของคุณคุณสามารถตรวจสอบเคล็ดลับสำหรับการเล่นกอล์ฟใน C #
Downgoat

ฉันเห็นด้วยกับ @ Doᴡɴɢᴏᴀᴛที่นี่ ฉันสามารถเล่นกอล์ฟด้วยความเร็วเพียง533 ไบต์ แต่มันอาจจะดีกว่า (คำเตือน: ฉันไม่ได้เขียนโปรแกรมใน C #.)
user48538

ฉันได้มันลงไปที่ 314 ด้วยusing System;class P{static int m;static void Main(){int n = int.Parse(Console.ReadLine());m = int.Parse(Console.ReadLine());M('o','-');for(int k=0;k<n;k++){for(int i=0;i<m;i++){M('|',' ');}if(k!=n-1){M('+','-');}}M('o','-');Console.ReadKey();}static void M(char x,char y){Console.WriteLine(x+new string(y,m)+x);}}
RedLaser

3
พลาดช่องว่างเล็กน้อยไปแล้ว 310 กับusing System;class P{static int m;static void Main(){int n=int.Parse(Console.ReadLine());m=int.Parse(Console.ReadLine());M('o','-');for(int k=0;k<n;k++){for(int i=0;i<m;i++){M('|',' ');}if(k!=n-1){M('+','-');}}M('o','-');Console.ReadKey();}static void M(char x,char y){Console.WriteLine(x+new string(y,m)+x);}}
RedLaser

2
ลงไปที่ 270 using C=System.Console;class P{static void Main(){int i,k,n=int.Parse(C.ReadLine()),m=int.Parse(C.ReadLine());System.Action<char,char> M=(x,y)=>C.WriteLine(x+new string(y,m)+x);M('o','-');for(k=0;k<n;k++){for(i=0;i<m;i++){M('|',' ');}if(k<n-1){M('+','-');}}M('o','-');}}โดยไม่มีการเปลี่ยนแปลงในแนวทางที่ใช้: มีความเป็นไปได้มากกว่าที่นี่ แต่เพียงเปลี่ยนวิธีการทำสิ่งต่าง ๆ เล็กน้อย
Joey

6

Julia, 87 ไบต์

f(n,m)=(g(x)=(b=x[1:1])x[2:2]^m*b*"\n";(t=g("o-"))join([g("| ")^m for i=1:n],g("+-"))t)

นี่คือฟังก์ชั่นที่รับจำนวนเต็มสองจำนวนและส่งคืนสตริง

Ungolfed:

function f(n::Int, m::Int)
    # Create a function g that takes a string of two characters and
    # constructs a line consisting of the first character, m of the
    # second, and the first again, followed by a newline.
    g(x) = (b = x[1:1]) * x[2:2]^m * b * "\n"

    # Assign t to be the top and bottom lines. Construct an array
    # of length n where each element is a string containing the
    # length-m segment of the interior. Join the array with the
    # ladder rung line. Concatenate all of this and return.
    return (t = g("o-")) * join([g("| ")^m for i = 1:n], g("+-")) * t
end

5

pb - 147 ไบต์

^t[B]>>[B]vw[T!0]{b[43]<[X]b[43]>w[B=0]{b[45]>}v[X-1]w[B=0]{b[124]^}v[X]t[T-1]}t[111]b[T]<w[X!0]{b[45]<}b[T]w[Y!0]{w[B!0]{^}b[124]^}b[T]^>>[B]vb[T]

นี่คือความท้าทายที่ pb ควรจะทำได้ดี การวาดภาพอย่างง่ายพร้อมตัวละครเป็นสิ่งที่ pb ได้รับการออกแบบมาอย่างดี อนิจจามันเป็นเพียงถ้อยคำที่ฉันเดาได้

ใช้ความยาวอินพุตก่อนตามด้วยขนาด รับอินพุตในรูปแบบของค่าไบต์ตัวอย่างเช่น:python -c 'print(chr(5) + chr(7))' | ./pbi.py ladder.pb

ดูภาพเคลื่อนไหวสนุก!

ด้วยความคิดเห็น:

^t[B]            # Save length to T
>>[B]v           # Go to X=size+1, Y=0

w[T!0]{          # While T is not 0:
    b[43]            # Write a '+'
    <[X]b[43]        # Write a '+' on the left side as well
    >w[B=0]{b[45]>}  # Travel back to the right '+', writing '-' on the way
    v[X-1]           # Go down by X-1 (== size)
    w[B=0]{b[124]^}  # Travel back up to the '+', writing '|' on the way
    v[X]             # Go down by X (== size + 1, location of next '+')
    t[T-1]           # Decerement T
}

t[111]           # Save 'o' to T (it's used 4 times so putting it
                 # in a variable saves bytes)

b[T]             # Write an 'o' (bottom right)

<w[X!0]{         # While not on X=0:
    b[45]<           # Travel left, writing '-' on the way
}

b[T]             # Write an 'o' (bottom left)

w[Y!0]{          # While not on Y=0:
    w[B!0]{^}        # Skip nonempty spaces
    b[124]           # Write a '|'
    ^                # Travel up
}

b[T]             # Write an 'o' (top left, replaces existing '+')

^>>[B]v          # Go back to where the size is saved and go to X=size+1, Y=0

b[T]             # Write an 'o' (top right, replaces existing '+')

5

ทุบตีบริสุทธิ์132 130 128 127 ไบต์

ใช่ฉันสามารถวางแทน 1 ไบต์ได้มากกว่า${p% *}นี้ แต่ฉันชอบสิ่งนี้:

p=printf\ -v;$p a %$1s;$p b %$2s;o="|$a|\n";h=+${a// /-}+\\n v=${a// /$o}
a=${b// /$h$v}${h//+/o};a=${a/+/o};${p% *} "${a/+/o}"

ตัวอย่าง:

ladders() {
    p=printf\ -v;$p a %$1s;$p b %$2s;o="|$a|\n";h=+${a// /-}+\\n v=${a// /$o}
    a=${b// /$h$v}${h//+/o};a=${a/+/o};${p% *} "${a/+/o}"
}

ladders 3 4
o---o
|   |
|   |
|   |
+---+
|   |
|   |
|   |
+---+
|   |
|   |
|   |
+---+
|   |
|   |
|   |
o---o

ladders 2 1
o--o
|  |
|  |
o--o

4

Haskell, 100 97 ไบต์

l#s=unlines$t:m++[t]where _:m=[1..l]>>["+"!"-"]++("|"!" "<$u);t="o"!"-";o!i=o++(u>>i)++o;u=[1..s]

ตัวอย่างการใช้งาน:

*Main> putStr $ 4 # 3
o---o
|   |
|   |
|   |
+---+
|   |
|   |
|   |
+---+
|   |
|   |
|   |
+---+
|   |
|   |
|   |
o---o

มันทำงานอย่างไร:

l#s=unlines$t:m++[t]         -- concat top line, middle part and end line
                             -- with newlines between every line
  where                      -- where
  _:m=                       -- the middle part is all but the first line of
     [1..l]>>                -- l times
         ["+"!"-"]           --    a plus-dashes-plus line
         ++("|"!" "<$u)      --    followed by s times a bar-spaces-bar line

  t="o"!"-"                  -- very first and last line
  o!i=o++(u>>i)++o           -- helper to build a line
  u=[1..s]

แก้ไข: @Christian Irwan พบ 3 ไบต์ ขอบคุณ!


การจับคู่รูปแบบสำหรับ -1 คะแนนm=init$[1..l]>>("|"!" "<$u)++["+"!"-"]=>(_:m)=[1..l]>>["+"!"-"]++("|"!" "<$u)
Akangka

_:m=[1..l]>>["+"!"-"]++("|"!" "<$u)ผลงานที่น่าประหลาดใจ
Akangka

@ChristianIrwan: ด่างดี! ขอบคุณ!
Nimi

3

brainfuck - 334 ไบต์

,[<+<<<<+>>>>>-]<[[>>]+[<<]>>-]<----[>---<----]--[>[+>>]<<[<<]>++++++]>[+.>>]-[<+>---]<+++++++>>--[<+>++++++]->---[<------->+]++++++++++[<++<]+++++[>[++++++>>]<<[<<]>-]>[-]>.-<<----[>>+++<<----]--[>+<--]>---<<<<++++++++++.,[>[>+>+<<-]>[<+>-]>[<<<<[>>>>>>[.>>]<<[<<]>>-]>>>>>[.>>]<<[<<]>-]<<<<+>-]>>>>[-]----[>---<----]>+.[>]<<<<<[.<<]

ฉันคาดว่าสิ่งนี้จะสั้นกว่านี้มาก

สิ่งนี้จะตั้งค่า "สตริง" ที่มีลักษณะ| (...) |และรูปแบบที่คล้ายกัน+----(...)----+โดยพิมพ์แต่ละอันตามความจำเป็นพร้อมกับปลอกพิเศษสำหรับos ที่ด้านบนและด้านล่าง

ต้องการล่ามที่ใช้เซลล์ 8 บิตและอนุญาตให้คุณออกจากเซลล์ 0 (ไม่ว่าจะเป็นเซลล์เชิงลบหรือการวนซ้ำ) จากประสบการณ์ของฉันนี่เป็นการตั้งค่าเริ่มต้นที่พบบ่อยที่สุด

ด้วยความคิดเห็น:

,[<+<<<<+>>>>>-]<[[>>]+[<<]>>-] Get m from input; make a copy
                      Turn it into m cells containing 1 with empty cells between

<----[>---<----]      Put 67 at the beginning (again with an empty cell between)

--[>[+>>]<<[<<]>++++++]  Add 43 to every nonempty cell

>[+.>>]               Add 1 to each cell and print it

-[<+>---]<+++++++    Put 92 after the last 45 (no empty cell!)

>>--[<+>++++++]      Put 43 immediately after the 92

->---[<------->+]    Put 234 after 43

++++++++++           And 10 after that

[<++<]             Add two to the 234; 92; the empty spaces; and left of the 111

+++++[>[++++++>>]<<[<<]>-] Add 30 to each 2; the 94; and the 236

>[-]>.-<<----[>>+++<<----] Erase leftmost 32; Print 111; subtract 68 from it

--[>+<--]>---        Put 124 where the 32 was

<<<<++++++++++.,     Print a newline; override the cell with n from input

[                    n times:

  >[>+>+<<-]>[<+>-]    Make a copy of m

  >[                   m times:

    <<<<                 Look for a flag at a specific cell

    [                    If it's there:

      >>>>>>[.>>]          Go to the 43; print it and every second cell after

      <<[<<]>>-            Clear the flag

    ]

    >>>>>[.>>]           Go to the 124; print it and every second cell after

    <<[<<]>              Go back to the copy of m

  -]

  <<<<+>               Plant the flag

-]

>>>>

[-]----[>---<----]>+ Erase the 124; add 68 to 43

.[>]                 Print it; then head to the end

<<<<<[.<<] Go to the last 45; print it; then print every second cell to the left



2

Perl, 98 ไบต์

($n,$m)=@ARGV;print$h="o"."-"x$m."o\n",((("|".(" "x$m)."|\n")x$m.$h)x$n)=~s{o(-+)o(?=\n.)}{+$1+}gr

1
คำตอบแรกที่ยอดเยี่ยม แต่ฉันไม่เห็น+สัญญาณใด ๆในรหัสของคุณคุณคิดว่าขั้นตอนกลางมี+สัญญาณที่ปลายแต่ละด้านหรือไม่?
เลเวลริเวอร์เซนต์

ขอบคุณสำหรับความคิดเห็นที่พูดออกมาอย่างดีมาก - ฉันเว้นระยะห่างจากเครื่องหมายบวก! ทำให้ฉันเสียพื้นที่ไปหน่อย ยังคงคิดว่าฉันจะย่อให้สั้นลงได้อย่างไร ... นอกจากจะละเว้น($n,$m)=@ARGV;และสมมติว่าสิ่งเหล่านั้นถูกกำหนดไว้แล้ว - ไม่แน่ใจว่ามันอยู่ในจิตวิญญาณหรือไม่ ฉันจะต้องค้นหามัน
ZILjr

เว้นแต่จะระบุไว้ในคำถามกฎอยู่ที่นี่meta.codegolf.stackexchange.com/a/2422/15599 คุณไม่สามารถสันนิษฐานได้ว่าตัวแปรถูกตั้งค่าไว้แล้ว แต่คุณสามารถเขียนฟังก์ชั่นแทนโปรแกรมได้ถ้ามันช่วยได้ ฉันไม่ทำ Perl แต่ฉันคิดว่านั่นอาจช่วยคุณ@ARGVได้ นอกจากนี้เมื่อตอบกลับใครบางคนอย่าลืมใส่ @username เพื่อให้พวกเขาได้รับการแจ้งเตือน ฉันไม่จำเป็นต้องทำเพราะนี่คือโพสต์ของคุณ
ระดับแม่น้ำ St

1

C, 122 ไบต์

f(int m,int n,char*s){int i=0,w=3+m++;for(;i<w*m*n+w;++i)*s++=i%w>m?10:" |-+-o"[!(i/w%m)*2+!(i%w%m)+!(i/w%(m*n))*2];*s=0;}

ลองมันออนไลน์


1

Tcl, 187 ไบต์

lassign $argv n w
set c 0
while { $c < [expr {($w * $n) + ($n + 2)}]} {if {[expr {$c % ($n + 1)}] == 0} {puts "o[string repeat "-" $w ]o"} else {puts "|[string repeat " " $w ]|"}
incr c}

รหัสนี้ทำเพื่อใส่ลงในไฟล์ที่มีอินพุตอาร์กิวเมนต์บนบรรทัดคำสั่ง ระบุจำนวนกล่องและความกว้างตามลำดับ


1

PHP, 81bytes

คาดว่าจะมี 2 ข้อโต้แย้งผ่านไปเมื่อเรียกใช้คำสั่ง PHP โดยตรง คนแรกคือขนาดและคนที่สองคือจำนวนขั้นตอน

$R=str_repeat;echo$P="o{$R('-',$W=$argv[1])}o
",$R("|{$R(' ',$W)}|
$P",$argv[2]);

อาจต้องการการปรับปรุงบางอย่าง


0

Python 2, 94 ไบต์

def F(n,m):a,b,c,d='o|+-';r=[a+d*m+a]+([b+' '*m+b]*m+[c+d*m+c])*n;r[-1]=r[0];print'\n'.join(r)

'Ungolfed:

def F(n,m):
 # 'o---o'
 r = ['o'+'-'*m+'o']
 # ('|   |'*m+'+---+') n times
 r += (['|'+' '*m+'|']*m+['+'+'-'*m+'+'])*n
 # replace last +---+ with o---o
 r[-1] = r[0]
 print '\n'.join(r)


0

Pip -l , 35 ไบต์

(^YsXbRLaJW'-)XbWR^('|XbRLaJ'+)WR'o

ลองออนไลน์!

คำอธิบาย

(^YsXbRLaJW'-)XbWR^('|XbRLaJ'+)WR'o
                                     a is length, b is size, s is space (implicit)
   sXb                               String containing b spaces
      RLa                            List containing a copies of that string
         JW'-                        Join on "-" and wrap the result in "-" as well
  Y                                  Necessary for operator precedence reasons
 ^                                   Split into a list of characters
(            )Xb                     String-repeat each character in the list b times
                                     This list represents the central columns of the ladder

                    '|Xb             String containing b pipe characters
                        RLa          List containing a copies of that string
                           J'+       Join on "+"
                   (          )WR'o  Wrap in "o"
                  ^                  Split into a list of characters
                                     This list represents the outer columns of the ladder

                WR                   Wrap the left list in the right list, vectorizing

บางรุ่นอื่น ๆ

ฉันลองวิธีการต่าง ๆ มากมายที่พยายามจับ Pyth ...

[Y'-XbWR'o;@>(sXbWR'|RLbPE'-XbWR'+RL:a)y]  41
Y^(t**b.1*:t**bX--a.1)" --"@yXbWR"|o+"@y   40
Y'|XbRLaJ'+YyWR'o;Z:sXbRLaJW'-RLbPEyAEy    39
t**:b(" |-o-+"<>2)@_@^t.1M$*Y[ttXa-1].1    39
J*Z:sXbRLaJW'-RLbWR:^('|XbRLaJ'+)WR'o      37
Y^$*Y[t**:btXa-1].1" --"@yXbWR"|o+"@y      37

ฉันชอบของt**bที่ใช้คณิตศาสตร์ในการสร้างรูปแบบแนวตั้งของบันได:

        b           Size; e.g. 3
    t               Preset variable for 10
     **:            Set t to t**b (e.g. 1000)
           a        Length; e.g. 3
            -1      2
         tX         String-repeat (the new value of) t 2 times: 10001000
   [          ]     Put t and the above into a list: [1000; 10001000]
               .1   Append 1 to both of them: [10001; 100010001]
$*(              )  Fold on multiplication: 1000200020001

1000200020001นั้นจะสามารถใช้ในการสร้างรูปแบบo|||+|||+|||oและ- - - -ที่ทำขึ้นบันได น่าเสียดายที่ฉันไม่สามารถเข้าถึงวิธีนี้สั้นกว่าวิธีเข้าร่วม / สรุปข้อมูลได้

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.