雪人保龄球


29

(相关/灵感来自:绘制保龄球

在冬季,这里的一个有趣消遣是使用一个大球(例如篮球)和微小的雪人人物来打雪人保龄球。让我们用ASCII重新创建它。

每个雪人包括以下内容:

(.,.)
( : )

这是十个雪人“别针”的对齐方式

(.,.) (.,.) (.,.) (.,.)
( : ) ( : ) ( : ) ( : )
   (.,.) (.,.) (.,.)
   ( : ) ( : ) ( : )
      (.,.) (.,.)
      ( : ) ( : )
         (.,.)
         ( : )

这些“销”被从标记110作为

7 8 9 10
 4 5 6
  2 3
   1

到目前为止,如此标准。但是,与普通的保龄球不同,雪人的针脚只是弄平而不能完全取下。这是由需要手动弄平被击中的所有销钉的积雪的人员完成的。扁平的雪人用_____(五个下划线)表示,上面带有空格。这是使1 3 5 6 9 10引脚变平的示例(意味着仅2 4 7 8保留引脚):

(.,.) (.,.)
( : ) ( : ) _____ _____
   (.,.)
   ( : ) _____ _____
      (.,.) 
      ( : ) _____

         _____

输入值

  • 整数形式的从1到的列表,以10 任何方便的格式表示击中了哪些引脚,因此需要进行展平。
  • 每个数字最多只能出现一次,并且这些数字可以按任何顺序排列(排序,未排序,降序排列),无论您选择哪种代码,都可以更轻松地选择。
  • 输入保证至少有一个整数。

输出量

雪人图钉的ASCII艺术表现形式,正确的图钉展平。

规则

  • 前导或尾随的换行符或空格都是可选的,只要字符本身正确对齐即可。
  • 完整的程序或功能都是可以接受的。如果是函数,则可以返回输出而不是打印输出。
  • 如果可能,请提供一个在线测试环境的链接,以便人们可以尝试您的代码!
  • 标准漏洞禁止出现。
  • 这是因此所有常用的高尔夫规则都适用,并且最短的代码(以字节为单位)获胜。

例子

1 3 5 6 9 10

(.,.) (.,.)
( : ) ( : ) _____ _____
   (.,.)
   ( : ) _____ _____
      (.,.) 
      ( : ) _____

         _____

1 2 3

(.,.) (.,.) (.,.) (.,.)
( : ) ( : ) ( : ) ( : )
   (.,.) (.,.) (.,.)
   ( : ) ( : ) ( : )

      _____ _____

         _____

1 2 3 4 5 6 8 9 10

(.,.)
( : ) _____ _____ _____

   _____ _____ _____

      _____ _____

         _____

18
编码高尔夫?不打保龄球吗?
2016年

我们可以将输入数字从0索引吗?并尽可能将输入值不带空格(例如0123456789)替换为1 2 3 4 5 6 7 8 9 10?
蓝绿色鹈鹕

完美的:D它使我可以更轻松地尝试> <>
蓝绿色鹈鹕

4
我不同意堆雪人。

我将自己标识为雪人,并发现其变平。
征服者

Answers:


7

05AB1E45 44字节

TF"(.,.)( : )"„ _5×{«4ä2ä¹N>åè})4L£Rvyø»}».c

在线尝试!

说明

TF                                           # for N in [0 ... 9] do:
  "(.,.)( : )"                               # push string
              „ _                            # push the string " _"
                 5×                          # repeat it 5 times
                   {                         # sort
                    «                        # concatenate the strings
                     4ä                      # split the string in 4 parts
                       2ä                    # split the list in 2 parts
                         ¹N>åè               # if index+1 is in the input, push the first part
                                             # else push the second part
                              }              # end loop
                               )             # wrap stack in a list
                                4L£          # split list in parts of size 1,2,3,4
                                   R         # reverse list
                                    v        # for each list in list of lists
                                     yø      # transpose the list
                                       »     # join by spaces and newlines
                                        }    # end loop
                                         »   # join by newlines
                                          .c # centralize

46

雪人1.0.2,157字节

(()("789:045600230001"4aG::48nSdU][:#:]eq]/nM;AsI[:"_____"wR["     "wR/aC;:"( : )"wR["(.,.)"wR/aC;bI;:"  "wRdUaC;bI\#**\;aMaZ:" "aJ1AfL;aM;aM1AfL"
"aJ1AfL*))

在线尝试!

当我看到这个挑战时,我知道我只需要用完美的语言来回答...

这是一个子例程,该子例程将输入作为数字数组,并通过当前的永久对象作为字符串输出。

包装为“可读性” /美观:

(()("789:045600230001"4aG::48nSdU][:#:]eq]/nM;AsI[
:"_____"wR["     "wR/aC;:"( : )"wR["(.,.)"wR/aC;bI
;:"  "wRdUaC;bI\#**\;aMaZ:" "aJ1AfL;aM;aM1AfL"
"aJ1AfL*))

略有偏离/评论版本:

}
1wR`
3wR`aC`
5wR`aC`
6wR`aC`
9wR`aC`
*

((
    )(
    "789:045600230001"  // pin layout data
    4aG                 // split into groups of 4; we need each row twice
    :                   // map over groups of 2 output lines
        :               // map over pins (or whitespace)
            48nS        // subtract ascii '0'
            dU][        // duplicate the pin; we need it in the if{}
            :           // if (pin) {
                #:]eq]/nM;AsI[:"_____"wR["     "wR/aC;:"( : )"wR["(.,.)"wR/aC;bI
            ;:          // } else {
                "  "wRdUaC
            ;bI         // }
            \#**\       // maneuver the permavars around to discard pin
        ;aM
        aZ:" "aJ1AfL;aM
    ;aM
    1AfL                // flatten (simulate a flatmap)
    "
"aJ                     // join on newline
    1AfL                // flatten again into a single string
    *
))

#sP

17
几乎唯一可以被称为“完美语言”的语境,:P
DJMcMayhem

2
一个雪人正在杀死自己的同类...你这怪物!
RudolfJelin

10

堆积,无竞争,118字节

deepmap在挑战之后,我添加了一些其他内容,以及大量的错误修正。在这里尝试!

@a((7 8 9 10)(4 5 6)(2 3)(1)){e:('(.,.)
( : )' ' 
_'5 hrep)a e has#'  'hcat
}deepmap{e i:' 
 'i 3*hrep e,$hcat#/!LF+}map

不打高尔夫球

{ a :
  ((7 8 9 10) (4 5 6) (2 3) (1))
  { e :
    (
      '(.,.)' LF '( : )' + + 
      ' ' LF '_' + + 5 hrep
    ) @possible
    a e has @ind
    possible ind get @res
    '  ' @padding
    res padding hcat return
  } deepmap
  { e i:
    ' ' LF ' ' + + i 3 * hrep
    e ,
    $hcat insert!
    LF +
  } map
} @:bowl

(1 2 3 4 6 10) bowl out

输出:

(.,.) (.,.) (.,.)       
( : ) ( : ) ( : ) _____ 
         (.,.)       
   _____ ( : ) _____ 

      _____ _____ 

         _____ 

这种语言看起来很棒。Wiki中的Fisher-Yates示例很漂亮。
约旦

@乔丹非常感谢你!这对我来说意义非凡:)
Conor O'Brien

7

Python 2中,248 243 241 226 224 223个 221 210 206 200 177字节

-5感谢@Rod

-15再次感谢Rod

-1使用Rod再次使用空间计算

由于有更多的行和缩进,因此看起来更长,但令人惊讶的是短了11个字节。

我敢肯定这将低于200 ...

我是对的,但并非没有@ Pietu1998的23个字节的严重提示。非常感谢!

i,z=input(),0;m=['']*10;n=m[:]
for x in range(11):m[x-1],n[x-1]=('(.,.)',' '*5,'( : )','_'*5)[x in i::2]
for y in 10,6,3,1:
 for q in m,n:print' '*3*z+' '.join(q[y-4+z:y])
 z+=1

在线尝试!

将输入作为整数列表。在248时太大了,但是可以用。



6

C#233 221 213 203个字节

方法将一个int数组a作为下降引脚的列表

string S(int[]a){string o="",x=o,y=o,z=o;for(int i=10;i>0;){var c=a.Contains(i);x=(c?"      ":"(.,.) ")+x;y=(c?"_____ ":"( : ) ")+y;if(i==7|i<5&i--!=3){o+=$"{z}{x}\n{z}{y}\n";x=y="";z+="   ";}}return o;}

包裹

string S(int[]a){string o="",x=o,y=o,z=o;for(int i=10;i>0;)
{var c=a.Contains(i);x=(c?"      ":"(.,.) ")+x;y=(c?"_____ ":
"( : ) ")+y;if(i==7|i<5&i--!=3){o+=$"{z}{x}\n{z}{y}\n";x=y="";
z+="   ";}}return o;}

扩大了

string S(int[] a)
{
    string o = "", x = o, y = o, z= o;
    for (int i = 10; i > 0;)
    {
        var c = a.Contains(i);
        x = (c ? "      " : "(.,.) ") + x;
        y = (c ? "_____ " : "( : ) ") + y;

        if (i==7|i<5&i--!=3)
        {
            o += $"{z}{x}\n{z}{y}\n";
            x = y = "";
            z += "   ";
        }
    }
    return o;
}

通过Ghost,raznagul和auhmaan的评论中的建议删除了几个字节。


2
Welcome to PPCG!
AdmBorkBork

nice! You can save a few bytes (5?) if you put the i-- in the for and change new[]{7,4,2,1}.Contains(i--) to i<9&&i%3==1||i==2
Ghost

Can improve that by two more (for -7) with i==7||i<5&&i!=3
Ghost

@Ghost thanks! knocked it down a bit more by using non-shortcurcuit ors and ands, and still decrementing with the final ref to i i==7|i<5&i--!=3
Erresen

You can save some bytes by replacing var o="";var x=... by string o="",x=""....
raznagul

5

Batch, 262 bytes

@echo off
for /l %%i in (1,1,10)do set s%%i=( : ) 
for %%i in (%*)do set s%%i=_____ 
set l=call:l 
%l%%s7%%s8%%s9%%s10%
%l%"   %s4%%s5%%s6%
%l%"      %s2%%s3%
%l%"         %s1%
exit/b
:l
set s=%~1
set s=%s:( : )=(.,.)%
echo(%s:_____=     %
echo(%~1

Note: Lines 2, 3 and 4 end in a space, and also outputs a trailing space on each line. These can be removed at a cost of 5 bytes. Works by creating variables s1...s10 as the bottom halves of the snowmen, then flattening the ones given as command-line arguments. The appropriate rows are printed twice, the first time with the bottom halves replaced with the top halves. This saves 18 bytes over using two sets of top and bottom half variables.


1
That's a slick answer.
AdmBorkBork

4

JavaScript, 154 149 bytes

f=
a=>`6 7 8 9
_3 4 5
__1 2
___0
`[r='replace'](/\d|_/g,m=>++m?~a.indexOf(m)?'_____':'( : )':'   ')[r](/.*\n?/g,m=>m[r](/ : |_/g,s=>s=='_'?' ':'.,.')+m)


I.oninput=()=>O.innerHTML=f(JSON.parse(`[${I.value.match(/\d+/g)}]`))
I.oninput()
<input id=I value="1 3 5 6 9 10"><pre id=O>


3

Pyth, 63 bytes

j.ejm+**3k;j;db)_CcR[1 3 6).e:*T]btMQ@m*T]*5d,d\_kc2"(.,.)( : )

A program that takes input of a list of integers and prints the result.

Test suite

[Explanation coming later]


3

Pyth, 51 bytes

The code contains some unprintables, so here is an xxd hexdump.

00000000: 6a6d 2e5b 3233 5f6a 3b6d 4063 323f 7d6b  jm.[23_j;m@c2?}k
00000010: 5172 2235 2035 5f22 392e 2220 3b5b 8db2  Qr"5 5_"9." ;[..
00000020: 1778 a822 6472 4673 4d50 4253 2d34 2f64  .x."drFsMPBS-4/d
00000030: 323b 38                                  2;8

Try it online.

Without unprintables, 52 bytes

jm.[23_j;m@c2?}kQr"5 5_"9").,.() : ("drFsMPBS-4/d2;8

Try it online.


2

Javascript 178 169 bytes

Essentially a port from my C# answer.

Takes an int array as the list of flattened "pins";

f=a=>{o=x=y=z="";for(i=10;i>0;){c=a.includes(i);x=(c?"      ":"(.,.) ")+x;y=(c?"_____ ":"( : ) ")+y;if(i==7|i<5&i--!=3){o+=z+x+"\n"+z+y+"\n";x=y="";z+= "   ";}}return o}

Wrapped:

f=a=>{o=x=y=z="";for(i=10;i>0;){c=a.includes(i);
x=(c?"      ":"(.,.) ")+x;y=(c?"_____ ":"( : ) ")+y;
if(i==7|i<5&i--!=3){o+=z+x+"\n"+z+y+"\n";x=y="";
z+= "   ";}}return o}

Expanded & Explained:

// function f takes parameter a (an array of ints) 
f = a => {

    // four strings:
    // o: output
    // x: top row of snowmen
    // y: bottom row of snowmen
    // z: padding to indent the snowmen
    o = x = y = z = "";

    // loop from 10 to 1 (the pins)
    // remove the "afterthought" decrement - we can do that later
    for (i = 10; i > 0;) {

        // set the boolean c to whether the current pin has been flattened
        c = a.includes(i);

        // prefix x and y with the appropriate "sprite"
        // using a ternary if on c
        x = (c ? "      " : "(.,.) ") + x;
        y = (c ? "_____ " : "( : ) ") + y;

        // determine if we've reached the end of a row (i equals 7, 4, 2 or 1)
        // use non shortcircuit operators to save bytes and ensure we hit the final i, because...
        // we also decrement i here 
        // (we didn't do this in the for loop declaration to save a byte)
        if (i == 7 | i < 5 & i-- != 3) {

            // concatenate our rows x & y,
            // prefixing them with the padding z,
            // postfixing them with a newline
            o += z + x + "\n" + z + y + "\n";

            // reset x and y rows
            x = y = "";

            // increase our padding for next time
            z += "   ";
        }
    }

    // return our final string (no semicolon to save a byte)
    return o
}
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.