Coding with Squared Strings
Description:
A squared string has n lines, each substring being n characters long: For example:
s = "abcd\nefgh\nijkl\nmnop"
is a squared string of size 4
.
We will use squared strings to code and decode texts. To make things easier we suppose that our original text doesn't include the character '\n'.
Coding
Input:
- a text
t
of lengthl
. - Consider the smallest integer
n
such thatn * n
be greater or equal tol
. - Complete
t
with the char of ascii code11
(we suppose that this char is not in our original text) until the length oft
isn * n
. - From now on we can transform the new
t
in a squared strings
of sizen
by inserting'\n'
where needed. - Apply a clockwise rotation of 90 degrees to
s
: that's it for the coding part.
Decoding
Input:
- a squared string
s
resulting from the coding - Apply a counter-clockwise rotation of 90 degrees to
s
- Do some cleaning to have the original text
t
You can see clockwise rotation of 90 degrees: http://www.codewars.com/kata/56dbeec613c2f63be4000be6 You can see counter-clockwise rotation of 90 degrees: http://www.codewars.com/kata/56dbf59b0a10feb08c000227
Example:
t = "I.was.going.fishing.that.morning.at.ten.o'clock"
code(t) -> "c.nhsoI\nltiahi.\noentinw\ncng.nga\nk..mg.s\n\voao.f.\n\v'trtig"
decode(code(t)) == "I.was.going.fishing.that.morning.at.ten.o'clock"
(Dots indicate spaces since they are quite invisible).
Notes:
Swift : character
11
is replaced by"\u{F7}"
(ie"÷"
-alt 246
-)Ocaml : character
11
is replaced by '&'Perl : character
11
is replaced by '&'Fortran: Your returned string for both functions are not permitted to contain redundant leading/trailing whitespace. In return, you may safely assume that all input strings passed into your function(s) will not contain redundant leading/trailing whitespace, i.e. you do not and should not trim the input string before operating on it
Don't use this coding to keep your secrets:-)
Similar Kata:
Stats:
Created | Mar 31, 2016 |
Published | Mar 31, 2016 |
Warriors Trained | 16725 |
Total Skips | 6336 |
Total Code Submissions | 13986 |
Total Times Completed | 2129 |
Ruby Completions | 71 |
Python Completions | 575 |
JavaScript Completions | 301 |
Haskell Completions | 73 |
Clojure Completions | 33 |
Java Completions | 209 |
C# Completions | 140 |
CoffeeScript Completions | 10 |
PHP Completions | 84 |
C++ Completions | 224 |
Crystal Completions | 9 |
C Completions | 120 |
TypeScript Completions | 98 |
Swift Completions | 48 |
F# Completions | 22 |
OCaml Completions | 17 |
Fortran Completions | 5 |
Scala Completions | 34 |
Julia Completions | 18 |
R Completions | 24 |
Go Completions | 83 |
Nim Completions | 5 |
Racket Completions | 7 |
Rust Completions | 61 |
Perl Completions | 8 |
Erlang Completions | 6 |
Prolog Completions | 7 |
Total Stars | 302 |
% of votes with a positive feedback rating | 89% of 410 |
Total "Very Satisfied" Votes | 330 |
Total "Somewhat Satisfied" Votes | 69 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 8 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |