You may have a look to the standard library documentation to find useful functions and methods for solving the following exercises.
The series expansion of
Evaluate
We define super digit of an integer x as follows:
- if x has only 1 digit, then its super digit is x;
- otherwise, the super digit of x is equal to the super digit of the sum of its digits.
For example, the super digit of 3 is calculated as
super_digit(3) = 3
Instead, the super digit of
super_digit(148148148) = super_digit(1+4+8+1+4+8+1+4+8)
= super_digit(39)
= super_digit(3+9)
= super_digit(12)
= super_digit(1+2)
= super_digit(3)
= 3.
Write a function super_digit
that given an integer n
returns the super digit of n
.
Write a function array_replication
that, given an array l
and a natural number n
, returns a new slice where each element is replicated n
times. For example, if l = [1;2;3;4]
and n = 3
, the result of list_replication l n
is [1;1;1;2;2;2;3;3;3;4;4;4]
.
Write a function array_replication1
that, given a list l
and a natural number n
, returns a new list that is obtained by concatenating l
with itself n
times. For example, if l = [1;2;3;4]
and n = 3
, the result of list_replication l n
is [1;2;3;4;1;2;3;4;1;2;3;4]
.
Write a function swap_adjacent
that given a string of length l
with l
even swap the characters at position i
and i+1
for all i
even in [0, l - 1]
. For example, swap_adjacent "abcdpqrs"
returns "badcqpsr"
.
Write a function mingle_string
that given two string p
and q
of the same lenght and mingles them together.
For example, mingle_string "abcde" "pqrst"
returns "apbqcrdset"
.
Write a function anagrams
that given a slice of strings ([]string
) returns a slice of slices of string ([][]string
), where each row contains words that are one the anagram of the others.