Best shuffle: Difference between revisions
Content added Content deleted
imported>Arakov |
(Added Easylang) |
||
Line 2,204: | Line 2,204: | ||
end. |
end. |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|EasyLang}}== |
|||
{{trans|C}} (deterministic) |
|||
<syntaxhighlight> |
|||
proc best_shuffle s$ . r$ diff . |
|||
l = len s$ |
|||
for c$ in strchars s$ |
|||
s[] &= strcode c$ |
|||
. |
|||
len cnt[] 128 |
|||
for i to l |
|||
cnt[s[i]] += 1 |
|||
max = higher max cnt[s[i]] |
|||
. |
|||
for i to 128 |
|||
while cnt[i] > 0 |
|||
cnt[i] -= 1 |
|||
buf[] &= i |
|||
. |
|||
. |
|||
r[] = s[] |
|||
for i to l |
|||
for j to l |
|||
if r[i] = buf[j] |
|||
r[i] = buf[(j + max) mod1 l] mod 128 |
|||
if buf[j] <= 128 |
|||
buf[j] += 128 |
|||
. |
|||
break 1 |
|||
. |
|||
. |
|||
. |
|||
diff = 0 |
|||
r$ = "" |
|||
for i to l |
|||
diff += if r[i] = s[i] |
|||
r$ &= strchar r[i] |
|||
. |
|||
. |
|||
for s$ in [ "abracadabra" "seesaw" "elk" "grrrrrr" "up" "a" ] |
|||
best_shuffle s$ r$ d |
|||
print s$ & " " & r$ & " " & d |
|||
. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
abracadabra brabacadaar 0 |
|||
seesaw wssaee 0 |
|||
elk kel 0 |
|||
grrrrrr rgrrrrr 5 |
|||
up pu 0 |
|||
a a 1 |
|||
</pre> |
|||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
ELENA 6.x : |
ELENA 6.x : |