====== Computer Lab 08, Automated testing ====== * Q/A * Practical work ===== Practical work ===== ==== Josephus problem ==== Read about the [[https://en.wikipedia.org/wiki/Josephus_problem|Josephus problem]]. ==== Josephus permutation ==== In module ''josephus.py'', create function ''josephus_permutation'' that will output items of the given sequence in the order of execution. def josephus_permutation(seq, start=0, skip=0): """ Return Josephus permutation of the given sequence. :param seq: Any sequence (list, string, ...) to be permuted. :param start: int, an index of item where the counting shall start. :param skip: int, how many items shall be skipped :return: permuted list of items of the same length as the original seq >>> josephus_permutation([1, 2, 3]) [1, 2, 3] >>> josephus_permutation([1, 2, 3, 4, 5], start=3) [4, 5, 1, 2, 3] >>> josephus_permutation([1, 2, 3, 4, 5], skip=3) [4, 3, 5, 2, 1] >>> josephus_permutation([1, 2, 3, 4, 5], start=3, skip=2) [1, 4, 3, 5, 2] """ **Test the function** during development. ==== Survivor ==== In module ''josephus.py'', create function ''survivor'' which will return the index of the last item in the Josephus permutation. You should implement the function without actually constructing the permutation! (But you can use function ''josephus_permutation'' to create your test cases.) def survivor(seq, start=0, skip=0): """ Return the last element of Josephus permutation of the given sequence :param seq: Any sequence (list, string, ...) to be permuted. :param start: int, an index of item where the counting shall start. :param skip: int, how many items shall be skipped :return: item of seq, the last one in the respective Jos. permutation >>> survivor([1, 2, 3]) 3 >>> survivor([1, 2, 3, 4, 5], start=3) 3 >>> survivor([1, 2, 3, 4, 5], skip=3) 1 >>> survivor([1, 2, 3, 4, 5], start=3, skip=2) 2 """ **Create your own additional test cases!** ===== Homework ===== * Finish the above tasks. * Read [[http://openbookproject.net/thinkcs/python/english3e/dictionaries.html|chapter 20 - Dictionaries]] of {[a4b99rph:Wenthworth]}.