Given a string, calculate the number of columns it corresponds to
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ
and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.
In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.
Some tests:
'A' returns 1 (meaning that it is the first column)
'B' returns 2
'Z' returns 26
'AA' returns 27
'AB' returns 28
'AZ' returns 52
'ZZ' returns 702
'AAA' returns 703
You can assume that capital letters will be given only.
Shortest bytes win.
Good luck!
code-golf math
add a comment |Â
up vote
1
down vote
favorite
In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ
and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.
In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.
Some tests:
'A' returns 1 (meaning that it is the first column)
'B' returns 2
'Z' returns 26
'AA' returns 27
'AB' returns 28
'AZ' returns 52
'ZZ' returns 702
'AAA' returns 703
You can assume that capital letters will be given only.
Shortest bytes win.
Good luck!
code-golf math
So... base 26 with the alphabet?
â Jo King
1 hour ago
It isn't quite base 26 because there's no zero.
â J.Doe
1 hour ago
@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treatedZ
as 10 anyway
â Jo King
32 mins ago
Reverse challenge.
â user202729
27 mins ago
1
@JoKing Bijective base.
â user202729
25 mins ago
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ
and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.
In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.
Some tests:
'A' returns 1 (meaning that it is the first column)
'B' returns 2
'Z' returns 26
'AA' returns 27
'AB' returns 28
'AZ' returns 52
'ZZ' returns 702
'AAA' returns 703
You can assume that capital letters will be given only.
Shortest bytes win.
Good luck!
code-golf math
In Excel, the columns range from A-Z, AA,AB,AZ,BA,..,BZ
and so on. They actually each stand for numbers, but rather are encoded as alphabet strings.
In this challenge, you will be given a string of alphabets, and you must calculate the column it corresponds to.
Some tests:
'A' returns 1 (meaning that it is the first column)
'B' returns 2
'Z' returns 26
'AA' returns 27
'AB' returns 28
'AZ' returns 52
'ZZ' returns 702
'AAA' returns 703
You can assume that capital letters will be given only.
Shortest bytes win.
Good luck!
code-golf math
code-golf math
asked 1 hour ago
K Split X
376110
376110
So... base 26 with the alphabet?
â Jo King
1 hour ago
It isn't quite base 26 because there's no zero.
â J.Doe
1 hour ago
@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treatedZ
as 10 anyway
â Jo King
32 mins ago
Reverse challenge.
â user202729
27 mins ago
1
@JoKing Bijective base.
â user202729
25 mins ago
add a comment |Â
So... base 26 with the alphabet?
â Jo King
1 hour ago
It isn't quite base 26 because there's no zero.
â J.Doe
1 hour ago
@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treatedZ
as 10 anyway
â Jo King
32 mins ago
Reverse challenge.
â user202729
27 mins ago
1
@JoKing Bijective base.
â user202729
25 mins ago
So... base 26 with the alphabet?
â Jo King
1 hour ago
So... base 26 with the alphabet?
â Jo King
1 hour ago
It isn't quite base 26 because there's no zero.
â J.Doe
1 hour ago
It isn't quite base 26 because there's no zero.
â J.Doe
1 hour ago
@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated
Z
as 10 anywayâ Jo King
32 mins ago
@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated
Z
as 10 anywayâ Jo King
32 mins ago
Reverse challenge.
â user202729
27 mins ago
Reverse challenge.
â user202729
27 mins ago
1
1
@JoKing Bijective base.
â user202729
25 mins ago
@JoKing Bijective base.
â user202729
25 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
R, 48 bytes
function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)
Try it online!
add a comment |Â
up vote
2
down vote
Perl 6, 17 bytes
:26[.ords X-64]
Try it online!
Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z
overflowing to the next column.
add a comment |Â
up vote
1
down vote
Python 2, 52 45 bytes
t=0
for c in input():t=26*t+ord(c)%64
print t
Try it online!
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
R, 48 bytes
function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)
Try it online!
add a comment |Â
up vote
2
down vote
R, 48 bytes
function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
R, 48 bytes
function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)
Try it online!
R, 48 bytes
function(s)(utf8ToInt(s)-64)%*%26^(nchar(s):1-1)
Try it online!
edited 1 hour ago
answered 1 hour ago
J.Doe
1,691112
1,691112
add a comment |Â
add a comment |Â
up vote
2
down vote
Perl 6, 17 bytes
:26[.ords X-64]
Try it online!
Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z
overflowing to the next column.
add a comment |Â
up vote
2
down vote
Perl 6, 17 bytes
:26[.ords X-64]
Try it online!
Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z
overflowing to the next column.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Perl 6, 17 bytes
:26[.ords X-64]
Try it online!
Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z
overflowing to the next column.
Perl 6, 17 bytes
:26[.ords X-64]
Try it online!
Anonymous code block that subtracts 64 from each byte value and converts from base 26 with Z
overflowing to the next column.
edited 36 mins ago
answered 1 hour ago
Jo King
17.4k24197
17.4k24197
add a comment |Â
add a comment |Â
up vote
1
down vote
Python 2, 52 45 bytes
t=0
for c in input():t=26*t+ord(c)%64
print t
Try it online!
add a comment |Â
up vote
1
down vote
Python 2, 52 45 bytes
t=0
for c in input():t=26*t+ord(c)%64
print t
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 2, 52 45 bytes
t=0
for c in input():t=26*t+ord(c)%64
print t
Try it online!
Python 2, 52 45 bytes
t=0
for c in input():t=26*t+ord(c)%64
print t
Try it online!
edited 19 mins ago
answered 29 mins ago
Chas Brown
4,4561419
4,4561419
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%2f174336%2fgiven-a-string-calculate-the-number-of-columns-it-corresponds-to%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
So... base 26 with the alphabet?
â Jo King
1 hour ago
It isn't quite base 26 because there's no zero.
â J.Doe
1 hour ago
@J.Doe Ah, I guess you're right. I didn't notice since my solution automatically treated
Z
as 10 anywayâ Jo King
32 mins ago
Reverse challenge.
â user202729
27 mins ago
1
@JoKing Bijective base.
â user202729
25 mins ago