Here is the easy algorithm we are taught for adding two numbers in base-10 notation. We are taught this algorithm in first or second grade.
sub infix:<+>(@x, @y) { #x, y are lists of digits #returns a list of digits my @greater = (@y.elems > @x.elems) ?? @y !! @x; my @lesser_ = (@y.elems > @x.elems) ?? @x !! @y; my @gPopped = @greater; my @lPopped = @lesser_; my $ carry = 0; my @sum; loop (my $ i = 0; $ i < @greater.elems; $ i++) { if (@lPopped.elems >= 1) { my $ gDigit = @gPopped.tail; my $ lDigit = @lPopped.tail; @sum.append: (($ gDigit + $ lDigit) % 10) + $ carry; $ carry = (($ gDigit + $ lDigit) / 10).floor; @lPopped = @lPopped.head(@lPopped.elems - 1); @gPopped = @gPopped.head(@gPopped.elems - 1); } else { my $ gDigit = @gPopped.tail; @sum.append: $ gDigit + $ carry; $ carry = 0; @gPopped = @gPopped.head(@gPopped.elems - 1); } } return @sum.reverse; }
The algorithm is very easy and a child can do it by hand. Meanwhile, I am unaware of any algorithm for multiplying two permutations decomposed into cycle form (e.g. $ (123)\times(12)(34)$ ). What is an easy algorithm for multiplying two cycles?