[关闭]
@aloyschen 2017-10-09T15:22:20.000000Z 字数 1420 阅读 70

CodeWars 刷题总结

CodeWars


Moves in squared strings

You are given a string of n lines, each substring being n characters long: For example:

  1. s = "abcd\nefgh\nijkl\nmnop"

We will study some transformations of this square of strings.

  1. rot(s) => "ponm\nlkji\nhgfe\ndcba"
  1. s = "abcd\nefgh\nijkl\nmnop" -->
  2. "abcd....\nefgh....\nijkl....\nmnop....\n....ponm\n....lkji\n....hgfe\n....dcba"

or printed:

  1. |rotation |selfie_and_rot
  2. |abcd --> ponm |abcd --> abcd....
  3. |efgh lkji |efgh efgh....
  4. |ijkl hgfe |ijkl ijkl....
  5. |mnop dcba |mnop mnop....
  6. ....ponm
  7. ....lkji
  8. ....hgfe
  9. ....dcba

Task:

Write these two functions rotand selfie_and_rot
and

high-order function oper(fct, s) where

fct is the function of one variable f to apply to the string s (fct will be one of rot, selfie_and_rot)

Examples:

  1. s = "abcd\nefgh\nijkl\nmnop"
  2. oper(rot, s) => "ponm\nlkji\nhgfe\ndcba"
  3. oper(selfie_and_rot, s) => "abcd....\nefgh....\nijkl....\nmnop....\n....ponm\n....lkji\n....hgfe\n....dcba"

Notes:

The form of the parameter fct in oper changes according to the language. You can see each form according to the language in "Your test cases".
It could be easier to take these katas from number (I) to number (IV)
Forthcoming katas will study other tranformations.

Bash Note:

The input strings are separated by , instead of \n. The ouput strings should be separated by \r instead of \n. See "Sample Tests".

知识点

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注