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) where

  • fct is the function of one variable f to apply to the string s (fct will be one of vertMirror, 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

More By Author:

Check out these other kata created by g964

Stats:

CreatedMar 6, 2016
PublishedMar 6, 2016
Warriors Trained46650
Total Skips11185
Total Code Submissions53110
Total Times Completed13969
Ruby Completions365
Python Completions3444
JavaScript Completions3475
CoffeeScript Completions18
Java Completions883
C# Completions545
Haskell Completions267
Clojure Completions210
C++ Completions693
PHP Completions644
TypeScript Completions412
F# Completions110
C Completions275
Crystal Completions22
Rust Completions485
Swift Completions642
R Completions99
Shell Completions101
Objective-C Completions28
OCaml Completions34
Julia Completions33
Scala Completions170
Go Completions524
Nim Completions11
Racket Completions24
Reason Completions6
Kotlin Completions449
Elixir Completions65
Prolog Completions17
Pascal Completions12
Dart Completions414
Lua Completions71
Perl Completions30
Elm Completions15
D Completions8
Erlang Completions12
Total Stars583
% of votes with a positive feedback rating90% of 2024
Total "Very Satisfied" Votes1680
Total "Somewhat Satisfied" Votes279
Total "Not Satisfied" Votes65
Ad
Contributors
  • g964 Avatar
  • myjinxin2015 Avatar
  • donaldsebleung Avatar
  • ParanoidUser Avatar
  • kazk Avatar
  • B1ts Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • 4500zenja1 Avatar
  • saudiGuy Avatar
Ad