The Written Digits Sequence
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.
Start with an empty sequence then define each term as the number of characters required to write out, in English, all of the digits of the sequence so far without spaces.*
For reference the number of characters of all of the (base ten) digits in English are:
zero one two three four five six seven eight nine
4 3 3 5 4 4 3 5 5 4
(Which is the start of both A52360 and A5589.)
This makes the first entry $a(0) = 0$ since there are zero digits present in the empty sequence.
This makes the second entry $a(1) = 4$ as it takes four characters to write "zero", the only digit present so far.
This makes the third entry $a(2) = 8$ as it takes four more characters to write the "four" for a total of eight to write "zerofour".
This makes the fourth entry $a(3) = 13$ as it takes five more characters to write "eight" for a total of thirteen to write "zerofoureight".
This makes the fifth entry $a(4) = 21$ as it takes eight more characters to write "onethree" for a total of twenty-one to write "zerofoureightonethree".
...and so on. Here are the first 100 entries:
0, 4, 8, 13, 21, 27, 35, 44, 52, 59, 67, 75, 84, 93, 102, 112, 121, 130, 142, 152, 162, 171, 182, 193, 205, 216, 225, 235, 247, 259, 270, 282, 293, 305, 318, 331, 344, 357, 371, 384, 398, 412, 422, 432, 444, 456, 467, 479, 492, 503, 516, 526, 536, 548, 561, 571, 583, 597, 610, 620, 630, 642, 652, 662, 671, 682, 693, 705, 718, 731, 744, 757, 771, 784, 798, 812, 823, 836, 849, 862, 873, 888, 903, 916, 926, 936, 948, 961, 971, 983, 997, 1010, 1024, 1038, 1055, 1070, 1086, 1101, 1114, 1127
* We could define it for other languages and/or other bases or with spaces of course
The challenge
Given $n$ output, in as few bytes of code as possible, any of:
- The first $n$ terms of the sequence (should work for non-negative integers)
- The value of $a(n)$ (should work for non-negative integers)
- The $n$th term of the sequence (should work for positive integers - i.e. value of $a(n-1)$)
This is code-golf so the shortest answer in bytes wins for each language, and the shortest answer in bytes wins. Don't let golfing languages stop you from entering in your favourite language be it a practical one or an esoteric one!
code-golf sequence arithmetic integer
add a comment |Â
up vote
5
down vote
favorite
Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.
Start with an empty sequence then define each term as the number of characters required to write out, in English, all of the digits of the sequence so far without spaces.*
For reference the number of characters of all of the (base ten) digits in English are:
zero one two three four five six seven eight nine
4 3 3 5 4 4 3 5 5 4
(Which is the start of both A52360 and A5589.)
This makes the first entry $a(0) = 0$ since there are zero digits present in the empty sequence.
This makes the second entry $a(1) = 4$ as it takes four characters to write "zero", the only digit present so far.
This makes the third entry $a(2) = 8$ as it takes four more characters to write the "four" for a total of eight to write "zerofour".
This makes the fourth entry $a(3) = 13$ as it takes five more characters to write "eight" for a total of thirteen to write "zerofoureight".
This makes the fifth entry $a(4) = 21$ as it takes eight more characters to write "onethree" for a total of twenty-one to write "zerofoureightonethree".
...and so on. Here are the first 100 entries:
0, 4, 8, 13, 21, 27, 35, 44, 52, 59, 67, 75, 84, 93, 102, 112, 121, 130, 142, 152, 162, 171, 182, 193, 205, 216, 225, 235, 247, 259, 270, 282, 293, 305, 318, 331, 344, 357, 371, 384, 398, 412, 422, 432, 444, 456, 467, 479, 492, 503, 516, 526, 536, 548, 561, 571, 583, 597, 610, 620, 630, 642, 652, 662, 671, 682, 693, 705, 718, 731, 744, 757, 771, 784, 798, 812, 823, 836, 849, 862, 873, 888, 903, 916, 926, 936, 948, 961, 971, 983, 997, 1010, 1024, 1038, 1055, 1070, 1086, 1101, 1114, 1127
* We could define it for other languages and/or other bases or with spaces of course
The challenge
Given $n$ output, in as few bytes of code as possible, any of:
- The first $n$ terms of the sequence (should work for non-negative integers)
- The value of $a(n)$ (should work for non-negative integers)
- The $n$th term of the sequence (should work for positive integers - i.e. value of $a(n-1)$)
This is code-golf so the shortest answer in bytes wins for each language, and the shortest answer in bytes wins. Don't let golfing languages stop you from entering in your favourite language be it a practical one or an esoteric one!
code-golf sequence arithmetic integer
By the first option, do you mean that 1)1
should output[0]
and0
should outputor 2)
0
should output[0]
(as in my former answer)?
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
â Jonathan Allan
1 hour ago
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.
Start with an empty sequence then define each term as the number of characters required to write out, in English, all of the digits of the sequence so far without spaces.*
For reference the number of characters of all of the (base ten) digits in English are:
zero one two three four five six seven eight nine
4 3 3 5 4 4 3 5 5 4
(Which is the start of both A52360 and A5589.)
This makes the first entry $a(0) = 0$ since there are zero digits present in the empty sequence.
This makes the second entry $a(1) = 4$ as it takes four characters to write "zero", the only digit present so far.
This makes the third entry $a(2) = 8$ as it takes four more characters to write the "four" for a total of eight to write "zerofour".
This makes the fourth entry $a(3) = 13$ as it takes five more characters to write "eight" for a total of thirteen to write "zerofoureight".
This makes the fifth entry $a(4) = 21$ as it takes eight more characters to write "onethree" for a total of twenty-one to write "zerofoureightonethree".
...and so on. Here are the first 100 entries:
0, 4, 8, 13, 21, 27, 35, 44, 52, 59, 67, 75, 84, 93, 102, 112, 121, 130, 142, 152, 162, 171, 182, 193, 205, 216, 225, 235, 247, 259, 270, 282, 293, 305, 318, 331, 344, 357, 371, 384, 398, 412, 422, 432, 444, 456, 467, 479, 492, 503, 516, 526, 536, 548, 561, 571, 583, 597, 610, 620, 630, 642, 652, 662, 671, 682, 693, 705, 718, 731, 744, 757, 771, 784, 798, 812, 823, 836, 849, 862, 873, 888, 903, 916, 926, 936, 948, 961, 971, 983, 997, 1010, 1024, 1038, 1055, 1070, 1086, 1101, 1114, 1127
* We could define it for other languages and/or other bases or with spaces of course
The challenge
Given $n$ output, in as few bytes of code as possible, any of:
- The first $n$ terms of the sequence (should work for non-negative integers)
- The value of $a(n)$ (should work for non-negative integers)
- The $n$th term of the sequence (should work for positive integers - i.e. value of $a(n-1)$)
This is code-golf so the shortest answer in bytes wins for each language, and the shortest answer in bytes wins. Don't let golfing languages stop you from entering in your favourite language be it a practical one or an esoteric one!
code-golf sequence arithmetic integer
Here's a reasonably trivial sequence which is not in the Online Encyclopedia of Integer Sequences.
Start with an empty sequence then define each term as the number of characters required to write out, in English, all of the digits of the sequence so far without spaces.*
For reference the number of characters of all of the (base ten) digits in English are:
zero one two three four five six seven eight nine
4 3 3 5 4 4 3 5 5 4
(Which is the start of both A52360 and A5589.)
This makes the first entry $a(0) = 0$ since there are zero digits present in the empty sequence.
This makes the second entry $a(1) = 4$ as it takes four characters to write "zero", the only digit present so far.
This makes the third entry $a(2) = 8$ as it takes four more characters to write the "four" for a total of eight to write "zerofour".
This makes the fourth entry $a(3) = 13$ as it takes five more characters to write "eight" for a total of thirteen to write "zerofoureight".
This makes the fifth entry $a(4) = 21$ as it takes eight more characters to write "onethree" for a total of twenty-one to write "zerofoureightonethree".
...and so on. Here are the first 100 entries:
0, 4, 8, 13, 21, 27, 35, 44, 52, 59, 67, 75, 84, 93, 102, 112, 121, 130, 142, 152, 162, 171, 182, 193, 205, 216, 225, 235, 247, 259, 270, 282, 293, 305, 318, 331, 344, 357, 371, 384, 398, 412, 422, 432, 444, 456, 467, 479, 492, 503, 516, 526, 536, 548, 561, 571, 583, 597, 610, 620, 630, 642, 652, 662, 671, 682, 693, 705, 718, 731, 744, 757, 771, 784, 798, 812, 823, 836, 849, 862, 873, 888, 903, 916, 926, 936, 948, 961, 971, 983, 997, 1010, 1024, 1038, 1055, 1070, 1086, 1101, 1114, 1127
* We could define it for other languages and/or other bases or with spaces of course
The challenge
Given $n$ output, in as few bytes of code as possible, any of:
- The first $n$ terms of the sequence (should work for non-negative integers)
- The value of $a(n)$ (should work for non-negative integers)
- The $n$th term of the sequence (should work for positive integers - i.e. value of $a(n-1)$)
This is code-golf so the shortest answer in bytes wins for each language, and the shortest answer in bytes wins. Don't let golfing languages stop you from entering in your favourite language be it a practical one or an esoteric one!
code-golf sequence arithmetic integer
code-golf sequence arithmetic integer
asked 2 hours ago
Jonathan Allan
49.3k534161
49.3k534161
By the first option, do you mean that 1)1
should output[0]
and0
should outputor 2)
0
should output[0]
(as in my former answer)?
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
â Jonathan Allan
1 hour ago
add a comment |Â
By the first option, do you mean that 1)1
should output[0]
and0
should outputor 2)
0
should output[0]
(as in my former answer)?
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
â Jonathan Allan
1 hour ago
By the first option, do you mean that 1)
1
should output [0]
and 0
should output
or 2) 0
should output [0]
(as in my former answer)?â Erik the Outgolfer
1 hour ago
By the first option, do you mean that 1)
1
should output [0]
and 0
should output
or 2) 0
should output [0]
(as in my former answer)?â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
â Jonathan Allan
1 hour ago
@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
â Jonathan Allan
1 hour ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
2
down vote
Pip, 21 bytes
Lai+:$+4335443554@^Pi
Takes input $n$ as a command-line argument and outputs the first $n$ terms. Try it online!
Explanation
Lai+:$+4335443554@^Pi
a is 1st cmdline arg; i is 0 (implicit)
La Loop (a) times:
Pi Print i
^ Split it into a list of characters (i.e. digits)
4335443554@ Use each digit to index into this number, giving the length of the
name of the digit (0 -> 4, 1 -> 3, etc.)
$+ Sum the results
i+: Increment i by that amount
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 82 bytes
f=(a,b=1,s=4)=>a?b<a?f(a,++b,s+=[...s+''].reduce((q,w)=>+'4335443554'[w]+q,0)):s:0
Try it online!
add a comment |Â
up vote
1
down vote
Jelly, 13 bytes
á¹ÂâÂÂváºÂçâÂÂá¸Â5äS+ÃÂá
Try it online!
0-indexed.
Full program; takes input from STDIN.
add a comment |Â
up vote
0
down vote
05AB1E, 15 bytes
ÃÂFDâ¢16|/â¢sSèOO
Try it online!
Explanation
ÃÂ # initialize stack with 0 and input
F # input times do:
D # duplicate the current number
sSè # and use one copy to index into
â¢16|/⢠# 4335443554
OO # sum digits and sum the stack
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
Pip, 21 bytes
Lai+:$+4335443554@^Pi
Takes input $n$ as a command-line argument and outputs the first $n$ terms. Try it online!
Explanation
Lai+:$+4335443554@^Pi
a is 1st cmdline arg; i is 0 (implicit)
La Loop (a) times:
Pi Print i
^ Split it into a list of characters (i.e. digits)
4335443554@ Use each digit to index into this number, giving the length of the
name of the digit (0 -> 4, 1 -> 3, etc.)
$+ Sum the results
i+: Increment i by that amount
add a comment |Â
up vote
2
down vote
Pip, 21 bytes
Lai+:$+4335443554@^Pi
Takes input $n$ as a command-line argument and outputs the first $n$ terms. Try it online!
Explanation
Lai+:$+4335443554@^Pi
a is 1st cmdline arg; i is 0 (implicit)
La Loop (a) times:
Pi Print i
^ Split it into a list of characters (i.e. digits)
4335443554@ Use each digit to index into this number, giving the length of the
name of the digit (0 -> 4, 1 -> 3, etc.)
$+ Sum the results
i+: Increment i by that amount
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Pip, 21 bytes
Lai+:$+4335443554@^Pi
Takes input $n$ as a command-line argument and outputs the first $n$ terms. Try it online!
Explanation
Lai+:$+4335443554@^Pi
a is 1st cmdline arg; i is 0 (implicit)
La Loop (a) times:
Pi Print i
^ Split it into a list of characters (i.e. digits)
4335443554@ Use each digit to index into this number, giving the length of the
name of the digit (0 -> 4, 1 -> 3, etc.)
$+ Sum the results
i+: Increment i by that amount
Pip, 21 bytes
Lai+:$+4335443554@^Pi
Takes input $n$ as a command-line argument and outputs the first $n$ terms. Try it online!
Explanation
Lai+:$+4335443554@^Pi
a is 1st cmdline arg; i is 0 (implicit)
La Loop (a) times:
Pi Print i
^ Split it into a list of characters (i.e. digits)
4335443554@ Use each digit to index into this number, giving the length of the
name of the digit (0 -> 4, 1 -> 3, etc.)
$+ Sum the results
i+: Increment i by that amount
answered 35 mins ago
DLosc
18.5k33588
18.5k33588
add a comment |Â
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 82 bytes
f=(a,b=1,s=4)=>a?b<a?f(a,++b,s+=[...s+''].reduce((q,w)=>+'4335443554'[w]+q,0)):s:0
Try it online!
add a comment |Â
up vote
1
down vote
JavaScript (Node.js), 82 bytes
f=(a,b=1,s=4)=>a?b<a?f(a,++b,s+=[...s+''].reduce((q,w)=>+'4335443554'[w]+q,0)):s:0
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
JavaScript (Node.js), 82 bytes
f=(a,b=1,s=4)=>a?b<a?f(a,++b,s+=[...s+''].reduce((q,w)=>+'4335443554'[w]+q,0)):s:0
Try it online!
JavaScript (Node.js), 82 bytes
f=(a,b=1,s=4)=>a?b<a?f(a,++b,s+=[...s+''].reduce((q,w)=>+'4335443554'[w]+q,0)):s:0
Try it online!
edited 1 hour ago
answered 1 hour ago
Luis felipe De jesus Munoz
3,36111049
3,36111049
add a comment |Â
add a comment |Â
up vote
1
down vote
Jelly, 13 bytes
á¹ÂâÂÂváºÂçâÂÂá¸Â5äS+ÃÂá
Try it online!
0-indexed.
Full program; takes input from STDIN.
add a comment |Â
up vote
1
down vote
Jelly, 13 bytes
á¹ÂâÂÂváºÂçâÂÂá¸Â5äS+ÃÂá
Try it online!
0-indexed.
Full program; takes input from STDIN.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Jelly, 13 bytes
á¹ÂâÂÂváºÂçâÂÂá¸Â5äS+ÃÂá
Try it online!
0-indexed.
Full program; takes input from STDIN.
Jelly, 13 bytes
á¹ÂâÂÂváºÂçâÂÂá¸Â5äS+ÃÂá
Try it online!
0-indexed.
Full program; takes input from STDIN.
edited 1 hour ago
answered 1 hour ago
Erik the Outgolfer
29.8k42899
29.8k42899
add a comment |Â
add a comment |Â
up vote
0
down vote
05AB1E, 15 bytes
ÃÂFDâ¢16|/â¢sSèOO
Try it online!
Explanation
ÃÂ # initialize stack with 0 and input
F # input times do:
D # duplicate the current number
sSè # and use one copy to index into
â¢16|/⢠# 4335443554
OO # sum digits and sum the stack
add a comment |Â
up vote
0
down vote
05AB1E, 15 bytes
ÃÂFDâ¢16|/â¢sSèOO
Try it online!
Explanation
ÃÂ # initialize stack with 0 and input
F # input times do:
D # duplicate the current number
sSè # and use one copy to index into
â¢16|/⢠# 4335443554
OO # sum digits and sum the stack
add a comment |Â
up vote
0
down vote
up vote
0
down vote
05AB1E, 15 bytes
ÃÂFDâ¢16|/â¢sSèOO
Try it online!
Explanation
ÃÂ # initialize stack with 0 and input
F # input times do:
D # duplicate the current number
sSè # and use one copy to index into
â¢16|/⢠# 4335443554
OO # sum digits and sum the stack
05AB1E, 15 bytes
ÃÂFDâ¢16|/â¢sSèOO
Try it online!
Explanation
ÃÂ # initialize stack with 0 and input
F # input times do:
D # duplicate the current number
sSè # and use one copy to index into
â¢16|/⢠# 4335443554
OO # sum digits and sum the stack
answered 5 mins ago
Emigna
43.9k431133
43.9k431133
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%2f174521%2fthe-written-digits-sequence%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
By the first option, do you mean that 1)
1
should output[0]
and0
should outputor 2)
0
should output[0]
(as in my former answer)?â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer I mean (1) as it should return the first n terms. That is, the options are "output the sequence up to but not including a(n)", "output a(n)", or "output a(n-1)".
â Jonathan Allan
1 hour ago