What numbers are these?
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
While I was writing numbers I noticed after a while that my keyboard had the Shift key pressed and blocked and all I wrote was $%&
-like characters. And even worse, I had been switching between the English and Spanish keyboard layouts so I don't know which one I used for each number.
Challenge
Given a string containing symbol characters, try to guess which number I wrote. My keyboard produces the following characters for the numbers when the Shift is pressed:
1234567890
----------
!"÷$%&/()= Spanish layout
!@#$%^&*() English layout
- The input will be a non-null, non-empty string composed of the symbols above.
- The output will be a single number if the keyboard layout can be inferred from the string (i.e. if the string contains a
@
an English layout was used, and if the string contains a"
a Spanish layout was used) or if the number is the same for both layouts (i.e. the input is!$
which translates as14
for both layouts); otherwise the output will be the two possible numbers for both layouts if it cannot be inferred and the resulting numbers are different. - The input string will always be written in a single layout. So you don't need to expect
"@
as input.
Examples
Input --> Output
------------------
/() 789 (Spanish layout detected by the use of /)
$%& 456,457 (Layout cannot be inferred)
!@# 123 (English layout detected by the use of @ and #)
()&! 8961,9071 (Layout cannot be inferred)
((÷)) 88399 (Spanish layout detected by the use of ÷)
!$ 14 (Layout cannot be inferred but the result is the same for both)
!!$$%% 114455 (Layout cannot be inferred but the result is the same for both)
==$" 0042/42 (Spanish layout, if a number starts with 0 you can choose to
omit them in the result or not)
Single character translations:
------------------------------
! 1
" 2
÷ 3
$ 4
% 5
& 6,7
/ 7
( 8,9
) 9,0
= 0
@ 2
# 3
^ 6
* 8
This is code-golf, so may the shortest code for each language win!
code-golf keyboard
add a comment |Â
up vote
4
down vote
favorite
While I was writing numbers I noticed after a while that my keyboard had the Shift key pressed and blocked and all I wrote was $%&
-like characters. And even worse, I had been switching between the English and Spanish keyboard layouts so I don't know which one I used for each number.
Challenge
Given a string containing symbol characters, try to guess which number I wrote. My keyboard produces the following characters for the numbers when the Shift is pressed:
1234567890
----------
!"÷$%&/()= Spanish layout
!@#$%^&*() English layout
- The input will be a non-null, non-empty string composed of the symbols above.
- The output will be a single number if the keyboard layout can be inferred from the string (i.e. if the string contains a
@
an English layout was used, and if the string contains a"
a Spanish layout was used) or if the number is the same for both layouts (i.e. the input is!$
which translates as14
for both layouts); otherwise the output will be the two possible numbers for both layouts if it cannot be inferred and the resulting numbers are different. - The input string will always be written in a single layout. So you don't need to expect
"@
as input.
Examples
Input --> Output
------------------
/() 789 (Spanish layout detected by the use of /)
$%& 456,457 (Layout cannot be inferred)
!@# 123 (English layout detected by the use of @ and #)
()&! 8961,9071 (Layout cannot be inferred)
((÷)) 88399 (Spanish layout detected by the use of ÷)
!$ 14 (Layout cannot be inferred but the result is the same for both)
!!$$%% 114455 (Layout cannot be inferred but the result is the same for both)
==$" 0042/42 (Spanish layout, if a number starts with 0 you can choose to
omit them in the result or not)
Single character translations:
------------------------------
! 1
" 2
÷ 3
$ 4
% 5
& 6,7
/ 7
( 8,9
) 9,0
= 0
@ 2
# 3
^ 6
* 8
This is code-golf, so may the shortest code for each language win!
code-golf keyboard
Dang it, that·
is challenging...
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer in fact the·
is useless for Spanish, it is only used in the Catalan language.
â Charlie
1 hour ago
Is output like(8, 9, 6, 1), (9, 0, 7, 1)
(for the 4th test case) acceptable?
â Lynn
40 mins ago
@Lynn yes, it is.
â Charlie
38 mins ago
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
While I was writing numbers I noticed after a while that my keyboard had the Shift key pressed and blocked and all I wrote was $%&
-like characters. And even worse, I had been switching between the English and Spanish keyboard layouts so I don't know which one I used for each number.
Challenge
Given a string containing symbol characters, try to guess which number I wrote. My keyboard produces the following characters for the numbers when the Shift is pressed:
1234567890
----------
!"÷$%&/()= Spanish layout
!@#$%^&*() English layout
- The input will be a non-null, non-empty string composed of the symbols above.
- The output will be a single number if the keyboard layout can be inferred from the string (i.e. if the string contains a
@
an English layout was used, and if the string contains a"
a Spanish layout was used) or if the number is the same for both layouts (i.e. the input is!$
which translates as14
for both layouts); otherwise the output will be the two possible numbers for both layouts if it cannot be inferred and the resulting numbers are different. - The input string will always be written in a single layout. So you don't need to expect
"@
as input.
Examples
Input --> Output
------------------
/() 789 (Spanish layout detected by the use of /)
$%& 456,457 (Layout cannot be inferred)
!@# 123 (English layout detected by the use of @ and #)
()&! 8961,9071 (Layout cannot be inferred)
((÷)) 88399 (Spanish layout detected by the use of ÷)
!$ 14 (Layout cannot be inferred but the result is the same for both)
!!$$%% 114455 (Layout cannot be inferred but the result is the same for both)
==$" 0042/42 (Spanish layout, if a number starts with 0 you can choose to
omit them in the result or not)
Single character translations:
------------------------------
! 1
" 2
÷ 3
$ 4
% 5
& 6,7
/ 7
( 8,9
) 9,0
= 0
@ 2
# 3
^ 6
* 8
This is code-golf, so may the shortest code for each language win!
code-golf keyboard
While I was writing numbers I noticed after a while that my keyboard had the Shift key pressed and blocked and all I wrote was $%&
-like characters. And even worse, I had been switching between the English and Spanish keyboard layouts so I don't know which one I used for each number.
Challenge
Given a string containing symbol characters, try to guess which number I wrote. My keyboard produces the following characters for the numbers when the Shift is pressed:
1234567890
----------
!"÷$%&/()= Spanish layout
!@#$%^&*() English layout
- The input will be a non-null, non-empty string composed of the symbols above.
- The output will be a single number if the keyboard layout can be inferred from the string (i.e. if the string contains a
@
an English layout was used, and if the string contains a"
a Spanish layout was used) or if the number is the same for both layouts (i.e. the input is!$
which translates as14
for both layouts); otherwise the output will be the two possible numbers for both layouts if it cannot be inferred and the resulting numbers are different. - The input string will always be written in a single layout. So you don't need to expect
"@
as input.
Examples
Input --> Output
------------------
/() 789 (Spanish layout detected by the use of /)
$%& 456,457 (Layout cannot be inferred)
!@# 123 (English layout detected by the use of @ and #)
()&! 8961,9071 (Layout cannot be inferred)
((÷)) 88399 (Spanish layout detected by the use of ÷)
!$ 14 (Layout cannot be inferred but the result is the same for both)
!!$$%% 114455 (Layout cannot be inferred but the result is the same for both)
==$" 0042/42 (Spanish layout, if a number starts with 0 you can choose to
omit them in the result or not)
Single character translations:
------------------------------
! 1
" 2
÷ 3
$ 4
% 5
& 6,7
/ 7
( 8,9
) 9,0
= 0
@ 2
# 3
^ 6
* 8
This is code-golf, so may the shortest code for each language win!
code-golf keyboard
code-golf keyboard
asked 1 hour ago
Charlie
6,9352081
6,9352081
Dang it, that·
is challenging...
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer in fact the·
is useless for Spanish, it is only used in the Catalan language.
â Charlie
1 hour ago
Is output like(8, 9, 6, 1), (9, 0, 7, 1)
(for the 4th test case) acceptable?
â Lynn
40 mins ago
@Lynn yes, it is.
â Charlie
38 mins ago
add a comment |Â
Dang it, that·
is challenging...
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer in fact the·
is useless for Spanish, it is only used in the Catalan language.
â Charlie
1 hour ago
Is output like(8, 9, 6, 1), (9, 0, 7, 1)
(for the 4th test case) acceptable?
â Lynn
40 mins ago
@Lynn yes, it is.
â Charlie
38 mins ago
Dang it, that
·
is challenging...â Erik the Outgolfer
1 hour ago
Dang it, that
·
is challenging...â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer in fact the
·
is useless for Spanish, it is only used in the Catalan language.â Charlie
1 hour ago
@EriktheOutgolfer in fact the
·
is useless for Spanish, it is only used in the Catalan language.â Charlie
1 hour ago
Is output like
(8, 9, 6, 1), (9, 0, 7, 1)
(for the 4th test case) acceptable?â Lynn
40 mins ago
Is output like
(8, 9, 6, 1), (9, 0, 7, 1)
(for the 4th test case) acceptable?â Lynn
40 mins ago
@Lynn yes, it is.
â Charlie
38 mins ago
@Lynn yes, it is.
â Charlie
38 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
1
down vote
Python 3, 76 bytes
lambda s:(*map(k.find,s),)for k in['=!"÷$%&/()',')!@#$%^&*(']if*s<=*k
Try it online!
add a comment |Â
up vote
1
down vote
Java (JDK), 173 bytes
Golfed
c->String s="",e=s;var m="21#3457#908###6##12#456389###0#7".split("");for(int l:c)e+=m[l=l%16];s+=m[l+16];return s.equals(e)
Try it online!
Ungolfed
c-> // Lamdba taking char array as input
String s="",e=s; // Initialise Spanish and English strings
var m="21#3457#908###6##12#456389###0#7".split(""); // Create magic hashing lookup array (see below)
for(int l:c) // Loops through all chars in input
e+=m[l=l%16]; // Get english number from array and append
s+=m[l+16]; // Get Spanish number from array and append
return s.equals(e)
The Magic Hashing Lookup Array
After some experimenting with values I realised that each of the ASCII values of the characters !"÷$%&/()=@#^*
modulo 16 returns a unique number. The 'magic hashing lookup array' stores the English numbers associated with each character at this unique index, and each of the Spanish numbers at this index offset by 16, making fetching the required number from the array trivial for each language. A hash is stored for values that are invalid for either language.
add a comment |Â
up vote
1
down vote
Jelly, 38 bytes
183á»ÂâÂÂ=!"âÂÂ$%&/()âÂÂj,âÂÂ)!@#$%^&*(âÂÂiⱮ≸ẠÃÂâÂÂQ
Try it online!
Note that if the number is the same for both layouts you must return a single number, and not a list, as if you had identified the layout.
â Charlie
19 mins ago
@Charlie Whoops, fixed. :P
â Erik the Outgolfer
17 mins ago
Nice! Just one question, I have tried your code with()
or(())
as input, but your code then return nothing. I suppose that's a limitation with what Jelly receives as input?
â Charlie
14 mins ago
1
@Charlie Try with'()'
and'(())'
respectively. Yes, if you don't quote the argument, it's only inputted as a string if it can't beeval
uated to a Python 3 value.
â Erik the Outgolfer
13 mins ago
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Python 3, 76 bytes
lambda s:(*map(k.find,s),)for k in['=!"÷$%&/()',')!@#$%^&*(']if*s<=*k
Try it online!
add a comment |Â
up vote
1
down vote
Python 3, 76 bytes
lambda s:(*map(k.find,s),)for k in['=!"÷$%&/()',')!@#$%^&*(']if*s<=*k
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 3, 76 bytes
lambda s:(*map(k.find,s),)for k in['=!"÷$%&/()',')!@#$%^&*(']if*s<=*k
Try it online!
Python 3, 76 bytes
lambda s:(*map(k.find,s),)for k in['=!"÷$%&/()',')!@#$%^&*(']if*s<=*k
Try it online!
answered 35 mins ago
Lynn
48.3k694223
48.3k694223
add a comment |Â
add a comment |Â
up vote
1
down vote
Java (JDK), 173 bytes
Golfed
c->String s="",e=s;var m="21#3457#908###6##12#456389###0#7".split("");for(int l:c)e+=m[l=l%16];s+=m[l+16];return s.equals(e)
Try it online!
Ungolfed
c-> // Lamdba taking char array as input
String s="",e=s; // Initialise Spanish and English strings
var m="21#3457#908###6##12#456389###0#7".split(""); // Create magic hashing lookup array (see below)
for(int l:c) // Loops through all chars in input
e+=m[l=l%16]; // Get english number from array and append
s+=m[l+16]; // Get Spanish number from array and append
return s.equals(e)
The Magic Hashing Lookup Array
After some experimenting with values I realised that each of the ASCII values of the characters !"÷$%&/()=@#^*
modulo 16 returns a unique number. The 'magic hashing lookup array' stores the English numbers associated with each character at this unique index, and each of the Spanish numbers at this index offset by 16, making fetching the required number from the array trivial for each language. A hash is stored for values that are invalid for either language.
add a comment |Â
up vote
1
down vote
Java (JDK), 173 bytes
Golfed
c->String s="",e=s;var m="21#3457#908###6##12#456389###0#7".split("");for(int l:c)e+=m[l=l%16];s+=m[l+16];return s.equals(e)
Try it online!
Ungolfed
c-> // Lamdba taking char array as input
String s="",e=s; // Initialise Spanish and English strings
var m="21#3457#908###6##12#456389###0#7".split(""); // Create magic hashing lookup array (see below)
for(int l:c) // Loops through all chars in input
e+=m[l=l%16]; // Get english number from array and append
s+=m[l+16]; // Get Spanish number from array and append
return s.equals(e)
The Magic Hashing Lookup Array
After some experimenting with values I realised that each of the ASCII values of the characters !"÷$%&/()=@#^*
modulo 16 returns a unique number. The 'magic hashing lookup array' stores the English numbers associated with each character at this unique index, and each of the Spanish numbers at this index offset by 16, making fetching the required number from the array trivial for each language. A hash is stored for values that are invalid for either language.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Java (JDK), 173 bytes
Golfed
c->String s="",e=s;var m="21#3457#908###6##12#456389###0#7".split("");for(int l:c)e+=m[l=l%16];s+=m[l+16];return s.equals(e)
Try it online!
Ungolfed
c-> // Lamdba taking char array as input
String s="",e=s; // Initialise Spanish and English strings
var m="21#3457#908###6##12#456389###0#7".split(""); // Create magic hashing lookup array (see below)
for(int l:c) // Loops through all chars in input
e+=m[l=l%16]; // Get english number from array and append
s+=m[l+16]; // Get Spanish number from array and append
return s.equals(e)
The Magic Hashing Lookup Array
After some experimenting with values I realised that each of the ASCII values of the characters !"÷$%&/()=@#^*
modulo 16 returns a unique number. The 'magic hashing lookup array' stores the English numbers associated with each character at this unique index, and each of the Spanish numbers at this index offset by 16, making fetching the required number from the array trivial for each language. A hash is stored for values that are invalid for either language.
Java (JDK), 173 bytes
Golfed
c->String s="",e=s;var m="21#3457#908###6##12#456389###0#7".split("");for(int l:c)e+=m[l=l%16];s+=m[l+16];return s.equals(e)
Try it online!
Ungolfed
c-> // Lamdba taking char array as input
String s="",e=s; // Initialise Spanish and English strings
var m="21#3457#908###6##12#456389###0#7".split(""); // Create magic hashing lookup array (see below)
for(int l:c) // Loops through all chars in input
e+=m[l=l%16]; // Get english number from array and append
s+=m[l+16]; // Get Spanish number from array and append
return s.equals(e)
The Magic Hashing Lookup Array
After some experimenting with values I realised that each of the ASCII values of the characters !"÷$%&/()=@#^*
modulo 16 returns a unique number. The 'magic hashing lookup array' stores the English numbers associated with each character at this unique index, and each of the Spanish numbers at this index offset by 16, making fetching the required number from the array trivial for each language. A hash is stored for values that are invalid for either language.
answered 30 mins ago
Luke Stevens
639214
639214
add a comment |Â
add a comment |Â
up vote
1
down vote
Jelly, 38 bytes
183á»ÂâÂÂ=!"âÂÂ$%&/()âÂÂj,âÂÂ)!@#$%^&*(âÂÂiⱮ≸ẠÃÂâÂÂQ
Try it online!
Note that if the number is the same for both layouts you must return a single number, and not a list, as if you had identified the layout.
â Charlie
19 mins ago
@Charlie Whoops, fixed. :P
â Erik the Outgolfer
17 mins ago
Nice! Just one question, I have tried your code with()
or(())
as input, but your code then return nothing. I suppose that's a limitation with what Jelly receives as input?
â Charlie
14 mins ago
1
@Charlie Try with'()'
and'(())'
respectively. Yes, if you don't quote the argument, it's only inputted as a string if it can't beeval
uated to a Python 3 value.
â Erik the Outgolfer
13 mins ago
add a comment |Â
up vote
1
down vote
Jelly, 38 bytes
183á»ÂâÂÂ=!"âÂÂ$%&/()âÂÂj,âÂÂ)!@#$%^&*(âÂÂiⱮ≸ẠÃÂâÂÂQ
Try it online!
Note that if the number is the same for both layouts you must return a single number, and not a list, as if you had identified the layout.
â Charlie
19 mins ago
@Charlie Whoops, fixed. :P
â Erik the Outgolfer
17 mins ago
Nice! Just one question, I have tried your code with()
or(())
as input, but your code then return nothing. I suppose that's a limitation with what Jelly receives as input?
â Charlie
14 mins ago
1
@Charlie Try with'()'
and'(())'
respectively. Yes, if you don't quote the argument, it's only inputted as a string if it can't beeval
uated to a Python 3 value.
â Erik the Outgolfer
13 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Jelly, 38 bytes
183á»ÂâÂÂ=!"âÂÂ$%&/()âÂÂj,âÂÂ)!@#$%^&*(âÂÂiⱮ≸ẠÃÂâÂÂQ
Try it online!
Jelly, 38 bytes
183á»ÂâÂÂ=!"âÂÂ$%&/()âÂÂj,âÂÂ)!@#$%^&*(âÂÂiⱮ≸ẠÃÂâÂÂQ
Try it online!
edited 17 mins ago
answered 39 mins ago
Erik the Outgolfer
29.8k42899
29.8k42899
Note that if the number is the same for both layouts you must return a single number, and not a list, as if you had identified the layout.
â Charlie
19 mins ago
@Charlie Whoops, fixed. :P
â Erik the Outgolfer
17 mins ago
Nice! Just one question, I have tried your code with()
or(())
as input, but your code then return nothing. I suppose that's a limitation with what Jelly receives as input?
â Charlie
14 mins ago
1
@Charlie Try with'()'
and'(())'
respectively. Yes, if you don't quote the argument, it's only inputted as a string if it can't beeval
uated to a Python 3 value.
â Erik the Outgolfer
13 mins ago
add a comment |Â
Note that if the number is the same for both layouts you must return a single number, and not a list, as if you had identified the layout.
â Charlie
19 mins ago
@Charlie Whoops, fixed. :P
â Erik the Outgolfer
17 mins ago
Nice! Just one question, I have tried your code with()
or(())
as input, but your code then return nothing. I suppose that's a limitation with what Jelly receives as input?
â Charlie
14 mins ago
1
@Charlie Try with'()'
and'(())'
respectively. Yes, if you don't quote the argument, it's only inputted as a string if it can't beeval
uated to a Python 3 value.
â Erik the Outgolfer
13 mins ago
Note that if the number is the same for both layouts you must return a single number, and not a list, as if you had identified the layout.
â Charlie
19 mins ago
Note that if the number is the same for both layouts you must return a single number, and not a list, as if you had identified the layout.
â Charlie
19 mins ago
@Charlie Whoops, fixed. :P
â Erik the Outgolfer
17 mins ago
@Charlie Whoops, fixed. :P
â Erik the Outgolfer
17 mins ago
Nice! Just one question, I have tried your code with
()
or (())
as input, but your code then return nothing. I suppose that's a limitation with what Jelly receives as input?â Charlie
14 mins ago
Nice! Just one question, I have tried your code with
()
or (())
as input, but your code then return nothing. I suppose that's a limitation with what Jelly receives as input?â Charlie
14 mins ago
1
1
@Charlie Try with
'()'
and '(())'
respectively. Yes, if you don't quote the argument, it's only inputted as a string if it can't be eval
uated to a Python 3 value.â Erik the Outgolfer
13 mins ago
@Charlie Try with
'()'
and '(())'
respectively. Yes, if you don't quote the argument, it's only inputted as a string if it can't be eval
uated to a Python 3 value.â Erik the Outgolfer
13 mins ago
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%2f173942%2fwhat-numbers-are-these%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
Dang it, that
·
is challenging...â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer in fact the
·
is useless for Spanish, it is only used in the Catalan language.â Charlie
1 hour ago
Is output like
(8, 9, 6, 1), (9, 0, 7, 1)
(for the 4th test case) acceptable?â Lynn
40 mins ago
@Lynn yes, it is.
â Charlie
38 mins ago