Eduard Lebedyuk · Jul 1

Code Golf: $zcvt(str, "LEET")

Leet (or "1337"), also known as eleet or leetspeak, is a system of modified spellings used primarily on the Internet. It often uses character replacements in ways that play on the similarity of their glyphs via reflection or other resemblance. Additionally, it modifies certain words based on a system of suffixes and alternate meanings. There are many dialects or linguistic varieties in different online communities. Wikipedia

You'll have to translate a string into a LeetSpeak.
As usual shortest solution wins.






  • You must not repeat the same letter consecutively. The order of keys in the reference table is important!
    • example: Eeee must be 3€3€
  • The parameter could contain space
  • The set of used punctuation is ,.!?
  • Punctuation should be kept in your return string
  • If a key does not exist for a character on referece table below, keep the character as is.
    • example: He must be H3
  • Use this code to check the result length
  • You can also use this test case here


Letter Key(s)
A "4", "@"
B "|3", "8"
C "(", "<"
E "3", "€"
G "9", "6"
I "|", "]"
K "|<", "|{"
L "1", "£"
O "0", "*"
S "5", "$"
T "7", "+"
X "><", "}{"
Z "2", "~/_"


  1. The signature of the contest entry MUST be:
Class codeGolf.Leet

ClassMethod Convert(a As %String) As %String
  ; your code here


  1. It is forbidden to modify class/signature, including but not limited to:
  • Adding inheritance
  • Setting default argument values
  • Adding class elements (Parameters, Methods, Includes, etc).
  1. It is forbidden to refer to non-system code from your entry. For example, this is not a valid entry:
ClassMethod Convert(a As %String) As %String
  q ##class(myPackage.myClass).test(a)
  1. The use of $ZWPACK and $ZWBPACK is also discouraged.
0 353
Discussion (8)1
Log in or sign up to continue

I've got an answer in 242 characters but I think there's a mistake in the test case:

Do $$$AssertEquals(##class(CodeGolf.Leet).Convert("no no no no "), "n0 n* n0 n*")

Do $$$AssertEquals(##class(CodeGolf.Leet).Convert("Iris"), "|R]5")

The "n" doesn't get converted to uppercase but the "r" does. Surely it should be

Do $$$AssertEquals(##class(CodeGolf.Leet).Convert("Iris"), "|r]5")

and there's a rogue space at the end of "no no no no ".

Here's my answer. Looks like I'm playing on my own. 242 Chars, not including comments.

/// For rules see https://community.intersystems.com/post/code-golf-zcvtstr-leet
/// Build a list where each letter that is to be replaced
/// is followed in the list by its two possible replacements.
/// The next piece indicates which was the last replacement used.
/// Note: Only uppercase letters are in the list so need to
/// translate before searching, using $ZU(28,L,5) to translate.
/// For each character in the input string find its list position.
/// Use $LISTFIND to find its position.
/// Test the position found with Position-1#4
/// Not found characters return 0, and 0-1#4 is non zero so do nothing with them
/// Positions 1,5,9,11,15,19,23,27,31,35,39,43, and 47 contain characters
/// that must be replaced. Position-1#4 is zero for these.
/// No test case or rule for any of the destination symbols already existing in
/// the input string. Introducing that will complicate things as would need to test
/// character before and after current one to try to avoid double letters.
/// When each character is found change the last used replacement indicator.
/// Then return the replacement characters.
/// If the replacement characters contained any of the replaceable characters
/// then you would have to work backwards from the end of the input string
/// to avoid getting in a loop. This would cost 1 character.
ClassMethod Convert(As %String) As %String
r(L)P=$lf(A,$zu(28,L,5)) q:P-1#4 $LI(A,P+3)='$LG(A,P+3) $LI(A,P+2-$LG(A,P+3))

Check for "ZzX"

Instead of "2~/_X", there should be "2~/_><"

size = 201 (single line)

I did have a 220 in one line but your answer is superb.

A=$lfs("A,4,@,,B,|3,8,,C,(,<,,E,3,€,,G,9,6,,I,|,],,K,|<,|{,,L,1,£,,O,0,*,,S,5,$,,T,7,+,,X,><,}{,,Z,2,~/_") i=1:1:$l(x){L=$E(x,i),P=$lf(A,$zu(28,L,5))+3 s:P#4=0 $LI(A,P)='$LG(A,P),$e(x,i)=$LI(A,P-1-$LG(A,P))x

199 if I steal your ideas

 i=1:1:$l(a){x=$lfs("A,4,@,B,|3,8,C,(,<,E,3,€,G,9,6,I,|,],K,|<,|{,L,1,£,O,0,*,S,5,$,T,7,+,X,><,}{,Z,2,~/_"),c=$e(a,i),p=$lf(x,$$$UPPER(c)) s:k(p)=3-$g(k(p),2),c=$li(x,p+k(p)) r=$g(r)_cr