Crown hundred crownty crown
Clash Royale CLAN TAG#URR8PPP
up vote
21
down vote
favorite
I noticed a certain game had a peculiar life counter, which instead of stopping at 999
, gained a new digit â the next number was crown hundred or ðÂÂÂ00
. After ðÂÂÂ99
came crown hundred crownty (ðÂÂÂðÂÂÂ0
) and the last number, after ðÂÂÂðÂÂÂ9
, was crown hundred crownty crown or ðÂÂÂðÂÂÂðÂÂÂ
, which would be 1110 in decimal.
Your task is to write a program or a function that outputs this counter.
Given an integer from the range [0,1110]
(inclusive on both ends), output a three character string where
- every character is from the list
0123456789ðÂÂÂ
- the crown (ðÂÂÂ) can only appear as the leftmost character or when there's a crown to the left of it
- when this number is read as a decimal number but with the crown counting as
10
, you get back the original number
Test cases
0 â "000"
15 â "015"
179 â "179"
999 â "999"
1000 â "ðÂÂÂ00"
1097 â "ðÂÂÂ97"
1100 â "ðÂÂÂðÂÂÂ0"
1108 â "ðÂÂÂðÂÂÂ8"
1110 â "ðÂÂÂðÂÂÂðÂÂÂ"
You may use any non-decimal character instead of the crown. To encourage pretty printing, the crown character (UTF8 byte sequence "240159145145") counts as one byte instead of four. Your program doesn't have to work for numbers outside the valid range.
This is code-golf, so the shortest answer, measured in bytes, wins!
code-golf number integer conversion
 |Â
show 5 more comments
up vote
21
down vote
favorite
I noticed a certain game had a peculiar life counter, which instead of stopping at 999
, gained a new digit â the next number was crown hundred or ðÂÂÂ00
. After ðÂÂÂ99
came crown hundred crownty (ðÂÂÂðÂÂÂ0
) and the last number, after ðÂÂÂðÂÂÂ9
, was crown hundred crownty crown or ðÂÂÂðÂÂÂðÂÂÂ
, which would be 1110 in decimal.
Your task is to write a program or a function that outputs this counter.
Given an integer from the range [0,1110]
(inclusive on both ends), output a three character string where
- every character is from the list
0123456789ðÂÂÂ
- the crown (ðÂÂÂ) can only appear as the leftmost character or when there's a crown to the left of it
- when this number is read as a decimal number but with the crown counting as
10
, you get back the original number
Test cases
0 â "000"
15 â "015"
179 â "179"
999 â "999"
1000 â "ðÂÂÂ00"
1097 â "ðÂÂÂ97"
1100 â "ðÂÂÂðÂÂÂ0"
1108 â "ðÂÂÂðÂÂÂ8"
1110 â "ðÂÂÂðÂÂÂðÂÂÂ"
You may use any non-decimal character instead of the crown. To encourage pretty printing, the crown character (UTF8 byte sequence "240159145145") counts as one byte instead of four. Your program doesn't have to work for numbers outside the valid range.
This is code-golf, so the shortest answer, measured in bytes, wins!
code-golf number integer conversion
3
Oh, Super Mario 3D Land!
â Deusovi
Sep 8 at 9:38
1
@Deusovi I was actually thinking about the follow-up game, Super Mario 3D World, but well guessed!
â Angs
Sep 8 at 10:00
2
This should be the IMO number for Boaty McBoatFace.
â Mr Lister
Sep 8 at 11:19
The bonus is multiplied by the number of crowns in the code, right?
â Erik the Outgolfer
Sep 8 at 14:13
3
@JeffZeitlin it's a redundant decimal system, where a number may have more than one representation (even disregarding leading zeroes). The crown is then reserved as a surprise element, only used when absolutely needed.
â Angs
Sep 8 at 20:32
 |Â
show 5 more comments
up vote
21
down vote
favorite
up vote
21
down vote
favorite
I noticed a certain game had a peculiar life counter, which instead of stopping at 999
, gained a new digit â the next number was crown hundred or ðÂÂÂ00
. After ðÂÂÂ99
came crown hundred crownty (ðÂÂÂðÂÂÂ0
) and the last number, after ðÂÂÂðÂÂÂ9
, was crown hundred crownty crown or ðÂÂÂðÂÂÂðÂÂÂ
, which would be 1110 in decimal.
Your task is to write a program or a function that outputs this counter.
Given an integer from the range [0,1110]
(inclusive on both ends), output a three character string where
- every character is from the list
0123456789ðÂÂÂ
- the crown (ðÂÂÂ) can only appear as the leftmost character or when there's a crown to the left of it
- when this number is read as a decimal number but with the crown counting as
10
, you get back the original number
Test cases
0 â "000"
15 â "015"
179 â "179"
999 â "999"
1000 â "ðÂÂÂ00"
1097 â "ðÂÂÂ97"
1100 â "ðÂÂÂðÂÂÂ0"
1108 â "ðÂÂÂðÂÂÂ8"
1110 â "ðÂÂÂðÂÂÂðÂÂÂ"
You may use any non-decimal character instead of the crown. To encourage pretty printing, the crown character (UTF8 byte sequence "240159145145") counts as one byte instead of four. Your program doesn't have to work for numbers outside the valid range.
This is code-golf, so the shortest answer, measured in bytes, wins!
code-golf number integer conversion
I noticed a certain game had a peculiar life counter, which instead of stopping at 999
, gained a new digit â the next number was crown hundred or ðÂÂÂ00
. After ðÂÂÂ99
came crown hundred crownty (ðÂÂÂðÂÂÂ0
) and the last number, after ðÂÂÂðÂÂÂ9
, was crown hundred crownty crown or ðÂÂÂðÂÂÂðÂÂÂ
, which would be 1110 in decimal.
Your task is to write a program or a function that outputs this counter.
Given an integer from the range [0,1110]
(inclusive on both ends), output a three character string where
- every character is from the list
0123456789ðÂÂÂ
- the crown (ðÂÂÂ) can only appear as the leftmost character or when there's a crown to the left of it
- when this number is read as a decimal number but with the crown counting as
10
, you get back the original number
Test cases
0 â "000"
15 â "015"
179 â "179"
999 â "999"
1000 â "ðÂÂÂ00"
1097 â "ðÂÂÂ97"
1100 â "ðÂÂÂðÂÂÂ0"
1108 â "ðÂÂÂðÂÂÂ8"
1110 â "ðÂÂÂðÂÂÂðÂÂÂ"
You may use any non-decimal character instead of the crown. To encourage pretty printing, the crown character (UTF8 byte sequence "240159145145") counts as one byte instead of four. Your program doesn't have to work for numbers outside the valid range.
This is code-golf, so the shortest answer, measured in bytes, wins!
code-golf number integer conversion
code-golf number integer conversion
edited Sep 8 at 15:38
asked Sep 8 at 8:10
Angs
3,8442535
3,8442535
3
Oh, Super Mario 3D Land!
â Deusovi
Sep 8 at 9:38
1
@Deusovi I was actually thinking about the follow-up game, Super Mario 3D World, but well guessed!
â Angs
Sep 8 at 10:00
2
This should be the IMO number for Boaty McBoatFace.
â Mr Lister
Sep 8 at 11:19
The bonus is multiplied by the number of crowns in the code, right?
â Erik the Outgolfer
Sep 8 at 14:13
3
@JeffZeitlin it's a redundant decimal system, where a number may have more than one representation (even disregarding leading zeroes). The crown is then reserved as a surprise element, only used when absolutely needed.
â Angs
Sep 8 at 20:32
 |Â
show 5 more comments
3
Oh, Super Mario 3D Land!
â Deusovi
Sep 8 at 9:38
1
@Deusovi I was actually thinking about the follow-up game, Super Mario 3D World, but well guessed!
â Angs
Sep 8 at 10:00
2
This should be the IMO number for Boaty McBoatFace.
â Mr Lister
Sep 8 at 11:19
The bonus is multiplied by the number of crowns in the code, right?
â Erik the Outgolfer
Sep 8 at 14:13
3
@JeffZeitlin it's a redundant decimal system, where a number may have more than one representation (even disregarding leading zeroes). The crown is then reserved as a surprise element, only used when absolutely needed.
â Angs
Sep 8 at 20:32
3
3
Oh, Super Mario 3D Land!
â Deusovi
Sep 8 at 9:38
Oh, Super Mario 3D Land!
â Deusovi
Sep 8 at 9:38
1
1
@Deusovi I was actually thinking about the follow-up game, Super Mario 3D World, but well guessed!
â Angs
Sep 8 at 10:00
@Deusovi I was actually thinking about the follow-up game, Super Mario 3D World, but well guessed!
â Angs
Sep 8 at 10:00
2
2
This should be the IMO number for Boaty McBoatFace.
â Mr Lister
Sep 8 at 11:19
This should be the IMO number for Boaty McBoatFace.
â Mr Lister
Sep 8 at 11:19
The bonus is multiplied by the number of crowns in the code, right?
â Erik the Outgolfer
Sep 8 at 14:13
The bonus is multiplied by the number of crowns in the code, right?
â Erik the Outgolfer
Sep 8 at 14:13
3
3
@JeffZeitlin it's a redundant decimal system, where a number may have more than one representation (even disregarding leading zeroes). The crown is then reserved as a surprise element, only used when absolutely needed.
â Angs
Sep 8 at 20:32
@JeffZeitlin it's a redundant decimal system, where a number may have more than one representation (even disregarding leading zeroes). The crown is then reserved as a surprise element, only used when absolutely needed.
â Angs
Sep 8 at 20:32
 |Â
show 5 more comments
14 Answers
14
active
oldest
votes
up vote
11
down vote
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 #
.
3
Nice recursive approach!
â Arnauld
Sep 8 at 9:43
add a comment |Â
up vote
7
down vote
JavaScript (ES6), 62 bytes
Outputs crowns as x
characters.
n=>(n+1e3+'').replace(/^21*0/,s=>s.replace(/./g,`x`)).slice(1)
Try it online!
How?
We add $1000$ to the input, coerce it to a string, look for the /^21*0/
pattern and replace each matching character with x
. Finally, we remove the leading character.
Examples:
$$beginalign&0 &rightarrow &text "1000" &rightarrow &text "1000" &rightarrow &text "000"\
&123 &rightarrow &text "1123" &rightarrow &text "1123" &rightarrow &text "123"\
&1023 &rightarrow &text "colorredtext20text23" &rightarrow &text "xx23" &rightarrow &text "x23"\
&1103 &rightarrow &text "colorredtext210text3" &rightarrow &text "xxx3" &rightarrow &text "xx3"\
&1110 &rightarrow &text "colorredtext2110text" &rightarrow &text "xxxx" &rightarrow &text "xxx"
endalign
$$
s.replace(/./g,`#`)
is neat... I hadArray(s.length+1).join`#`
, and my regex was longer too! Nice work, +1
â Mr. Xcoder
Sep 8 at 9:23
add a comment |Â
up vote
7
down vote
Shakespeare Programming Language, 763 692 690 689 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Ajax:You be the sum of you 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 of you 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a 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 of you 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 of you 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).
add a comment |Â
up vote
4
down vote
Python 2, 75 bytes
Shamelessly steals Arnauld's regex. Uses C
as crown.
lambda k:re.sub("^21*0",lambda g:len(g.group())*"C",`k+1000`)[1:]
import re
Try it online!
Python 2, 51 bytes
This instead implements tsh's recursive method. Saved 2 bytes thanks to ovs.
f=lambda n,p=1000:n/p and'C'+f(n-p,p/10)or`n+p`[1:]
Try it online!
add a comment |Â
up vote
3
down vote
Retina 0.8.2, 41 bytes
b((.)|..)b
$#2$*00$&
T`d`_#`(?=....)1+0
Try it online! Uses #
s instead of ðÂÂÂ
s. Link includes test cases. Explanation:
b((.)|..)b
$#2$*00$&
Pad 1- and 2-digit numbers to three digits.
T`d`_#`(?=....)1+0
Change leading 1
s of 4-digit numbers to #
s and delete the next 0
.
add a comment |Â
up vote
2
down vote
Clean, 87 bytes
Doesn't output crowns (uses c
).
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ccc"+lpad(""<+n rem(10^i))i'0')%(i,9)
Try it online!
$ 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
Clean, 99 - 3 = 96 bytes
This one has crowns.
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ðÂÂÂðÂÂÂðÂÂÂ"+lpad(""<+n rem(10^i))i'0')%(i*4,99)
Try it online!
add a comment |Â
up vote
2
down vote
Jelly, 19 bytes - 0 = 19
<÷ìçDi0ÃÂâ¶áºÂâ¹á¸Â;+÷Dá¸ÂṫÃÂ
A full program printing the result using a space character as the crown.
(As a monadic Link a mixed list of integer digits and space characters is yielded)
Try it online! Or see the test-suite.
...maybe a recursive implementation will be shorter.
How?
<÷ìç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"
add a comment |Â
up vote
2
down vote
Python 2, 52 bytes
lambda n:['%03d'%n,'%3s'%`n`.lstrip('1')[1:]][n>999]
Try it online!
add a comment |Â
up vote
1
down vote
C, 84 bytes
f(n,k)k=3-n/1000-n/1100-n/1110;printf(k?"%s%0*d":"%s","CCC"+k,k,n%(int)pow(10,k));
Try it online!
1
f(n,p)for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;
â tsh
Sep 8 at 16:54
add a comment |Â
up vote
1
down vote
Japt, 20 bytes
A naïve (and slightly drunk!) port of Arnauld's solution. Uses "
for crown.
U+Aó s r"^21*0"_çQÃÂÃÂ
Try it
add a comment |Â
up vote
1
down vote
Java 10, 84 83 bytes
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);
Port of @tsh' C comment.
Uses .
instead of crowns.
Try it online.
Alternative approach (84 (87-3) bytes):
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.
Try it online.
add a comment |Â
up vote
1
down vote
05AB1E, 20 18 bytes
âÂÂâ¹iâÂÂ+æëTð.;âÂÂ1 â :
Uses spaces for crowns.
Try it online or verify all test cases.
Explanation:
âÂÂâ¹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 " â " "
add a comment |Â
up vote
1
down vote
APL (Dyalog Unicode), 32 bytes
1e3âÂÂâµ<âº:1âÂÂâÂÂâµ+âºâÂÂ'C',(âµ-âº)âÂÂâ¨âº÷10
Try it online!
Prefix direct function.
Port of @tsh's JS Answer.
How:
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
add a comment |Â
up vote
1
down vote
PHP, 71 bytes
for($n=$argn,$x=1e4;1<$x/=10;$n%=$n<$x?$x/10:$x)echo$n<$x?$n/$x*10|0:C;
prints C
for the crown. Run as pipe with -nR
or try it online.
add a comment |Â
14 Answers
14
active
oldest
votes
14 Answers
14
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
11
down vote
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 #
.
3
Nice recursive approach!
â Arnauld
Sep 8 at 9:43
add a comment |Â
up vote
11
down vote
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 #
.
3
Nice recursive approach!
â Arnauld
Sep 8 at 9:43
add a comment |Â
up vote
11
down vote
up vote
11
down vote
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 (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 #
.
answered Sep 8 at 9:37
tsh
7,26311143
7,26311143
3
Nice recursive approach!
â Arnauld
Sep 8 at 9:43
add a comment |Â
3
Nice recursive approach!
â Arnauld
Sep 8 at 9:43
3
3
Nice recursive approach!
â Arnauld
Sep 8 at 9:43
Nice recursive approach!
â Arnauld
Sep 8 at 9:43
add a comment |Â
up vote
7
down vote
JavaScript (ES6), 62 bytes
Outputs crowns as x
characters.
n=>(n+1e3+'').replace(/^21*0/,s=>s.replace(/./g,`x`)).slice(1)
Try it online!
How?
We add $1000$ to the input, coerce it to a string, look for the /^21*0/
pattern and replace each matching character with x
. Finally, we remove the leading character.
Examples:
$$beginalign&0 &rightarrow &text "1000" &rightarrow &text "1000" &rightarrow &text "000"\
&123 &rightarrow &text "1123" &rightarrow &text "1123" &rightarrow &text "123"\
&1023 &rightarrow &text "colorredtext20text23" &rightarrow &text "xx23" &rightarrow &text "x23"\
&1103 &rightarrow &text "colorredtext210text3" &rightarrow &text "xxx3" &rightarrow &text "xx3"\
&1110 &rightarrow &text "colorredtext2110text" &rightarrow &text "xxxx" &rightarrow &text "xxx"
endalign
$$
s.replace(/./g,`#`)
is neat... I hadArray(s.length+1).join`#`
, and my regex was longer too! Nice work, +1
â Mr. Xcoder
Sep 8 at 9:23
add a comment |Â
up vote
7
down vote
JavaScript (ES6), 62 bytes
Outputs crowns as x
characters.
n=>(n+1e3+'').replace(/^21*0/,s=>s.replace(/./g,`x`)).slice(1)
Try it online!
How?
We add $1000$ to the input, coerce it to a string, look for the /^21*0/
pattern and replace each matching character with x
. Finally, we remove the leading character.
Examples:
$$beginalign&0 &rightarrow &text "1000" &rightarrow &text "1000" &rightarrow &text "000"\
&123 &rightarrow &text "1123" &rightarrow &text "1123" &rightarrow &text "123"\
&1023 &rightarrow &text "colorredtext20text23" &rightarrow &text "xx23" &rightarrow &text "x23"\
&1103 &rightarrow &text "colorredtext210text3" &rightarrow &text "xxx3" &rightarrow &text "xx3"\
&1110 &rightarrow &text "colorredtext2110text" &rightarrow &text "xxxx" &rightarrow &text "xxx"
endalign
$$
s.replace(/./g,`#`)
is neat... I hadArray(s.length+1).join`#`
, and my regex was longer too! Nice work, +1
â Mr. Xcoder
Sep 8 at 9:23
add a comment |Â
up vote
7
down vote
up vote
7
down vote
JavaScript (ES6), 62 bytes
Outputs crowns as x
characters.
n=>(n+1e3+'').replace(/^21*0/,s=>s.replace(/./g,`x`)).slice(1)
Try it online!
How?
We add $1000$ to the input, coerce it to a string, look for the /^21*0/
pattern and replace each matching character with x
. Finally, we remove the leading character.
Examples:
$$beginalign&0 &rightarrow &text "1000" &rightarrow &text "1000" &rightarrow &text "000"\
&123 &rightarrow &text "1123" &rightarrow &text "1123" &rightarrow &text "123"\
&1023 &rightarrow &text "colorredtext20text23" &rightarrow &text "xx23" &rightarrow &text "x23"\
&1103 &rightarrow &text "colorredtext210text3" &rightarrow &text "xxx3" &rightarrow &text "xx3"\
&1110 &rightarrow &text "colorredtext2110text" &rightarrow &text "xxxx" &rightarrow &text "xxx"
endalign
$$
JavaScript (ES6), 62 bytes
Outputs crowns as x
characters.
n=>(n+1e3+'').replace(/^21*0/,s=>s.replace(/./g,`x`)).slice(1)
Try it online!
How?
We add $1000$ to the input, coerce it to a string, look for the /^21*0/
pattern and replace each matching character with x
. Finally, we remove the leading character.
Examples:
$$beginalign&0 &rightarrow &text "1000" &rightarrow &text "1000" &rightarrow &text "000"\
&123 &rightarrow &text "1123" &rightarrow &text "1123" &rightarrow &text "123"\
&1023 &rightarrow &text "colorredtext20text23" &rightarrow &text "xx23" &rightarrow &text "x23"\
&1103 &rightarrow &text "colorredtext210text3" &rightarrow &text "xxx3" &rightarrow &text "xx3"\
&1110 &rightarrow &text "colorredtext2110text" &rightarrow &text "xxxx" &rightarrow &text "xxx"
endalign
$$
edited Sep 8 at 10:26
answered Sep 8 at 9:16
Arnauld
64.6k580274
64.6k580274
s.replace(/./g,`#`)
is neat... I hadArray(s.length+1).join`#`
, and my regex was longer too! Nice work, +1
â Mr. Xcoder
Sep 8 at 9:23
add a comment |Â
s.replace(/./g,`#`)
is neat... I hadArray(s.length+1).join`#`
, and my regex was longer too! Nice work, +1
â Mr. Xcoder
Sep 8 at 9:23
s.replace(/./g,`#`)
is neat... I had Array(s.length+1).join`#`
, and my regex was longer too! Nice work, +1â Mr. Xcoder
Sep 8 at 9:23
s.replace(/./g,`#`)
is neat... I had Array(s.length+1).join`#`
, and my regex was longer too! Nice work, +1â Mr. Xcoder
Sep 8 at 9:23
add a comment |Â
up vote
7
down vote
Shakespeare Programming Language, 763 692 690 689 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Ajax:You be the sum of you 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 of you 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a 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 of you 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 of you 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).
add a comment |Â
up vote
7
down vote
Shakespeare Programming Language, 763 692 690 689 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Ajax:You be the sum of you 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 of you 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a 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 of you 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 of you 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).
add a comment |Â
up vote
7
down vote
up vote
7
down vote
Shakespeare Programming Language, 763 692 690 689 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Ajax:You be the sum of you 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 of you 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a 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 of you 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 of you 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).
Shakespeare Programming Language, 763 692 690 689 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a cat a big big cat.Ajax:You be the sum of you 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 of you 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 between I twice the sum of a cat a big big cat.Ford:You be the quotient between you twice the sum of a 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 of you 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 of you 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).
edited Sep 9 at 20:03
answered Sep 9 at 4:23
JosiahRyanW
4316
4316
add a comment |Â
add a comment |Â
up vote
4
down vote
Python 2, 75 bytes
Shamelessly steals Arnauld's regex. Uses C
as crown.
lambda k:re.sub("^21*0",lambda g:len(g.group())*"C",`k+1000`)[1:]
import re
Try it online!
Python 2, 51 bytes
This instead implements tsh's recursive method. Saved 2 bytes thanks to ovs.
f=lambda n,p=1000:n/p and'C'+f(n-p,p/10)or`n+p`[1:]
Try it online!
add a comment |Â
up vote
4
down vote
Python 2, 75 bytes
Shamelessly steals Arnauld's regex. Uses C
as crown.
lambda k:re.sub("^21*0",lambda g:len(g.group())*"C",`k+1000`)[1:]
import re
Try it online!
Python 2, 51 bytes
This instead implements tsh's recursive method. Saved 2 bytes thanks to ovs.
f=lambda n,p=1000:n/p and'C'+f(n-p,p/10)or`n+p`[1:]
Try it online!
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Python 2, 75 bytes
Shamelessly steals Arnauld's regex. Uses C
as crown.
lambda k:re.sub("^21*0",lambda g:len(g.group())*"C",`k+1000`)[1:]
import re
Try it online!
Python 2, 51 bytes
This instead implements tsh's recursive method. Saved 2 bytes thanks to ovs.
f=lambda n,p=1000:n/p and'C'+f(n-p,p/10)or`n+p`[1:]
Try it online!
Python 2, 75 bytes
Shamelessly steals Arnauld's regex. Uses C
as crown.
lambda k:re.sub("^21*0",lambda g:len(g.group())*"C",`k+1000`)[1:]
import re
Try it online!
Python 2, 51 bytes
This instead implements tsh's recursive method. Saved 2 bytes thanks to ovs.
f=lambda n,p=1000:n/p and'C'+f(n-p,p/10)or`n+p`[1:]
Try it online!
edited Sep 8 at 17:48
answered Sep 8 at 9:41
Mr. Xcoder
30.5k758194
30.5k758194
add a comment |Â
add a comment |Â
up vote
3
down vote
Retina 0.8.2, 41 bytes
b((.)|..)b
$#2$*00$&
T`d`_#`(?=....)1+0
Try it online! Uses #
s instead of ðÂÂÂ
s. Link includes test cases. Explanation:
b((.)|..)b
$#2$*00$&
Pad 1- and 2-digit numbers to three digits.
T`d`_#`(?=....)1+0
Change leading 1
s of 4-digit numbers to #
s and delete the next 0
.
add a comment |Â
up vote
3
down vote
Retina 0.8.2, 41 bytes
b((.)|..)b
$#2$*00$&
T`d`_#`(?=....)1+0
Try it online! Uses #
s instead of ðÂÂÂ
s. Link includes test cases. Explanation:
b((.)|..)b
$#2$*00$&
Pad 1- and 2-digit numbers to three digits.
T`d`_#`(?=....)1+0
Change leading 1
s of 4-digit numbers to #
s and delete the next 0
.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Retina 0.8.2, 41 bytes
b((.)|..)b
$#2$*00$&
T`d`_#`(?=....)1+0
Try it online! Uses #
s instead of ðÂÂÂ
s. Link includes test cases. Explanation:
b((.)|..)b
$#2$*00$&
Pad 1- and 2-digit numbers to three digits.
T`d`_#`(?=....)1+0
Change leading 1
s of 4-digit numbers to #
s and delete the next 0
.
Retina 0.8.2, 41 bytes
b((.)|..)b
$#2$*00$&
T`d`_#`(?=....)1+0
Try it online! Uses #
s instead of ðÂÂÂ
s. Link includes test cases. Explanation:
b((.)|..)b
$#2$*00$&
Pad 1- and 2-digit numbers to three digits.
T`d`_#`(?=....)1+0
Change leading 1
s of 4-digit numbers to #
s and delete the next 0
.
answered Sep 8 at 11:32
Neil
75.6k744170
75.6k744170
add a comment |Â
add a comment |Â
up vote
2
down vote
Clean, 87 bytes
Doesn't output crowns (uses c
).
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ccc"+lpad(""<+n rem(10^i))i'0')%(i,9)
Try it online!
$ 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
Clean, 99 - 3 = 96 bytes
This one has crowns.
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ðÂÂÂðÂÂÂðÂÂÂ"+lpad(""<+n rem(10^i))i'0')%(i*4,99)
Try it online!
add a comment |Â
up vote
2
down vote
Clean, 87 bytes
Doesn't output crowns (uses c
).
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ccc"+lpad(""<+n rem(10^i))i'0')%(i,9)
Try it online!
$ 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
Clean, 99 - 3 = 96 bytes
This one has crowns.
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ðÂÂÂðÂÂÂðÂÂÂ"+lpad(""<+n rem(10^i))i'0')%(i*4,99)
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Clean, 87 bytes
Doesn't output crowns (uses c
).
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ccc"+lpad(""<+n rem(10^i))i'0')%(i,9)
Try it online!
$ 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
Clean, 99 - 3 = 96 bytes
This one has crowns.
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ðÂÂÂðÂÂÂðÂÂÂ"+lpad(""<+n rem(10^i))i'0')%(i*4,99)
Try it online!
Clean, 87 bytes
Doesn't output crowns (uses c
).
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ccc"+lpad(""<+n rem(10^i))i'0')%(i,9)
Try it online!
$ 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
Clean, 99 - 3 = 96 bytes
This one has crowns.
import StdEnv,Text
$n#i=3-n/1000-n/1100-n/1110
=("ðÂÂÂðÂÂÂðÂÂÂ"+lpad(""<+n rem(10^i))i'0')%(i*4,99)
Try it online!
edited Sep 8 at 9:01
answered Sep 8 at 8:50
ÃÂurous
5,32311031
5,32311031
add a comment |Â
add a comment |Â
up vote
2
down vote
Jelly, 19 bytes - 0 = 19
<÷ìçDi0ÃÂâ¶áºÂâ¹á¸Â;+÷Dá¸ÂṫÃÂ
A full program printing the result using a space character as the crown.
(As a monadic Link a mixed list of integer digits and space characters is yielded)
Try it online! Or see the test-suite.
...maybe a recursive implementation will be shorter.
How?
<÷ìç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"
add a comment |Â
up vote
2
down vote
Jelly, 19 bytes - 0 = 19
<÷ìçDi0ÃÂâ¶áºÂâ¹á¸Â;+÷Dá¸ÂṫÃÂ
A full program printing the result using a space character as the crown.
(As a monadic Link a mixed list of integer digits and space characters is yielded)
Try it online! Or see the test-suite.
...maybe a recursive implementation will be shorter.
How?
<÷ìç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"
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Jelly, 19 bytes - 0 = 19
<÷ìçDi0ÃÂâ¶áºÂâ¹á¸Â;+÷Dá¸ÂṫÃÂ
A full program printing the result using a space character as the crown.
(As a monadic Link a mixed list of integer digits and space characters is yielded)
Try it online! Or see the test-suite.
...maybe a recursive implementation will be shorter.
How?
<÷ìç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"
Jelly, 19 bytes - 0 = 19
<÷ìçDi0ÃÂâ¶áºÂâ¹á¸Â;+÷Dá¸ÂṫÃÂ
A full program printing the result using a space character as the crown.
(As a monadic Link a mixed list of integer digits and space characters is yielded)
Try it online! Or see the test-suite.
...maybe a recursive implementation will be shorter.
How?
<÷ìç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"
edited Sep 8 at 14:26
answered Sep 8 at 14:09
Jonathan Allan
48.4k534159
48.4k534159
add a comment |Â
add a comment |Â
up vote
2
down vote
Python 2, 52 bytes
lambda n:['%03d'%n,'%3s'%`n`.lstrip('1')[1:]][n>999]
Try it online!
add a comment |Â
up vote
2
down vote
Python 2, 52 bytes
lambda n:['%03d'%n,'%3s'%`n`.lstrip('1')[1:]][n>999]
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Python 2, 52 bytes
lambda n:['%03d'%n,'%3s'%`n`.lstrip('1')[1:]][n>999]
Try it online!
Python 2, 52 bytes
lambda n:['%03d'%n,'%3s'%`n`.lstrip('1')[1:]][n>999]
Try it online!
edited Sep 8 at 18:49
answered Sep 8 at 18:08
ovs
17.5k21058
17.5k21058
add a comment |Â
add a comment |Â
up vote
1
down vote
C, 84 bytes
f(n,k)k=3-n/1000-n/1100-n/1110;printf(k?"%s%0*d":"%s","CCC"+k,k,n%(int)pow(10,k));
Try it online!
1
f(n,p)for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;
â tsh
Sep 8 at 16:54
add a comment |Â
up vote
1
down vote
C, 84 bytes
f(n,k)k=3-n/1000-n/1100-n/1110;printf(k?"%s%0*d":"%s","CCC"+k,k,n%(int)pow(10,k));
Try it online!
1
f(n,p)for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;
â tsh
Sep 8 at 16:54
add a comment |Â
up vote
1
down vote
up vote
1
down vote
C, 84 bytes
f(n,k)k=3-n/1000-n/1100-n/1110;printf(k?"%s%0*d":"%s","CCC"+k,k,n%(int)pow(10,k));
Try it online!
C, 84 bytes
f(n,k)k=3-n/1000-n/1100-n/1110;printf(k?"%s%0*d":"%s","CCC"+k,k,n%(int)pow(10,k));
Try it online!
answered Sep 8 at 14:09
Steadybox
14.7k32578
14.7k32578
1
f(n,p)for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;
â tsh
Sep 8 at 16:54
add a comment |Â
1
f(n,p)for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;
â tsh
Sep 8 at 16:54
1
1
f(n,p)for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;
â tsh
Sep 8 at 16:54
f(n,p)for(p=1000;p/=10;)n-=putchar(n/p>9?46:48+n/p)%12*p;
â tsh
Sep 8 at 16:54
add a comment |Â
up vote
1
down vote
Japt, 20 bytes
A naïve (and slightly drunk!) port of Arnauld's solution. Uses "
for crown.
U+Aó s r"^21*0"_çQÃÂÃÂ
Try it
add a comment |Â
up vote
1
down vote
Japt, 20 bytes
A naïve (and slightly drunk!) port of Arnauld's solution. Uses "
for crown.
U+Aó s r"^21*0"_çQÃÂÃÂ
Try it
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Japt, 20 bytes
A naïve (and slightly drunk!) port of Arnauld's solution. Uses "
for crown.
U+Aó s r"^21*0"_çQÃÂÃÂ
Try it
Japt, 20 bytes
A naïve (and slightly drunk!) port of Arnauld's solution. Uses "
for crown.
U+Aó s r"^21*0"_çQÃÂÃÂ
Try it
answered Sep 8 at 22:32
Shaggy
16.7k21661
16.7k21661
add a comment |Â
add a comment |Â
up vote
1
down vote
Java 10, 84 83 bytes
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);
Port of @tsh' C comment.
Uses .
instead of crowns.
Try it online.
Alternative approach (84 (87-3) bytes):
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.
Try it online.
add a comment |Â
up vote
1
down vote
Java 10, 84 83 bytes
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);
Port of @tsh' C comment.
Uses .
instead of crowns.
Try it online.
Alternative approach (84 (87-3) bytes):
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.
Try it online.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Java 10, 84 83 bytes
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);
Port of @tsh' C comment.
Uses .
instead of crowns.
Try it online.
Alternative approach (84 (87-3) bytes):
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.
Try it online.
Java 10, 84 83 bytes
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);
Port of @tsh' C comment.
Uses .
instead of crowns.
Try it online.
Alternative approach (84 (87-3) bytes):
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.
Try it online.
edited Sep 10 at 13:51
answered Sep 10 at 9:23
Kevin Cruijssen
30.3k553167
30.3k553167
add a comment |Â
add a comment |Â
up vote
1
down vote
05AB1E, 20 18 bytes
âÂÂâ¹iâÂÂ+æëTð.;âÂÂ1 â :
Uses spaces for crowns.
Try it online or verify all test cases.
Explanation:
âÂÂâ¹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 " â " "
add a comment |Â
up vote
1
down vote
05AB1E, 20 18 bytes
âÂÂâ¹iâÂÂ+æëTð.;âÂÂ1 â :
Uses spaces for crowns.
Try it online or verify all test cases.
Explanation:
âÂÂâ¹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 " â " "
add a comment |Â
up vote
1
down vote
up vote
1
down vote
05AB1E, 20 18 bytes
âÂÂâ¹iâÂÂ+æëTð.;âÂÂ1 â :
Uses spaces for crowns.
Try it online or verify all test cases.
Explanation:
âÂÂâ¹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 " â " "
05AB1E, 20 18 bytes
âÂÂâ¹iâÂÂ+æëTð.;âÂÂ1 â :
Uses spaces for crowns.
Try it online or verify all test cases.
Explanation:
âÂÂâ¹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 " â " "
edited Sep 10 at 14:17
answered Sep 10 at 8:23
Kevin Cruijssen
30.3k553167
30.3k553167
add a comment |Â
add a comment |Â
up vote
1
down vote
APL (Dyalog Unicode), 32 bytes
1e3âÂÂâµ<âº:1âÂÂâÂÂâµ+âºâÂÂ'C',(âµ-âº)âÂÂâ¨âº÷10
Try it online!
Prefix direct function.
Port of @tsh's JS Answer.
How:
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
add a comment |Â
up vote
1
down vote
APL (Dyalog Unicode), 32 bytes
1e3âÂÂâµ<âº:1âÂÂâÂÂâµ+âºâÂÂ'C',(âµ-âº)âÂÂâ¨âº÷10
Try it online!
Prefix direct function.
Port of @tsh's JS Answer.
How:
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
add a comment |Â
up vote
1
down vote
up vote
1
down vote
APL (Dyalog Unicode), 32 bytes
1e3âÂÂâµ<âº:1âÂÂâÂÂâµ+âºâÂÂ'C',(âµ-âº)âÂÂâ¨âº÷10
Try it online!
Prefix direct function.
Port of @tsh's JS Answer.
How:
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
APL (Dyalog Unicode), 32 bytes
1e3âÂÂâµ<âº:1âÂÂâÂÂâµ+âºâÂÂ'C',(âµ-âº)âÂÂâ¨âº÷10
Try it online!
Prefix direct function.
Port of @tsh's JS Answer.
How:
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
answered Sep 10 at 18:22
J. Sallé
1,448318
1,448318
add a comment |Â
add a comment |Â
up vote
1
down vote
PHP, 71 bytes
for($n=$argn,$x=1e4;1<$x/=10;$n%=$n<$x?$x/10:$x)echo$n<$x?$n/$x*10|0:C;
prints C
for the crown. Run as pipe with -nR
or try it online.
add a comment |Â
up vote
1
down vote
PHP, 71 bytes
for($n=$argn,$x=1e4;1<$x/=10;$n%=$n<$x?$x/10:$x)echo$n<$x?$n/$x*10|0:C;
prints C
for the crown. Run as pipe with -nR
or try it online.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
PHP, 71 bytes
for($n=$argn,$x=1e4;1<$x/=10;$n%=$n<$x?$x/10:$x)echo$n<$x?$n/$x*10|0:C;
prints C
for the crown. Run as pipe with -nR
or try it online.
PHP, 71 bytes
for($n=$argn,$x=1e4;1<$x/=10;$n%=$n<$x?$x/10:$x)echo$n<$x?$n/$x*10|0:C;
prints C
for the crown. Run as pipe with -nR
or try it online.
answered Sep 10 at 21:20
Titus
12.4k11236
12.4k11236
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f171860%2fcrown-hundred-crownty-crown%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
3
Oh, Super Mario 3D Land!
â Deusovi
Sep 8 at 9:38
1
@Deusovi I was actually thinking about the follow-up game, Super Mario 3D World, but well guessed!
â Angs
Sep 8 at 10:00
2
This should be the IMO number for Boaty McBoatFace.
â Mr Lister
Sep 8 at 11:19
The bonus is multiplied by the number of crowns in the code, right?
â Erik the Outgolfer
Sep 8 at 14:13
3
@JeffZeitlin it's a redundant decimal system, where a number may have more than one representation (even disregarding leading zeroes). The crown is then reserved as a surprise element, only used when absolutely needed.
â Angs
Sep 8 at 20:32