Crown hundred crownty crown
JavaScript (Node.js), 50 bytes
f=(n,p=1e3)=>n<p?(n+p+'').slice(1):'#'+f(n-p,p/10)
Try it online!
TIO was based on Arnauld's answer. Show as #
.
JavaScript (ES6), 62 46 44 bytes
Saved 2 bytes thanks to @nwellnhof
Outputs crowns as x
characters.
n=>(n+1e4+'').replace(/1+0/,'xxx').slice(-3)
Try it online!
How?
We add \$10000\$ to the input, coerce it to a string, look for the /1+0/
pattern and replace it with xxx
. Finally, we return the 3 trailing characters.
Examples:
$$\begin{align}&0 &\rightarrow &\text{ "}\color{red}{\text{10}}\text{000"} &\rightarrow &\text{ "xxx000"} &\rightarrow &\text{ "000"}\\ &123 &\rightarrow &\text{ "}\color{red}{\text{10}}\text{123"} &\rightarrow &\text{ "xxx123"} &\rightarrow &\text{ "123"}\\ &1023 &\rightarrow &\text{ "}\color{red}{\text{110}}\text{23"} &\rightarrow &\text{ "xxx23"} &\rightarrow &\text{ "x23"}\\ &1103 &\rightarrow &\text{ "}\color{red}{\text{1110}}\text{3"} &\rightarrow &\text{ "xxx3"} &\rightarrow &\text{ "xx3"}\\ &1110 &\rightarrow &\text{ "}\color{red}{\text{11110}}\text{"} &\rightarrow &\text{ "xxx"} &\rightarrow &\text{ "xxx"} \end{align} $$
Shakespeare Programming Language, 763 692 690 689 683 bytes
,.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.
Try it online!
Uses " "
instead of crowns. At the cost of 4 more bytes, this could be modified to show a "visible" character instead.
Explanation:
,.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).