KeyPad Code to Text!
Pyth - 31 bytes
The new key thing cost me too much.
ss.emr!FZk@@QsedthdfndeTrb8cz\#
Test Suite.
JavaScript, 105 99 bytes
f=
(s,a)=>s.replace(/#| ?((.)\2*)/g,(m,n,d)=>d?(l=a[d][n.length-1],x?l:l.toUpperCase()):(x=!x,''),x=1)
a=[' ','.,!','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz']
F=s=>console.log( f(s,a) )
F('#4440555#666888330#999#66688111')
F('#6#33777 7779990#222#4477744477778627777111');
F('#44#27 79990#66#3390#999#332777111');
- 6 bytes off thanks @Neil.
Perl 6, 119 97 bytes
map based solution 119 bytes
->$_,\a{my$u=0;[~] map {/'#'/??{$u+^=1;|()}()!!(&lc,&uc)[$u](a[.substr(0,1)].substr(.chars-1,1))},.comb(/(\d)$0*|'#'/)}
Try it
substitution based solution 97 bytes
->$_,\a{my$u=0;S:g/(\d)$0*|./{$0??(&lc,&uc)[$u](a[$0].substr($/.chars-1,1))!!($u+^=$/eq'#')x 0}/}
Try it
Expanded:
-> # pointy block lambda
$_, # input string
\a # helper array
{
my $u = 0;
S # substitute (implicit against 「$_」)
:global
/
| (\d) $0* # digit followed by same digit
| . # everything else
/{
$0 # is 「$0」 set (digit)
?? # if so then
(&lc,&uc)[$u]( # call either 「lc」 or 「uc」
a[$0] # get the value from the input array
.substr( # select the correct character
$/.chars - 1,
1
)
)
!!
(
$u +^= $/ eq '#' # numeric xor $u if 「#」 was matched
) x 0 # string repeated zero times (empty string)
}/
}