7 kyu

Rotate for a Max

57 of 11,050g964

Description:

Let us begin with an example:

Take a number: 56789. Rotate left, you get 67895.

Keep the first digit in place and rotate left the other digits: 68957.

Keep the first two digits in place and rotate the other ones: 68579.

Keep the first three digits and rotate left the rest: 68597. Now it is over since keeping the first four it remains only one digit which rotated is itself.

You have the following sequence of numbers:

56789 -> 67895 -> 68957 -> 68579 -> 68597

and you must return the greatest: 68957.

Task

Write function max_rot(n) which given a positive integer n returns the maximum number you got doing rotations similar to the above example.

So max_rot (or maxRot or ... depending on the language) is such as:

  • max_rot(56789) should return 68957

  • max_rot(38458215) should return 85821534

Algorithms

Similar Kata:

More By Author:

Check out these other kata created by g964

Stats:

CreatedJan 24, 2016
PublishedJan 24, 2016
Warriors Trained39086
Total Skips7214
Total Code Submissions89665
Total Times Completed11050
Ruby Completions329
Python Completions2893
JavaScript Completions2941
CoffeeScript Completions18
Haskell Completions140
Clojure Completions75
C# Completions593
Java Completions1760
Elixir Completions153
C++ Completions850
PHP Completions551
TypeScript Completions253
Crystal Completions9
F# Completions66
C Completions346
Shell Completions135
OCaml Completions33
Kotlin Completions380
Julia Completions18
R Completions68
PowerShell Completions55
Go Completions397
Nim Completions9
Racket Completions23
Reason Completions3
Scala Completions57
Perl Completions38
Prolog Completions7
Rust Completions111
Lua Completions56
Factor Completions10
Total Stars653
% of votes with a positive feedback rating86% of 1683
Total "Very Satisfied" Votes1303
Total "Somewhat Satisfied" Votes288
Total "Not Satisfied" Votes92
Ad
Contributors
  • g964 Avatar
  • NaMe613 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • B1ts Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • Madjosz Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • Kacarott Avatar
  • razetime Avatar
  • KayleighWasTaken Avatar
Ad