Anonymous user
Best shuffle: Difference between revisions
→{{header|Elena}}
m (→{{header|REXX}}: added/changed whitespace and comments, changed indentations.) |
|||
Line 1,264:
#define extensions.
#class(extension)op
{
#method shuffled
#var aShuffled := convertor toArray:aLiteral.▼
[
#var
[
[
▲ ].
].
].
^ false.▼
▲ ].
^ control run:aShuffled &forEach:(Summing new:(String new)) literal.▼
#var aScore := Integer new.▼
▲ control run &int:0 &int:(anOriginal length - 1) &forEvery: (&index:i)
]
[ ((anOriginal @ i) == (aShuffled @ i)) ? [ aScore += 1. ]. ].▼
#method score : anOriginalText
[
#var anOriginal := anOriginalText toArray.
▲ #var aScore := Integer new.
0 to:(anOriginal length - 1) &doEach: (:i)
▲ [ ((anOriginal @ i) == (aShuffled @ i)) ? [ aScore += 1. ]. ].
]
}
#symbol program =
[
[
#var aShuffled :=
].
console readChar.
].</lang>
{{out}}
<pre>
The best shuffle of abracadabra is caadrbabaar(0)
The best shuffle of seesaw is ewaess(0)
The best shuffle of grrrrrr is rgrrrrr(5)
The best shuffle of pop is opp(1)
The best shuffle of up is pu(0)
The best shuffle of a is a(1)
</pre>
=={{header|Erlang}}==
|