6 kyu
Reverse or rotate?
978 of 24,428g964
Description:
The input is a string str
of digits. Cut the string into chunks (a chunk here is a substring of the initial string) of size sz
(ignore the last chunk if its size is less than sz
).
If the sum of a chunk's digits is divisible by 2
, reverse that chunk;
otherwise rotate it to the left by one position.
Put together these modified chunks and return the result as a string.
If
sz
is<= 0
or ifstr == ""
return ""sz
is greater(>)
than the length ofstr
it is impossible to take a chunk of sizesz
hence return "".
Examples:
("123456987654", 6) --> "234561876549"
("123456987653", 6) --> "234561356789"
("66443875", 4) --> "44668753"
("66443875", 8) --> "64438756"
("664438769", 8) --> "67834466"
("123456779", 8) --> "23456771"
("", 8) --> ""
("123456779", 0) --> ""
("563000655734469485", 4) --> "0365065073456944"
Example of a string rotated to the left by one position:
s = "123456" gives "234561".
Algorithms
Strings
Similar Kata:
Stats:
Created | Feb 6, 2016 |
Published | Feb 6, 2016 |
Warriors Trained | 90408 |
Total Skips | 29860 |
Total Code Submissions | 144004 |
Total Times Completed | 24428 |
Ruby Completions | 978 |
Python Completions | 5893 |
JavaScript Completions | 7134 |
CoffeeScript Completions | 24 |
Haskell Completions | 321 |
Clojure Completions | 128 |
C# Completions | 1120 |
Java Completions | 2553 |
Elixir Completions | 208 |
C++ Completions | 1673 |
PHP Completions | 892 |
TypeScript Completions | 772 |
Crystal Completions | 23 |
F# Completions | 76 |
C Completions | 629 |
Rust Completions | 499 |
Swift Completions | 316 |
R Completions | 86 |
Shell Completions | 70 |
OCaml Completions | 31 |
Kotlin Completions | 562 |
Scala Completions | 149 |
Julia Completions | 38 |
PowerShell Completions | 38 |
Go Completions | 591 |
Nim Completions | 8 |
Racket Completions | 24 |
Reason Completions | 1 |
VB Completions | 30 |
Lua Completions | 85 |
Pascal Completions | 7 |
Perl Completions | 17 |
Elm Completions | 2 |
D Completions | 6 |
COBOL Completions | 4 |
Total Stars | 1243 |
% of votes with a positive feedback rating | 87% of 3145 |
Total "Very Satisfied" Votes | 2433 |
Total "Somewhat Satisfied" Votes | 589 |
Total "Not Satisfied" Votes | 123 |