基本ASCII提示


36

替代标题:在墙上统计您的监狱判决

给定一个数字n,输出记录分为传统的每组5个和每行50个。


例子

1个

|
|
|
|

4

||||
||||
||||
||||

5

|||/
||/|
|/||
/|||

6

|||/ |
||/| |
|/|| |
/||| |

50

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

51

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|
|
|
|

256

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/ |||/
||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/| ||/|
|/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/|| |/||
/||| /||| /||| /||| /||| /||| /||| /||| /||| /||| 

|||/ |
||/| |
|/|| |
/||| |

规则

  • 每组5个标记,每行50个标记。
  • 前4个记号是垂直的,第5个记数符与其他所有记号交叉。
    • 前四个|字符均由四个垂直字符组成。
    • 最后的第5个/对角线横跨第一个第4个对角线,并带有一个字符。
  • 每个组应以空格分隔,每行应使用空白换行符。
  • 约束n为:(0 <= n <= 1000为简单起见)。
  • 尾随空格和换行符很好,而前面则不行。
  • 这是,字节计数最低。

沙盒中的〜4个人审核。


PS 有趣的小提示,监狱中每排的平均计数为50,因此为alt。标题。



巨大的挑战,复杂而简单。
ATaco

@ATaco我真的很想找到在“大图”中汇总斜杠的解决方案,并考虑到可以按行推断斜杠模式(这很容易取胜)。
魔术章鱼缸

2
谢谢你这么多的使他们正斜杠,而不是反斜杠。
totallyhuman

1
@totallyhuman噢,天哪,我张贴的图片中的那个家伙……这是什么普遍性?是伯恩斯坦再一次承受了……硬币是正面还是反面来决定最近的美国大选?!
魔术章鱼缸

Answers:


11

木炭30 25字节

FN«J﹪ι⁵⁰×⁵÷ι⁵⁰¿﹪⊕ι⁵↓⁴«←↙⁴

在线尝试!链接是详细版本的代码。说明:

 N                          Input number
F «                         Loop over implicit range
     ι     ι                Loop index
      ⁵⁰    ⁵⁰              Literal 50
    ﹪                       Modulo
          ÷                 Integer divide
         ⁵                  Literal 5
        ×                   Multiply
   J                        Jump to column, row
                 ι          Loop index
                ⊕           Incremented
                  ⁵         Literal 5
               ﹪            Modulo
              ¿             If
                   ↓⁴       Print 4 `|`s downwards
                     «      Implicit else
                      ←     Move left
                       ↙⁴   Print 4 `/`s down and left

6

时髦156个 132 133字节的

n=>{k=n=>((l="|"::rep)(3-i)+"/"+l(i)+" ")::rep(n)p=print L=f=>fori=0i<4i++p(f())forc=0c<n//50c++{L@k(10);p()}L@k((m=n%50)//5)+l(m%5)}

在线尝试!


1
时髦是...现在呢?有趣。以前从未遇到过这种语言。
魔术章鱼缸

1
@MagicOctopusUrn可能是因为我写了它:P
ATaco

1
基于JavaScript的语言?危险的。但这没关系,我喜欢危险。
魔术章鱼缸

1
fori=0i<4i++p(f())forc=0c<n//50c++以语法的名字命名的这邪恶的野兽是什么
完全人类的



5

果冻,37个字节

:5[“|||/”]ẋ;”|ẋ⁸%5¤¤W¤ṙ€4Ḷ¤s⁵Z€G€j⁾¶¶

在线尝试!

说明

:5[“|||/”]ẋ;”|ẋ⁸%5¤¤W¤ṙ€4Ḷ¤s⁵Z€G€j⁾¶¶  Main Link
:5                                     Floordiv by 5
  [“|||/”]ẋ                            Repeat ["|||/"] by this number
           ;                           Append
            ”|ẋ    ¤                   "|" repeated by
               ⁸%5¤                    The argument modulo 5
                    W¤                 Then wrapped to prevent weirdness
                      ṙ€               Rotate each tally segment by
                        4Ḷ¤            (each) [0, 1, 2, 3]
                           s⁵          Slice into pieces of length 10 (to get 50 per row)
                             Z€        Transpose each
                               G€      Convert each into a grid
                                 j⁾¶¶  Join these grids by a double newline

这太久了


@FrownyFrog已修复,谢谢!
HyperNeutrino

4

外壳,29个字节

J;øṀṪṙŀ4C10§:oR"|||/"÷5oR'|%5

在线尝试!

我觉得第一个5是多余的,但是删除它会导致类型错误...

说明

J;øṀṪṙŀ4C10§:oR"|||/"÷5oR'|%5  Implicit input, an integer n.
                       oR'|    Repeat the character '|'
                           %5  n mod 5 times.
             oR"|||/"          Repeat the string "|||/"
                     ÷5        n/5 times.
           §:                  Tack the '|'-string to the end of that list.
        C10                    Cut the list of strings into pieces of length 10.
   Ṁ                           For each piece,
    Ṫ ŀ4                       for each k in [0,1,2,3],
     ṙ                         rotate each string k steps to the left
                               and collect the results into a list.
                               Now we have a list of lists of lists of strings.
J;ø                            Join them with the list [[]].
                               Implicitly join each list of strings by spaces,
                               then join the resulting list of strings by newlines,
                               and print the result.

4

SOGL V0.12,33 个字节

ā.{┐4∙F5\?X1w⁄3-14╚╬5@}┼FM»\?O¶oā

在这里尝试!

打手机很难。

说明:

ā                                  push an empty array
 .{                                repeat input times
   ┐4∙                               push a 4 tall line
      F5\?            }              if the counter (1-indexed) divides by 5
          X                            pop that vertical line
           1w⁄                         get the width of the main array
              3-                       subtract 3 from that width - X position
                1                      push 1 - Y position
                 4╚                    push a 4 long diagonal
                   ╬5                  place that in the main array at [width-3; 1]
                     @                 push a space - for the below to add spacing
                       ┼             append horizontally
                        FM»\?        if the counter divides by 50
                             O         output the main array
                              ¶o       output a newline
                                ā      push a new array
                                       (note that the outputting here doesn't disable
                                       implicit outputting)

4

的JavaScript(ES6),139个 137字节

n=>eval('s="";for(i=0;i++<=n/50;s+=N)for(j=5;--j;s+=N=`\n`)for(k=0;k<(x=(y=n-i*50)<0?50+y:50);)s+=++k%5?k%5-j|k>5*(x/5|0)?"|":"/":" ";s')

返回时,用一个结尾的新行的字符串n时,不是50,一个多几个尾随换行符n 50的倍数。

不打高尔夫球

n=>{
    s=""
    for(i=0; i++ <= n/50; s+=N)
        for(j=5; --j; s+=N=`\n`)
            for(k=0; k < (x = (y = n-i*50) < 0 ? 50+y : 50);)
                s += ++k%5 ?
                    k%5-j|k>5*(x/5|0) ?
                        "|"
                    : "/"
                : " "
    return s
}

测试片段

eval解决方案,150字节

n=>(A=(v,m)=>j=>[...Array(v).keys()].map(m).join(j))(n/50+1|0,i=>A(4,j=>A(x=(y=n+~i*50)<0?50+y:50,k=>++k%5?k%5-4+j|k>5*(x/5|0)?"|":"/":" ")``)`
`)`

`

可能可以再打一次,但eval到目前为止该方法已经缩短了。


我花了10分钟的时间来完成非高尔夫版本的工作并理解它。= ^ P您那里有一些不错的技巧。
DLosc

非常确定您可以做到(i = 0; ++ i <n / 50; s + = N),这样可以节省一个字符
DanielIndie

@DanielIndie之所以失败,是因为外循环运行的次数太少了:在线尝试!
贾斯汀·马里纳

4

J50 48 45 35 33字节

_50|:\'|/ '{~[{.(|.2,=i.4)$~]-5|]

在线尝试!

                (    =i.4)          Identity matrix of size 4.
                (  2,    )          Prepend a row of 2s.
                (|.      )          Upside down.
                          $~        Take __ rows.
                            ]-5|]   Input rounded down to a multiple of 5.
             [{.                    Pad with rows of zeroes to [input] rows.
      '|/ '{~                       Get the characters.
_50|:\                              Transpose and fit to width.

我喜欢在这一部分使用中缀的想法4,&' '\7$'|||/'
乔纳(Jonah)

@Jonah,它必须走了:(
FrownyFrog

3

C(gcc),170个字节

char*s="|||/ \0||/| \0|/|| \0/||| \0";h;k;g(x){for(h=0;h<5;h++){for(k=x;k>4;k-=5)printf(s+6*h);for(;k&&h-4;k--)printf("|");putchar(10);}}f(x){for(;x>49;x-=50)g(50);g(x);}

在线尝试!

f是将非负整数(x)并按指定分组的许多计数打印到stdout 的函数

g是一个辅助功能,可打印x以5为单位的计数,而不用分割线。

f调用g(50)并递减x50,直到小于50,然后调用g(x)以在一行上打印剩余的计数。

schar*这样的字符串,它s是束的第一行,s+6是第二行,s+12是第三行,s+18是第四行,s+24是空字符串。

g(x)打印捆束并将x减5,直到x小于5,然后打印x单个记数。



2

Python 2,142字节

n=input()
while n>0:print"\n".join("".join("|/ "[2*(j%5>3)+(n/(5*(j/5+1))and 3-i==j%5)]for j in range(min(50,n)))for i in range(4)),"\n";n-=50

在线尝试!


1
18分钟内达到142个字节?不错 :)。
魔术章鱼缸

3
当您一个小时前应该真正上床睡觉时,便开始快速工作
Halvard Hummel

Quick ~= Quality;)。不错的工作。
魔术章鱼缸

3
错误...可能会被误解。说您做得很好,质量工作很快……不是相反。
魔术章鱼缸


2

Perl 5,103个字节

$a=<>;do{$_=$a<50?"|||/ "x($a/5).'|'x($a%5):"|||/ "x10;for$i(1..4){say;s%\|/%/|%g}say""}while($a-=50)>0

在线尝试!


2

Haskell,134个字节

f#n=unlines$(concat.f.(<$[1..n`div`5]))<$>["|||/ ","||/| ","|/|| ","/||| "]
f n|n>50=id#50++'\n':f(n-50)|1>0=(++['|'<$[1..n`mod`5]])#n

在线尝试!

asdfghjkl-是的,我正在努力。


2

PHP,138 141 + 1个字节

可能不是最短的解决方案

for(;0<$z=50+min($n=$x=$y=0,$argn-=50);print"
")while($n++<$z||!$x=+(3<$y+=$n=print"
"))echo"/| "[$n%5?($y+$x++)%4<3|$n%5+$y<4|$z-$z%5<$n:2];

与管道一起运行-nR在线尝试


整齐!但是从第二个计数线开始,这些计数并没有完全越过。
SpazzMarticus

从5.5开始(本地5.6.31和7.1.9)运行“在线尝试”示例时。
SpazzMarticus

1
$x仅在第一个循环中未定义,这会使输出结果大于54。固定,但没有打高尔夫球:sandbox.onlinephpfunctions.com/code/…–
SpazzMarticus

@SpazzMarticus已修复
Titus

凉!这是我第一次调试高尔夫代码,您让我很难受!:)我想我很着迷!
SpazzMarticus

2

蟒蛇, 129 113 112字节

f=lambda n:n>50and f(50)+"\n\n"+f(n-50)or"\n".join(("|||/|||"[k:k+4]+" ")*(n//5)+" "+"|"*(n%5)for k in range(4))

说明

def p(n):
  if n > 50:
    return p(50) + "\n\n" + p(n-50) # Handle 50-groups recursively
  else:
    # For each of the 4 lines:
    rows = []
    for row in range(4):
      #  - Build the "|||/"-blocks by slicing the correct part of "|||/|||".
      #  - Do that n/5 times
      #  - Then add "|" n%5 times
      rows += [("|||/|||"[row:row+4]+" ")*(n//5) + " " + "|"*(n%5)]

    # Join the four rows together
    return "\n".join(rows)

适用于Python 2和3。

在线尝试



1

红宝石,100字节

->n{(n/-50*-4).times{|i|j=[n-i/4*50,50].min
$><<("|||/|||"[i%4,4]+" ")*(j/5)+?|*(j%5)+$/*(1+i%4/3)}}

已评论

->n{(n/-50*-4).times{|i|              #Calculate rows of tallies (Ruby rounds division towards negative infinity. Multiply by 4 lines per tally and iterate through them.)
  j=[n-i/4*50,50].min                 #Number of strokes printed in current row is either the number remaining, or 50, whichever is less
    $><<("|||/|||"[i%4,4]+" ")*(j/5)+ #Send to stdout the correct 4 chars selected from "|||/|||" plus a space, j/5 times (rounded down, which eliminates odd strokes.) 
    ?|*(j%5)+                         #If there are any odd strokes, add them to the output
    $/*(1+i%4/3)                      #followed by a newline (2 for the final line of each row of tallies.)
  }
}

在线尝试!


1

47 46字节

Wa-:yP('|X4.sRA3-_'/M,4)X(YMN[a50])/5.'|Xy%5.n

在线尝试!

说明

        Implicit: a is 1st cmdline arg, y is "", s is space, n is newline
W       While loop:
 a-:y   Each iteration, subtract y from a and check if a is still nonzero
        (Since "" is 0 in numeric contexts, this does nothing the first time through)
     P  Print the following:

('|X4.sRA3-_'/M,4)X(YMN[a50])/5.'|Xy%5.n
              M                           Map this function to each number in
               ,4                         range(4):
 '|X4                                      String of four pipe characters
     .s                                    Concatenate a space
       RA                                  Replace the character at index
         3-_                                (3 minus function argument)
            '/                              with forward slash

                                          We now have a list of four strings representing
                                           the rows of a group of 5 tally marks; the
                                           following operations apply to the list
                                           element-wise:

                       [a50]              List of a (number of remaining tallies) and 50
                     MN                   Get the min (number of tallies on this row)
                    Y                     Yank it into y
                   (        )/5           Divide by 5 (number of groups on this row)
(                )X                       String-multiply by that amount
                                   y%5    Number of leftover tallies on this row
                                '|X       String-multiply that many pipes
                               .          Concatenate
                                      .n  Concatenate a newline

结果列表将如下所示:

["|||/ ||\n" "||/| ||\n" "|/|| ||\n" "/||| ||\n"]

默认情况下,P将列表的内容连接在一起,并用结尾的换行符输出它们。因此,我们得到

|||/ ||
||/| ||
|/|| ||
/||| ||

包含两个结尾的换行符(一个来自列表内容,另一个由所添加P)。如果要打印另一行,这将在其间给出必需的空白行。




0

05AB1E,28 个字节

5‰"|||/"¬‚×J4ôTôεε3Ý._}ø»¶«,

在线尝试。

说明:

5              # Divmod the (implicit) input-integer by 5
                #  i.e. 111 → [22,1]
  "|||/"        # Push string "|||/"
        ¬       # Push its first character (without popping the string itself): "|"
               # Pair them together: ["|||/","|"]
          ×     # Repeat it based on the divmod
                #  i.e. [22,1] → ["|||/|||/|||/...|||/|||/|||/","|"]
           J    # Join everything together to a single string
                #  → "|||/|||/|||/...|||/|||/|||/|"
            4ô  # Which is then split into block of size 4
                #  → ["|||/","|||/","|||/",...,"|||/","|||/","|||/","|"]
Tô              # Then split this list into sublists of size 10
                #  → ["|||/","|||/","|||/",...],[...,"|||/"],["|||/","|||/","|"]]
  ε             # For-each over the sublists:
   ε            #  Map over the strings in the sublist:
    3Ý          #   Push list [0,1,2,3]
      ._        #   For each: rotate the string that many times
                #    ("|||/" → ["|||/","||/|","|/||","/|||"])
              #  After the map: zip/transpose; swapping rows/columns
     »          #  Join each inner list by spaces, and then the strings by newlines
      ¶«        #  Append a newline to each string
        ,       #  And print with trailing newline

¶«,当然有一些可能的等字节替代方案,例如,¶?,õ,



By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.