Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
48
Task/Best-shuffle/Elena/best-shuffle.elena
Normal file
48
Task/Best-shuffle/Elena/best-shuffle.elena
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import system'routines;
|
||||
import extensions;
|
||||
import extensions'text;
|
||||
|
||||
extension op
|
||||
{
|
||||
get Shuffled()
|
||||
{
|
||||
var original := self.toArray();
|
||||
var shuffled := self.toArray();
|
||||
|
||||
for (int i := 0, i < original.Length, i += 1) {
|
||||
for (int j := 0, j < original.Length, j += 1) {
|
||||
if (i != j && original[i] != shuffled[j] && original[j] != shuffled[i])
|
||||
{
|
||||
shuffled.exchange(i,j)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
^ shuffled.summarize(new StringWriter()).toString()
|
||||
}
|
||||
|
||||
score(originalText)
|
||||
{
|
||||
var shuffled := self.toArray();
|
||||
var original := originalText.toArray();
|
||||
int score := 0;
|
||||
|
||||
for (int i := 0, i < original.Length, i += 1) {
|
||||
if (original[i] == shuffled[i]) { score += 1 }
|
||||
};
|
||||
|
||||
^ score
|
||||
}
|
||||
}
|
||||
|
||||
public program()
|
||||
{
|
||||
new string[]{"abracadabra", "seesaw", "grrrrrr", "pop", "up", "a"}.forEach:(s)
|
||||
{
|
||||
var shuffled_s := s.Shuffled;
|
||||
|
||||
console.printLine("The best shuffle of ",s," is ",shuffled_s,"(",shuffled_s.score(s),")")
|
||||
};
|
||||
|
||||
console.readChar()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue