私を裏返したクリスマスツリーにしてください!

チャレンジ

We all know about normal Christmas trees – but how about an
upside-down Christmas tree! This is a fairly
easy, Christmas themed チャレンジ. The objective of this チャレンジ is to
make me an ASCII upside-down Christmas tree. Here are the ルール for
this チャレンジ:

  1. Accept an odd, positive integer. You can assume it will always
    be between 7 and 51.
  2. The base of the tree will be made of the characters:

    ___
     /
     |
    
  3. The top of the tree (the star), will be made up of a single
    *.

  4. Each line of the tree will be constructed using the format
    <?> where ? is any number of
    -s. For example, if making a line of length
    5, the line should be <--->. Or if
    making a line of length 8, the line should be
    <------>.

  5. Here is how the body of the tree should be constructed:

    1. Take the odd number n given as input, and create a
      line of the tree that length.

    2. Subtract 4 from n and create a line of
      the tree that length.

    3. Subtract 2 from n and create a line of
      the tree that length.

    4. Decrement n by 2. After that, unless
      n equals 5, go back to
      step 2.

  6. The base (see step 2.) the star (see step 3.) and each line of
    the tree (see steps 4. and 5.) should all be centered using the
    original odd number input (see step 1.) as the maximum
    width.

例/テストケース

odd number inputed: 7
  ___
   /
   |
<----->      line length -> 7
  <->        line length -> 7 - 4 = 3
 <--->       line length -> 7 - 2 = 5
   *


odd number inputed: 13
     ___
      /
      |
<----------->      line length -> 13
  <------->        line length -> 13 - 4 = 9
 <--------->       line length -> 13 - 2 = 11
   <----->         line length -> 11 - 4 = 7
  <------->        line length -> 11 - 2 = 9
    <--->          line length -> 9 - 4 = 5
   <----->         line length -> 9 - 2 = 7
     <->           line length -> 7 - 4 = 3 
    <--->          line length -> 7 - 2 = 5
      *


odd number inputed: 9
   ___
    /
    |
<------->      line length -> 9
  <--->        line length -> 9 - 4 = 5
 <----->       line length -> 9 - 2 = 7
   <->         line length -> 7 - 4 = 3
  <--->        line length -> 7 - 2 = 5
    *


odd number inputed: 17
       ___
        /
        |
<--------------->      line length -> 17
  <----------->        line length -> 17 - 4 = 13
 <------------->       line length -> 17 - 2 = 15
   <--------->         line length -> 15 - 4 = 11
  <----------->        line length -> 15 - 2 = 13
    <------->          line length -> 13 - 4 = 9
   <--------->         line length -> 13 - 2 = 11
     <----->           line length -> 11 - 4 = 7
    <------->          line length -> 11 - 2 = 9
      <--->            line length -> 9 - 4 = 5
     <----->           line length -> 9 - 2 = 7
       <->             line length -> 7 - 4 = 3
      <--->            line length -> 7 - 2 = 5
        *    

ルール

ベストアンサー

Python 3, 127 121
105 103 100 98 bytes

これは、行のリストを返す無名のラムダ関数です:

lambda o:[s.center(o)for s in['___',' /','|',*[f'<{"-"*(o-i+2-i%2*3)}>'for i in range(4,o)],'*']]

3-お試しください!

この回答の主な部分は、行に付けるダッシュの数を計算する(o-i + 2-i%2 *
3)
です。答えの残りの部分は、これを目的のASCIIアートに変換するだけです。

Many thanks to Mr.
Xcoder
, for shaving 6 bytes, and discussing golfs with me in
chat.

3 *(i%2)ということに気づいた Lynn
にも感謝します。 2バイト短くなる i%2 * 3 にすることができます!

返信を残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です