Most frequent k chars distance: Difference between revisions
Content added Content deleted
(Added Wren) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 141: | Line 141: | ||
MostFreqKHashing(str2,2) = F9L8 |
MostFreqKHashing(str2,2) = F9L8 |
||
MostFreqKSDF(str1,str2,2,100) = 83 |
MostFreqKSDF(str1,str2,2,100) = 83 |
||
</pre> |
|||
=={{header|11l}}== |
|||
{{trans|Python}} |
|||
<lang 11l>F most_freq_khashing(inputString, K) |
|||
DefaultDict[Char, Int] occuDict |
|||
L(c) inputString |
|||
occuDict[c]++ |
|||
V occuList = sorted(occuDict.items(), key' x -> x[1], reverse' 1B) |
|||
V outputDict = Dict(occuList[0 .< K]) |
|||
R outputDict |
|||
F most_freq_ksimilarity(inputStr1, inputStr2) |
|||
V similarity = 0 |
|||
L(c, cnt1) inputStr1 |
|||
I c C inputStr2 |
|||
V cnt2 = inputStr2[c] |
|||
similarity += cnt1 + cnt2 |
|||
R similarity |
|||
F most_freq_ksdf(inputStr1, inputStr2, K, maxDistance) |
|||
R maxDistance - most_freq_ksimilarity(most_freq_khashing(inputStr1, K), most_freq_khashing(inputStr2, K)) |
|||
V str1 = ‘LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV’ |
|||
V str2 = ‘EWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLG’ |
|||
V K = 2 |
|||
V maxDistance = 100 |
|||
V dict1 = most_freq_khashing(str1, 2) |
|||
print(dict1, end' ":\n") |
|||
print(dict1.map((c, cnt) -> c‘’String(cnt)).join(‘’)) |
|||
V dict2 = most_freq_khashing(str2, 2) |
|||
print(dict2, end' ":\n") |
|||
print(dict2.map((c, cnt) -> c‘’String(cnt)).join(‘’)) |
|||
print(most_freq_ksdf(str1, str2, K, maxDistance))</lang> |
|||
{{out}} |
|||
<pre> |
|||
[L = 9, T = 8]: |
|||
L9T8 |
|||
[F = 9, L = 8]: |
|||
F9L8 |
|||
83 |
|||
</pre> |
</pre> |
||