Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,15 @@
constant tests = {"abracadabra", "seesaw", "elk", "grrrrrr", "up", "a"}
string s,t
for test=1 to length(tests) do
s = tests[test]
t = shuffle(s)
for i=1 to length(t) do
for j=1 to length(t) do
if i!=j and t[i]!=s[j] and t[j]!=s[i] then
{t[i], t[j]} = {t[j], t[i]}
exit
end if
end for
end for
printf(1,"%s -> %s (%d)\n",{s,t,sum(sq_eq(t,s))})
end for

View file

@ -0,0 +1,22 @@
func best_shuffle(String orig) -> (String, Number) {
var s = orig.chars
var t = s.shuffle
s.range.each { |i|
s.range.each { |j|
if (i!=j && t[i]!=s[j] && t[j]!=s[i]) {
t[i, j] = t[j, i];
break;
}
}
}
var word = t.join;
(word, orig ^ word -> count("\0"));
}
<abracadabra seesaw elk grrrrrr up a>.each { |word|
var (sword, score) = best_shuffle(word)
"%-12s %12s: %d\n".printf(word, sword, score)
}