["112" "5624-82" "4824" "0721/608-4067" "10/783--5" "1078-913-5" "381482" "04824"] `Phone set \ test numbers; ["an" "blau" "Bo\"" "Boot" "bo\"s" "da" "Fee" "fern" "Fest" "fort" "je" "jemand" "mir" "Mix" "Mixer" "Name" "neu" "o\"d" "Ort" "so" "Tor" "Torf" "Wasser"] `Word set \ test words; ["ejnqrwxdsyftamcivbkulopghz" "01112223334455666777888999"] `Map set \ char -> int; [ic 256 !: 26 !: 65 + [+] 32 amend4 @. ci] `lc def \ upper -> lower; [Map 0 @ [?.] left Map 1 @ @.] `mp def \ string -> syms; Word ["\"" dv lc mp] map `Digit set \ words -> digits; Digit [#:] map `Count set \ count each digit-string; Count =: `Part set \ partiton vector; Digit Part @ `Digit set \ partition digits; Word Part @ `Word set \ partition words; Digit [hash] map `Hash set \ hash each digit partition; Count ?: `Count set \ count of each partition; [1 ":" dup "/-" dvl match [,] right] `codes def \ try to encode a single phone number; [[b m n] [[[n #: ~:] m ,] [[r #: ] r ] [[b ] ] [r]] case] lambda `match def \ ; [[m n d w c p h] [[c n #: >] []] [[d #: // phonecodes / map characters to integers, setup setup:{D@:p:=C::#:'D::digit'W;W@:p;C?:;P::=:'D;H::_hash'D::D@'P[;;0]} digit:{M[1;M[0]?/:_dv[(_ci@[!256;65+!26;+;32])@_ic x;"\""]]} M:("ejnqrwxdsyftamcivbkulopghz";"01112223334455666777888999") / phonecodes codes:{x,/:match[1;":";x _dvl"/-"]} match:{[b;m;n]:[~#n;,m;#r:,/find[m;n]'[D;W;C;P;H];r;b;_f[0;m," ",*n;1_ n];r]} find:{[m;n;d;w;c;p;h]:[c>#n;();(#d)>i:(d;h)?c#n;,/w[p i]{m," ",x,y}/:\:match[1;"";c _ n];()]} \ W:0:"w.txt" N:0:"n.txt" setup[] \t ,/codes'N 5624-82: mir Tor 5624-82: Mix Tor 4824: fort 4824: Tor 4 4824: Torf 10/783--5: je Bo" da 10/783--5: je bo"s 5 10/783--5: neu o"d 5 381482: so 1 Tor 04824: 0 fort 04824: 0 Tor 4 04824: 0 Torf \\ slow #1, uses _sm: codes:{x,/:match[1;":";x _dvl"/-"]} match:{[b;p;n]:[~#n;,p;#r:,/{match[1;p," ",W x;(-1+#D x)_ n]}'initial n;r;b;match[0;p," ",*n;1_ n];r]} initial:{[n]k@&n _sm/:D k:&D[;0]=*n} M:{@[_n;`$',/x;:;&#:'x]}("e";"jnq";"rwx";"dsy";"ft";"am";"civ";"bku";"lop";"ghz") map:{1!"*",,/$M@`$'x} / map chars to digits, append wildcard lc:(_ci@[!256;65+!26;+;32])@_ic$: / -> lower case nq:_dv[;"\""] / no umlauts D:(map nq lc@)'W \\ slow #2, uses _ss codes:{ o@:i:&0<#:'o:n _ss/:D k:&~C>#n:x _dvl"/-" i@:&#:'o;i@:j: lower case nq:_dv[;"\""] / no umlauts C:#:'D:(map nq lc@)'W