7 kyu
Moves in squared strings (I)
365 of 13,969g964
Description:
This kata is the first of a sequence of four about "Squared Strings".
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.
- Vertical mirror:
vert_mirror (or vertMirror or vert-mirror)
vert_mirror(s) => "dcba\nhgfe\nlkji\nponm"
- Horizontal mirror:
hor_mirror (or horMirror or hor-mirror)
hor_mirror(s) => "mnop\nijkl\nefgh\nabcd"
or printed:
vertical mirror |horizontal mirror
abcd --> dcba |abcd --> mnop
efgh hgfe |efgh ijkl
ijkl lkji |ijkl efgh
mnop ponm |mnop abcd
Task:
- Write these two functions
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 ofvertMirror, horMirror
)
Examples:
s = "abcd\nefgh\nijkl\nmnop"
oper(vert_mirror, s) => "dcba\nhgfe\nlkji\nponm"
oper(hor_mirror, s) => "mnop\nijkl\nefgh\nabcd"
Note:
The form of the parameter fct
in oper
changes according to the language. You can see each form according to the language in "Sample Tests".
Bash Note:
The input strings are separated by ,
instead of \n
. The output strings should be separated by \r
instead of \n
. See "Sample Tests".
Fundamentals
Algorithms
Strings
Similar Kata:
Stats:
Created | Mar 6, 2016 |
Published | Mar 6, 2016 |
Warriors Trained | 46650 |
Total Skips | 11185 |
Total Code Submissions | 53110 |
Total Times Completed | 13969 |
Ruby Completions | 365 |
Python Completions | 3444 |
JavaScript Completions | 3475 |
CoffeeScript Completions | 18 |
Java Completions | 883 |
C# Completions | 545 |
Haskell Completions | 267 |
Clojure Completions | 210 |
C++ Completions | 693 |
PHP Completions | 644 |
TypeScript Completions | 412 |
F# Completions | 110 |
C Completions | 275 |
Crystal Completions | 22 |
Rust Completions | 485 |
Swift Completions | 642 |
R Completions | 99 |
Shell Completions | 101 |
Objective-C Completions | 28 |
OCaml Completions | 34 |
Julia Completions | 33 |
Scala Completions | 170 |
Go Completions | 524 |
Nim Completions | 11 |
Racket Completions | 24 |
Reason Completions | 6 |
Kotlin Completions | 449 |
Elixir Completions | 65 |
Prolog Completions | 17 |
Pascal Completions | 12 |
Dart Completions | 414 |
Lua Completions | 71 |
Perl Completions | 30 |
Elm Completions | 15 |
D Completions | 8 |
Erlang Completions | 12 |
Total Stars | 583 |
% of votes with a positive feedback rating | 90% of 2024 |
Total "Very Satisfied" Votes | 1680 |
Total "Somewhat Satisfied" Votes | 279 |
Total "Not Satisfied" Votes | 65 |