项目作者: myself379

项目描述 :
Cyclic Sort Katas
高级语言: PHP
项目地址: git://github.com/myself379/php-task-3-cyclic-sort.git
创建时间: 2018-05-15T16:47:35Z
项目社区:https://github.com/myself379/php-task-3-cyclic-sort

开源协议:

下载


Cyclic Sort Katas

Installation guide

Simply pull this repo and run

  1. composer install

composer_install

then run

  1. phpunit

phpunit

or if there is no phpunit install globally, run through the vendor directory

  1. ./vendor/phpunit/phpunit/phpunit

vendor_phpunit

Problem Statement

  1. /**
  2. * Cyclic sorts the input using the ordering.
  3. * @param string input The input string value.
  4. * @param int ordering The ordering, > 1.
  5. * @return The reordered output
  6. */
  7. function cyclicSort($input, $ordering) { }

Given an array with these items “A”, “B”, “C”, “D”, “E”, “F”, “G”, “H”, “I”, “J”; and the ordering of 7.

Counting from “A” and the 7th character is “G”.

So the first output character is “G”.

Remove “G” and remains “A”, “B”, “C”, “D”, “E”, “F”, “H”, “I”, “J”.

Then starting from “H”, count 7 in cyclic fashion (and roll over, starts from beginning), and reach “D”.

So the second output character is “D”.

Remove “D” and remains “A”, “B”, “C”, “E”, “F”, “H”, “I”, “J”.

Starting from “E” and count 7 in cyclic fashion (and roll over, starts from beginning) and reach “B”.

So the second output character is “B”.

Remove “B” and remains “A”, “C”, “E”, “F”, “H”, “I”, “J”.

Starting from “C” and count 7 and continue the process until nothing remains.

Finally, it should produce the output array of this order.

  1. "G", "D", "B", "A", "C", "F", "J", "E", "H", "I"
  1. $input = "ABCDEFGHIJ";
  2. $output = cyclicSort($input, 7);
  3. echo $output.PHP_EOL; // GDBACFJEHI

Tasks

  1. What is the output of “0123456789ABCDEF”, if the order is “11”?

  2. With the order is “13”, the sorted/scrambled message is given below:

  1. d nntobmeanhnld ftcitao.Laluw lyteuhtoohevet iGa rs llUnai coBn o oayg. p no .oddf .ityio gntire d. LoKrRiouyiG

What is the original message (before it was cyclically sorted)?