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 if str == "" return ""
  • sz is greater (>) than the length of str it is impossible to take a chunk of size sz 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

Stats:

CreatedFeb 6, 2016
PublishedFeb 6, 2016
Warriors Trained90408
Total Skips29860
Total Code Submissions144004
Total Times Completed24428
Ruby Completions978
Python Completions5893
JavaScript Completions7134
CoffeeScript Completions24
Haskell Completions321
Clojure Completions128
C# Completions1120
Java Completions2553
Elixir Completions208
C++ Completions1673
PHP Completions892
TypeScript Completions772
Crystal Completions23
F# Completions76
C Completions629
Rust Completions499
Swift Completions316
R Completions86
Shell Completions70
OCaml Completions31
Kotlin Completions562
Scala Completions149
Julia Completions38
PowerShell Completions38
Go Completions591
Nim Completions8
Racket Completions24
Reason Completions1
VB Completions30
Lua Completions85
Pascal Completions7
Perl Completions17
Elm Completions2
D Completions6
COBOL Completions4
Total Stars1243
% of votes with a positive feedback rating87% of 3145
Total "Very Satisfied" Votes2433
Total "Somewhat Satisfied" Votes589
Total "Not Satisfied" Votes123
Ad
Contributors
  • g964 Avatar
  • NaMe613 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • FArekkusu Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
Ad