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,25 @@
func encode(str) {
var table = ('a'..'z' -> join);
str.chars.map { |c|
var s = '';
table.sub!(Regex('(.*?)' + c), {|s1| s=s1; c + s1});
s.len;
}
}
func decode(nums) {
var table = ('a'..'z' -> join);
nums.map { |n|
var s = '';
table.sub!(Regex('(.{' + n + '})(.)'), {|s1, s2| s=s2; s2 + s1});
s;
}.join;
}
%w(broood bananaaa hiphophiphop).each { |test|
var encoded = encode(test);
say "#{test}: #{encoded}";
var decoded = decode(encoded);
print "in" if (decoded != test);
say "correctly decoded to #{decoded}";
}

View file

@ -0,0 +1,36 @@
module MoveToFront {
define ABC = @("a".."z")
func m2f(ar,i) {
[ar.delete_index(i)] + ar
}
func encode(str) {
var ar = ABC+[]
gather {
str.each_char { |char|
take(var i = ar.index(char))
ar = m2f(ar, i);
}
}
}
func decode(indices) {
var ar = ABC+[]
gather {
indices.each { |i|
take ar[i];
ar = m2f(ar, i)
}
}.join
}
}
%w(broood bananaaa hiphophiphop).each { |test|
var encoded = MoveToFront::encode(test);
say "#{test}: #{encoded}";
var decoded = MoveToFront::decode(encoded);
print "in" if (decoded != test);
say "correctly decoded to #{decoded}";
}