6 kyu
Reverse or rotate?
974 of 24,174g964
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 | 89900 |
Total Skips | 29772 |
Total Code Submissions | 143010 |
Total Times Completed | 24174 |
Ruby Completions | 974 |
Python Completions | 5817 |
JavaScript Completions | 7069 |
CoffeeScript Completions | 24 |
Haskell Completions | 319 |
Clojure Completions | 128 |
C# Completions | 1110 |
Java Completions | 2535 |
Elixir Completions | 206 |
C++ Completions | 1658 |
PHP Completions | 884 |
TypeScript Completions | 759 |
Crystal Completions | 23 |
F# Completions | 76 |
C Completions | 628 |
Rust Completions | 488 |
Swift Completions | 312 |
R Completions | 86 |
Shell Completions | 69 |
OCaml Completions | 30 |
Kotlin Completions | 552 |
Scala Completions | 149 |
Julia Completions | 38 |
PowerShell Completions | 37 |
Go Completions | 580 |
Nim Completions | 8 |
Racket Completions | 24 |
Reason Completions | 1 |
VB Completions | 27 |
Lua Completions | 80 |
Pascal Completions | 7 |
Perl Completions | 16 |
Elm Completions | 2 |
D Completions | 6 |
COBOL Completions | 4 |
Total Stars | 1237 |
% of votes with a positive feedback rating | 87% of 3130 |
Total "Very Satisfied" Votes | 2419 |
Total "Somewhat Satisfied" Votes | 588 |
Total "Not Satisfied" Votes | 123 |