クラウン百王冠


26

私は、特定のゲームが独特のライフカウンターを持っていた気づいたの代わりに停車の999次の番号だった- 、新しい数字を獲得したクラウン百か👑00。後に👑99来たクラウン百crownty👑👑0)と最後の番号は、後に👑👑9、だったクラウン百crowntyクラウン👑👑👑小数で1110年になり、。

あなたの仕事は、このカウンタを出力するプログラムまたは関数を書くことです。

範囲の整数[0,1110](両端を含む)を指定すると、3文字の文字列が出力されます。

  • すべてのキャラクターはリストからのものです 0123456789👑
  • クラウン(👑)は、左端のキャラクターとして、またはその左側にクラウンがある場合にのみ表示できます
  • この数が10進数として読み取られるが、クラウンがとしてカウントされる10場合、元の数に戻ります

テストケース

   0 → "000"
  15 → "015"
 179 → "179"
 999 → "999"
1000 → "👑00"
1097 → "👑97"
1100 → "👑👑0"
1108 → "👑👑8"
1110 → "👑👑👑"

クラウンの代わりに10進数以外の文字を使用できます。きれいに印刷するために、クラウン文字(UTF8バイトシーケンス "\ 240 \ 159 \ 145 \ 145")は4バイトではなく1バイトとしてカウントされます。プログラムは、有効範囲外の数値に対して機能する必要はありません。

これはであるため、バイト単位で測定した最短回答が勝ちです!


4
ああ、スーパーマリオ3Dランド!
デウソビ

2
@Deusovi私は実際にフォローアップゲームのスーパーマリオ3Dワールドについて考えていましたが、よく推測されました!
アンス

3
これは、Boaty McBoatFaceのIMO番号である必要があります。
ミスターリスター

ボーナスには、コードのクラウンの数が掛けられますよね?
エリックアウトゴルファー

3
@JeffZeitlinそれは冗長な10進数システムであり、数値は複数の表現を持つ場合があります(先行ゼロは無視されます)。クラウンはその後、絶対に必要な場合にのみ使用される驚きの要素として予約されています。
アンス

回答:


2

05AB1E20 18 バイト

₄‹i₄+¦ëTð.;„1 „  :

クラウンにスペースを使用します。

オンラインそれを試してみたり、すべてのテストケースを確認してください

説明:

₄‹i               # If the (implicit) input is smaller than 1000:
   ₄+             #  Add 1000 to the (implicit) input
     ¦            #  And remove the leading 1 (so the leading zeros are added)
                  #   i.e. 17 → 1017 → "017"
  ë               # Else:
   Tð.;           #  Replace the first "10" with a space " "
                  #   i.e. 1010 → " 10"
                  #   i.e. 1101 → "1 1"
                  #   i.e. 1110 → "11 "
       1   :    #  Replace every "1 " with "  " (until it no longer changes)
                  #   i.e. " 10" → " 10"
                  #   i.e. "1 1" → "  1"
                  #   i.e. "11 " → "   "


9

JavaScript(ES6)、 62 46  44バイト

@nwellnhofのおかげで2バイト節約

クラウンをxキャラクターとして出力します。

n=>(n+1e4+'').replace(/1+0/,'xxx').slice(-3)

オンラインでお試しください!

どうやって?

10000/1+0/xxx

例:

0 」10000 " 「xxx000」 「000」123 」10123 " 「xxx123」 「123」1023 」11023 " 「xxx23」 「x23」1103 」11103 " 「xxx3」 「xx3」1110 」11110 「xxx」 「xxx」


s.replace(/./g,`#`)はきちんとしています...私は持っていましたArray(s.length+1).join`#`、そして私の正規表現も長かったです!良い仕事、+ 1
Mr. Xcoder

@ Mr.Xcoder実際にはひどいアイデアでした。しかし、修正には1年以上かかりました。:D
アーナルド

8

シェークスピアプログラミング言語763 692 690 689 683バイト

,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Listen tothy!Ajax:You big big cat.Scene V:.Ajax:Remember the remainder of the quotient betweenI twice the sum ofa cat a big big cat.Ford:You be the quotient betweenyou twice the sum ofa cat a big big cat.Ajax:You be the sum ofyou a pig.Be you nicer zero?If solet usScene V.Ford:You big big cat.[Exit Ajax][Enter Page]Page:Recall.Ford:You be I.Scene X:.Page:Recall.Am I nicer zero?If notopen heart.If notlet usScene L.Ford:You big big big big big cat.Speak thy.Am I worse a cat?If soyou zero.Scene L:.[Exit Page][Enter Ajax]Ford:You be the sum ofyou a pig.Is you nicer a cat?[Exit Ajax][Enter Page]Ford:If solet usScene X.

オンラインでお試しください!

" "クラウンの代わりに使用します。さらに4バイトのコストで、これを代わりに「可視」文字を表示するように変更できます。

説明:

,.Ajax,.Ford,.Page,.Act I:.Scene I:.[Enter Ajax and Ford]

    Boilerplate, introducing the characters.

Ford:Listen tothy!

    Input a value to Ajax.

Ajax:You big big cat.

    Set Ford's value to 4 (we will be pushing 4 digits from Ajax onto Ford's personal stack).

Scene V:.Ajax:Remember the remainder of the quotient betweenI twice the sum ofa cat a big big cat.Ford:You be the quotient betweenyou twice the sum ofa cat a big big cat.

    DIGIT-PUSHING LOOP: Push Ajax's last digit onto Ford's stack; divide Ajax by 10.

Ajax:You be the sum ofyou a pig.Be you nicer zero?If solet usScene V.

    Decrement Ford; loop until Ford is 0.

Ford:You big big cat.

    Set Ajax's value to 4 (we will pop 3 digits from Ford's stack in the next loop).

[Exit Ajax][Enter Page]Page:Recall.Ford:You be I.

    Pop the top value off Ford's stack, and store that into Page.
    Here, Page will contain 0 if there are no crowns to be drawn,
    and 1 if there are crowns to be drawn.

Scene X:.Page:Recall.Am I nicer zero?If notopen heart.If notlet usScene L.

    DIGIT-DRAWING LOOP: Pop the top value off of Ford's stack and set Ford equal to that value.
    If there are no crowns to be drawn, output Ford's literal value here, and skip the crown-drawing section.

Ford:You big big big big big cat.Speak thy.Am I worse a cat?If soyou zero.

    Draw crown.
    If we are drawing crowns, and Ford contains 0 here, then we are now done drawing crowns, and thus we store 0 into Page.
    (Put in one more "big" for the crown to look like an @ symbol.)

Scene L:.[Exit Page][Enter Ajax]Ford:You be the sum ofyou a pig.Is you nicer a cat?[Exit Ajax][Enter Page]Ford:If solet usScene X.

    Decrement Ajax; loop until Ajax is 1 (i.e. 3 times).


@HelloGoodbyeありがとう、私はいくつかのスペースを取り除くのを忘れていました。
JosiahRyanW

5

Python 2、53バイト

-22バイトのArnauldへの脱帽。ただし、再帰は依然として勝ちます。

lambda k:re.sub("1+0","CCC",`k+10000`)[-3:]
import re

オンラインでお試しください!

Python 2バイト

代わりに、tshの再帰的メソッドを実装します。ovsのおかげで2バイト節約されました。

f=lambda n,p=1000:n/p and'C'+f(n-p,p/10)or`n+p`[1:]

オンラインでお試しください!


JS回答で行ったのと同じ方法で、最初のソリューションを更新することにより、54バイト。ただし、Pythonでは再帰が勝つようです。
アーナルド

1
@Arnauldありがとう:D。この編集は本当にSGITWでした
Xcoder氏

nwellnhofはそれ以来、10000を追加するとより単純なパターンになることを指摘しています1+0。したがって、この53バイトバージョン。
アーナウルド

@Arnauldありがとう;)それはかなり印象的です。
Xcoder氏


3

Retina 0.8.2、41バイト

\b((.)|..)\b
$#2$*00$&
T`d`_#`(?=....)1+0

オンラインでお試しください!#sの代わりに👑sを使用します。リンクにはテストケースが含まれます。説明:

\b((.)|..)\b
$#2$*00$&

1桁と2桁の数字を3桁に埋め込みます。

T`d`_#`(?=....)1+0

14桁の数字の先頭のsをsに変更し#、次を削除し0ます。


3

ゼリー、19 バイト -0 = 19

<ȷ¬ȧDi0ɓ⁶ẋ⁹Ḋ;+ȷDḊṫʋ

スペース文字をクラウンとして使用して結果を印刷する完全なプログラム。
(単項リンクとして、整数とスペース文字の混合リストが生成されます)

オンラインでお試しください!または、テストスイートを参照してください。

...おそらく再帰的な実装は短くなるでしょう。

どうやって?

<ȷ¬ȧDi0ɓ⁶ẋ⁹Ḋ;+ȷDḊṫʋ - Main Link: integer, N    e.g. 1010       or   10
 ȷ                  - literal 1000                  1000            1000
<                   - less than?                    0               1
  ¬                 - logical not                   1               0
    D               - to decimal list               [1,0,1,0]       [1,0]
   ȧ                - logical and                   [1,0,1,0]       0
      0             - literal zero                  0               0
     i              - first index - call this I     2               1  (0 treated as [0] by i)
       ɓ            - new dyadic chain with swapped arguments - i.e. f(N, I)
        ⁶           - literal space character       ' '             ' '
          ⁹         - chain's right argument        2               1
         ẋ          - repeat                        [' ',' ']       [' ']
           Ḋ        - dequeue                       [' ']           []
                  ʋ - last four links as a dyad - i.e. f(N, I)
             +ȷ     -   add 1000                    2010            1010
               D    -   to decimal list             [2,0,1,0]       [1,0,1,0]
                Ḋ   -   dequeue                     [0,1,0]         [0,1,0]
                 ṫ  -   tail from index (I)         [1,0]           [0,1,0]
            ;       - concatenate                   [' ',1,0]       [0,1,0]
                    - implicit print                " 10"           "010"


2

クリーン、87バイト

クラウンを出力しません(を使用c)。

import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ccc"+lpad(""<+n rem(10^i))i'0')%(i,9)

オンラインでお試しください!

$ n                   // function $ of `n`
 # i =                // define `i` as (the number of digits that aren't crowns)
  3 -                 // three minus
  n / 1000 -          // 1 if first digit is crown
  n / 1100 -          // 1 if second digit is crown
  n / 1110            // 1 if third digit is crown
 = (                  // the string formed by
  "ccc" +             // prefixing three crowns to
  lpad (              // the padding of
   "" <+ n rem (10^i) // non-crown digits of `n`
  ) i '0'             // with zeroes
 ) % (i, 9)           // and removing the extra crowns

クリーン、99-3 = 96バイト

これには王冠があります。

import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("👑👑👑"+lpad(""<+n rem(10^i))i'0')%(i*4,99)

オンラインでお試しください!


第二の答えは90のスコアを持っている
pppery


1

Java 10、84 83バイト

n->{for(int p=100,t;p>0;n-=t%12*p,p/=10)System.out.printf("%c",t=n/p>9?46:48+n/p);}

@tsh 'Cのコメントのポート。
用途.クラウンの代わりにます。

オンラインでお試しください。

代替アプローチ(84(87-3)バイト):

n->f(n,1000)String f(int n,int p){return n<p?(n+p+"").substring(1):"👑"+f(n-p,p/10);}

Port of @tsh 'JavaScript's answer

オンラインでお試しください。


1

APL(Dyalog Unicode)、32バイト

1e3∘{⍵<⍺:1↓⍕⍵+⍺⋄'C',(⍵-⍺)∇⍨⍺÷10}

オンラインでお試しください!

プレフィックス直接機能。

@tshのJSアンサーのポート。

どうやって:

1e3∘{⍵<⍺:1↓⍕⍵+⍺⋄'C',(⍵-⍺)∇⍨⍺÷10}  Main function, arguments  and  (⍵  input,   1000).
     ⍵<⍺:                           If ⍵<⍺
         1                         Drop (↓) the first element (1) of
                                   Format (⍕); 'stringify'
            ⍵+⍺                     ⍵+⍺
                                   else
                'C',                Concatenate (,) the literal 'C' with
                         ∇⍨         Recursive call (∇) with swapped arguments (⍨)
                    (⍵-⍺)  ⍺÷10     New arguments;   ⍵-⍺;   ⍺÷10






0

クリーン96バイト

Super Mario 3D Land、New Super Mao Bros.2、Super Mario 3D Worldにはこのライフカウンターがあると思います。

import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("👑👑👑"+lpad(""<+n rem(10^i))i'0')%(i*4,99

Cleanに同意します。

浮気していないことを確認してください。


3
サイトへようこそ。これは何語ですか?
ウィートウィザード
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.