皇冠百冠皇冠


26

我注意到某个游戏有一个奇特的寿命计数器,而不是停在这999,获得了新的数字-在未来数百元👑00。之后👑99来到冠百个crownty👑👑0)和最后一个号码,之后👑👑9,被冠百crownty冠👑👑👑,这将是1110十进制。

你的任务是写一个程序或功能输出这个计数器。

给定范围内的整数[0,1110](包括两端),输出三个字符串,其中

  • 每个字符都来自列表 0123456789👑
  • 冠(👑)只能显示为最左侧的字符,也可以显示为左侧的冠
  • 当此数字读取为十进制数字,但冠冕计数为时10,您将获得原始数字

测试用例

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

您可以使用任何非十进制字符代替冠。为了鼓励漂亮地打印,冠字符(UTF8字节序列“ \ 240 \ 159 \ 145 \ 145”)算作一个字节而不是四个字节。您的程序不必处理超出有效范围的数字。

这是,因此最短的答案(以字节为单位)会胜出!


4
哦,超级马里奥3D土地!
Deusovi

2
@Deusovi我实际上是在考虑后续游戏《超级马里奥3D世界》,但很好猜!
Angs

3
这应该是Boaty McBoatFace的IMO号。
李斯特先生,

奖金乘以代码中的冠数,对不对?
Erik the Outgolfer

3
@JeffZeitlin这是一个冗余的十进制系统,其中一个数字可能具有多个表示形式(甚至不考虑前导零)。然后将表冠保留为惊喜元素,仅在绝对需要时使用。
昂斯

Answers:


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。最后,我们返回3个尾随字符。

例子:

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`#`,我的正则表达式也更长了!
做得好

@ Mr.Xcoder这实际上是一个可怕的想法。但是修复它花了一年多的时间。:D
Arnauld

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个字节。递归仍然是成功的。

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

在线尝试!

Python 2,51个字节

相反,它实现了tsh的递归方法。由于ovs,节省了2个字节。

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

在线尝试!


通过更新第一个解决方案获得54个字节,方法与我对JS答案所做的相同。不过,似乎递归仍然在Python中胜出。
Arnauld

1
@Arnauld谢谢:D。此编辑确实是SGITW
Xcoder先生,

此后nwellnhof指出加10000会导致更简单的模式1+0。因此,此53字节版本。
Arnauld

@Arnauld谢谢;)令人印象深刻。
Xcoder先生,


3

视网膜0.8.2,41字节

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

在线尝试!使用#s代替👑s。链接包括测试用例。说明:

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

将1位和2位数字填充到三位数字。

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

1将4位数的前导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

Japt,20个字节

天真的(而且有点醉!)Arnauld的解决方案。用途"为冠。

U+A³ s r"^21*0"_çQÃÅ

试试吧



1

APL(Dyalog Unicode),32字节

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

在线尝试!

前缀直接功能。

@tsh的JS Answer的端口。

怎么样:

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

1

PHP,71字节

for($n=$argn,$x=1e4;1<$x/=10;$n%=$n<$x?$x/10:$x)echo$n<$x?$n/$x*10|0:C;

打印C冠冕。与管道一起运行-nR在线尝试



1

C, 84  58字节

感谢@tsh保存25个字节,感谢@ceilingcat保存一个字节!

f(n,p){for(p=1e3;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;}

在线尝试!


1
f(n,p){for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;}
tsh



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
欢迎来到该网站。这是什么语言?
小麦巫师
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.