6 kyu
Moves in squared strings (II)
152 of 5,006g964
Description:
You are given a string of n
lines, each substring being n
characters long: For example:
s = "abcd\nefgh\nijkl\nmnop"
We will study some transformations of this square of strings.
- rot(s):
Clock rotation 180 degrees.rot(s) => "ponm\nlkji\nhgfe\ndcba"
- selfie_and_rot(s) (or selfieAndRot or selfie-and-rot):
It is an initial string combined with its 180-degree clock-rotated version, interspersed with dots proportional to the length of the segments, to better illustrate the rotation when printed.s = "abcd\nefgh\nijkl\nmnop" --> "abcd....\nefgh....\nijkl....\nmnop....\n....ponm\n....lkji\n....hgfe\n....dcba"
On printing, these functions work as follows:
|rot |selfie_and_rot
|abcd --> ponm |abcd --> abcd....
|efgh lkji |efgh efgh....
|ijkl hgfe |ijkl ijkl....
|mnop dcba |mnop mnop....
....ponm
....lkji
....hgfe
....dcba
Notice that the number of dots is the common length of "abcd", "efgh", "ijkl", "mnop".
Task:
- Write these two functions
rot
andselfie_and_rot
and
high-order function
oper(fct, s)
wherefct is the function of one variable f to apply to the string
s
(fct will be one ofrot, selfie_and_rot
)
Examples:
s = "abcd\nefgh\nijkl\nmnop"
oper(rot, s) => "ponm\nlkji\nhgfe\ndcba"
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".
Algorithms
Strings
Similar Kata:
Stats:
Created | Mar 6, 2016 |
Published | Mar 6, 2016 |
Warriors Trained | 19458 |
Total Skips | 7179 |
Total Code Submissions | 24854 |
Total Times Completed | 5006 |
Ruby Completions | 152 |
Python Completions | 1268 |
JavaScript Completions | 1129 |
CoffeeScript Completions | 12 |
Java Completions | 394 |
C# Completions | 250 |
Haskell Completions | 110 |
Clojure Completions | 61 |
C++ Completions | 381 |
PHP Completions | 226 |
TypeScript Completions | 152 |
F# Completions | 36 |
C Completions | 162 |
Crystal Completions | 11 |
Rust Completions | 198 |
Swift Completions | 143 |
R Completions | 45 |
Shell Completions | 40 |
Objective-C Completions | 13 |
OCaml Completions | 21 |
Scala Completions | 66 |
Julia Completions | 21 |
Go Completions | 111 |
Nim Completions | 7 |
Racket Completions | 15 |
Kotlin Completions | 92 |
Prolog Completions | 12 |
Dart Completions | 110 |
Pascal Completions | 4 |
Lua Completions | 33 |
Perl Completions | 10 |
Elm Completions | 6 |
D Completions | 8 |
Erlang Completions | 5 |
Total Stars | 252 |
% of votes with a positive feedback rating | 90% of 855 |
Total "Very Satisfied" Votes | 702 |
Total "Somewhat Satisfied" Votes | 127 |
Total "Not Satisfied" Votes | 26 |