Numeronyms or N8s?
Caché ObjectScript, 231 bytes
r(a,b) s o=$REPLACE(o,a,b) q
z(s) f i=1:1:$L(s," ") s u=$P(s," ",i),l=$L(u),o=$S(l<4:u,1:$E(u)_(l-2)_$E(u,l)) d:l>3 r("I1","i1"),r("l1","L1") d g:r z+4
. i '(l<4!(v(o)=u!'$D(v(o)))) s r=1 q
. s v(o)=u,t=t_o_" "
q t
q "A7s R4t"
This would be good-ol' standards-compliant MUMPS if it weren't for that pesky $REPLACE
call, which isn't part of the standard. Reimplementing it in pure M takes a good 80ish bytes, so I didn't go down that route.
The entry point is $$z("your string here")
, which returns "y2r s4g h2e"
, and so forth.
C#, 280 274 bytes
First time golfer here! Been enjoying reading these lately and so I thought I might try out some myself! Probably not the best solution, but oh well!
class B{static void Main(string[] a){string[] n=Console.ReadLine().Split(' ');string o="";int j,i=j=0;for(;j<n.Length;j++){int s=n[j].Length;n[j]=((s<4)?n[j]:""+n[j][0]+(s-2)+n[j][s-1])+" ";o+=n[j];for(;i<j;i++)if(n[j]==n[i]){o="A7s R4t";j=n.Length;}}Console.WriteLine(o);}}
Same thing ungolfed:
class B
{
static void Main(string[] a)
{
string[] n = Console.ReadLine().Split(' ');
string o = "";
int j, i = j = 0;
for(; j < n.Length;j++)
{
int s = n[j].Length;
n[j] = ((s<4) ? n[j] : "" + n[j][0] + (s - 2) + n[j][s - 1]) + " ";
o += n[j];
for (; i < j; i++)
{
if (n[j] == n[i]) { o = "A7s R4t"; j=n.Length;}
}
}
Console.WriteLine(o);
}
}
Thanks guys!
Perl, 131 120 bytes
I've added a byte for using the -p
switch:
s/\B(\w+)(\w)/length($1)."$2_$1"/ge;$_="A7s R4t\n"if/(\w\d+\w)(\w+)\b.*\1(?!\2)/;s/_\w+//g;s/I1\w/\l$&/g;s/l1\w/\u$&/g;
Explanation
# Replace internal letters with count, but keep them around for the next test.
s/\B(\w+)(\w)/length($1)."$2_$1"/ge;
# Detect ambiguous result
$_ = "A7s R4t\n" if
# Use negative look-ahead assertion to find conflicts
/(\w\d+\w)(\w+)\b.*\1(?!\2)/;
# We're done with the internal letters now
s/_\w+//g;
# Transform case of initial 'I' and 'l', but only before '1'
s/I1\w/\l$&/g;
s/l1\w/\u$&/g;