22
2
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!
Dang it, that
·
is challenging... – Erik the Outgolfer – 2018-10-12T20:39:03.0232@EriktheOutgolfer in fact the
·
is useless for Spanish, it is only used in the Catalan language. – Charlie – 2018-10-12T20:41:04.550Is output like
{(8, 9, 6, 1), (9, 0, 7, 1)}
(for the 4th test case) acceptable? – Lynn – 2018-10-12T21:01:55.993@Lynn yes, it is. – Charlie – 2018-10-12T21:03:31.747
When outputting 2 numbers, does the order matter? – Shaggy – 2018-10-12T22:30:47.133
@Shaggy not at all. :-) – Charlie – 2018-10-12T22:35:49.180
For my English layout it's
!"£$%^&*()
– Okx – 2018-10-13T08:33:54.777@Okx interesting, I suppose my sysadmin has installed the American English layout in my computer. The British one seems to be a mix of both. – Charlie – 2018-10-13T08:40:52.327
Is that dot (
·
) the same as byte 250 in CP437 and DOS Latin-1? If so, may we encode input and our submissions in such code pages able to represent all of the characters required in a single byte? – Οurous – 2018-10-14T05:24:54.950@Οurous the byte 250 in CP437 seems to be a punctuation mark resembling the middle dot, so yes, you can use it. I'm not sure what you want to do with the code pages but please, go ahead. – Charlie – 2018-10-14T05:43:51.500
@Charlie The reason I ask is it saves a lot of space not having to handle an otherwise multi-byte character. – Οurous – 2018-10-14T22:11:52.323
Can the input be taken as a list of characters instead of string? – Kevin Cruijssen – 2018-10-15T06:48:42.590
@KevinCruijssen yes, of course. – Charlie – 2018-10-15T07:00:15.807