[Question]
  [
## The task
This is a simple challenge.
Your input is a single non-empty string, containing only digits `0123456789` and hashes `#`.
It will contain exactly one run of digits, which encodes a nonnegative integer and may wrap around the end of the string, and at least one `#`.
The integer may have leading zeroes.
For example, `##44##`, `013####` and `23###1` are valid inputs, while `###`, `0099` and `#4#4` are not.
Your task is to extract the integer `n` from the string, and output the string rotated `n` steps to the right.
## Examples
* The input `#1##` should be rotated 1 step to the right, so the correct output is `##1#`.
* The input `#026###` should be rotated 26 steps to the right, since the leading 0 is ignored. The correct output is `26####0`.
* The input `1####2` contains the integer 21 wrapped over the end, so it should be rotated 21 steps to the right. The correct output is `##21##`.
## Rules and scoring
You can write a full program or a function.
The lowest byte count wins, and standard loopholes are disallowed.
You can assume that the number `n` fits into the standard `int` type of your language.
Conversely, if that standard `int` type implements arbitrary-precision integers, you must support (in theory) an arbitrarily large `n`.
## Test cases
```
#1## -> ##1#
##4## -> #4###
1####1 -> ####11
1####2 -> ##21##
#026### -> 26####0
#000### -> #000###
###82399 -> ##82399#
51379#97 -> #9751379
#98##### -> ###98###
#######4## -> #4########
60752#1183 -> 8360752#11
####99366800## -> 366800######99
########9##### -> ###9##########
91#####515694837 -> 1#####5156948379
###6114558###### -> #6114558########
######219088736090042#### -> 9088736090042##########21
#46055080150577874656291186550000138168########### -> 0138168############4605508015057787465629118655000
568375993099127531613012513406622393034741346840434468680494753262730615610086255892915828812820699971764142551702608639695081452206500085233149468399533981039485419872101852######################3680 -> 99533981039485419872101852######################36805683759930991275316130125134066223930347413468404344686804947532627306156100862558929158288128206999717641425517026086396950814522065000852331494683
```
  
[Answer]
# CJam, 11 bytes
```
q_'#%W%sim>
```
[Try it online!](http://cjam.tryitonline.net/#code=cV8nIyVXJXNpbT4&input=IyMjIyMjMjE5MDg4NzM2MDkwMDQyIyMjIw) or [verify all test cases](http://cjam.tryitonline.net/#code=cU4vewpRXycjJVclc2ltPgpOfWZRCg&input=IzEjIwojIzQjIwoxIyMjIzEKMSMjIyMyCiMwMjYjIyMKIzAwMCMjIwojIyM4MjM5OQo1MTM3OSM5NwojOTgjIyMjIwojIyMjIyMjNCMjCjYwNzUyIzExODMKIyMjIzk5MzY2ODAwIyMKIyMjIyMjIyM5IyMjIyMKOTEjIyMjIzUxNTY5NDgzNwojIyM2MTE0NTU4IyMjIyMjCiMjIyMjIzIxOTA4ODczNjA5MDA0MiMjIyM).
Note that this won't work for the last two test cases, since the involved numbers don't fit into 64 bits.
### How it works
```
q_          e# Read all input and push it twice.
  '#%       e# Split at runs of '#'.
     W%     e# Reverse the resulting array.
       si   e# Cast to string, then to int.
         m> e# Rotate the original input that many places to the right.
```
[Answer]
# Julia, ~~71~~ 65 bytes
```
s->join(circshift([s...],maximum(parse,split(s*s,"#",keep=1<0))))
```
This is an anonymous function that accepts a string and returns a string. To call it, assign it to a variable.
We append the input to itself, split it into an array with `#` as the separator, parse each integer, and take the maximum. This defines the number of times we shift the string to the right. We splat the string into a `Char` array, shift, and `join` it back together.
[Answer]
# Python, 66 bytes
```
lambda l:(2*l)[-int(''.join(l.split('#')[::-1]))%len(l):][:len(l)]
```
[Answer]
# Retina, ~~65~~ ~~57~~ 49
```
(\d*)#*(\d+)
$2$1 $0
^\d+
$*
+`1 (.*)(.)
 $2$1
<space>
```
Saved 8 bytes thanks to Martin!
[Try it Online!](http://retina.tryitonline.net/#code=KFxkKikjKihcZCspCiQyJDEgJDAKXlxkKwokKgorYDEgKC4qKSguKQogJDIkMQogCg&input=MSMjIyMy)
Note that this will time out / run out of memory for the very large test cases online, and on most sane machines, for some of the larger ones.
This takes the last number in the string and the first or no number in the string and puts them in front of the string. Then it converts that combined number to unary and repeatedly rotates while dropping a unary digit.
[Answer]
# Jelly, ~~12~~ 10 bytes
```
ẋ2~ṣ0‘ḌṂṙ@
```
[Try it online!](http://jelly.tryitonline.net/#code=4bqLMn7huaMw4oCY4biM4bmC4bmZQA&input=&args=IiMjIyMjIzIxOTA4ODczNjA5MDA0MiMjIyMi) or [verify all test cases](http://jelly.tryitonline.net/#code=4bqLMn7huaMw4oCY4biM4bmC4bmZQArDh-KCrGrigbc&input=&args=IiMxIyMiLCIjIzQjIyIsIjEjIyMjMSIsIjEjIyMjMiIsIiMwMjYjIyMiLCIjMDAwIyMjIiwiIyMjODIzOTkiLCI1MTM3OSM5NyIsIiM5OCMjIyMjIiwiIyMjIyMjIzQjIyIsIjYwNzUyIzExODMiLCIjIyMjOTkzNjY4MDAjIyIsIiMjIyMjIyMjOSMjIyMjIiwiOTEjIyMjIzUxNTY5NDgzNyIsIiMjIzYxMTQ1NTgjIyMjIyMiLCIjIyMjIyMyMTkwODg3MzYwOTAwNDIjIyMjIiwiIzQ2MDU1MDgwMTUwNTc3ODc0NjU2MjkxMTg2NTUwMDAwMTM4MTY4IyMjIyMjIyMjIyMiLCI1NjgzNzU5OTMwOTkxMjc1MzE2MTMwMTI1MTM0MDY2MjIzOTMwMzQ3NDEzNDY4NDA0MzQ0Njg2ODA0OTQ3NTMyNjI3MzA2MTU2MTAwODYyNTU4OTI5MTU4Mjg4MTI4MjA2OTk5NzE3NjQxNDI1NTE3MDI2MDg2Mzk2OTUwODE0NTIyMDY1MDAwODUyMzMxNDk0NjgzOTk1MzM5ODEwMzk0ODU0MTk4NzIxMDE4NTIjIyMjIyMjIyMjIyMjIyMjIyMjIyMjMzY4MCI).
### Background
Say the input is `51379#97`.
By repeating the string twice (`51379#9751379#97`), we can make sure that it will contain a contiguous representation of the number.
Next, we apply bitwise NOT to all characters. This attempts to cast to int, so **'1'** gets evaluated to **1**, then mapped to **~1 = -2**. On failure (`#`), it returns **0**.
For our example, this gives
```
[-6, -2, -4, -8, -10, 0, -10, -8, -6, -2, -4, -8, -10, 0, -10, -8]
```
Next, we split at zeroes to separate the part that encodes the number from the rest.
```
[[-6, -2, -4, -8, -10], [-10, -8, -6, -2, -4, -8, -10], [-10, -8]]
```
Bitwise NOT maps **n** to **-n - 1**, so we increment each to obtain **-n**.
```
[[-5, -1, -3, -7, -9], [-9, -7, -5, -1, -3, -7, -9], [-9, -7]]
```
Next, we convert each list from base 10 to integer.
```
[-51379, -9751379, -97]
```
The lowest number is the negative of the one we're searching for. Since Jelly list rotation atom `ṙ` rotates to the *left*, this avoid multiplying by **-1** to rotate to the right.
### How it works
```
ẋ2~ṣ0‘ḌṂṙ@  Main link. Input: S (string)
ẋ2          Repeat the string twice.
  ~         Apply bitwise NOT to all characters.
            This maps 'n' to ~n = -(n+1) and '# to 0.
   ṣ0       Split at occurrences of zeroes.
     ‘      Increment all single-digit numbers.
      Ḍ     Convert each list from base 10 to integer.
       Ṃ    Take the minimum.
        ṙ@  Rotate S that many places to the left.
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), ~~28~~ ~~25~~ ~~17~~ 16 bytes
```
!G1Y4XXPZcXvUYS!
```
*8 bytes less borrowing Dennis' idea of splitting the array and reversing the order of the pieces*
The two last test cases don't work because the number is too large.
*EDIT (May 20, 2016) The code in the link uses `Xz` instead of `Xv`, owing to recent changes in the language.*
[**Try it online!**](http://matl.tryitonline.net/#code=IUcxWTRYWFBaY1h6VVlTIQ&input=JyMjIyMjIzIxOTA4ODczNjA5MDA0MiMjIyMn)
```
!         % take implicit input: string. Transpose into column char array
G         % push input string again
1Y4       % predefined literal '\d' (for regexp)
XX        % match regexp. Gives cell array with 1 or 2 strings
P         % flip that array
ZcXv      % join the strings in that array, without spaces
U         % convert to number
YS        % rotate the transposed input that many times
!         % put back into row form (string). Implicitly display
```
[Answer]
## PowerShell, 153 bytes
(But see the Extra Credit section, below)
```
param($a)$d=[System.collections.arraylist][char[]]$a;for($b=+("$a$a"-split"#"-ne'')[1];$b;$b--){$r=$d[-1];$d.removeAt($d.Count-1);$d.insert(0,$r)}-join$d
```
PowerShell doesn't have the concept of "shifting" an array, so I had to roll my own solution. Will take a *long* time for larger numbers, but it should eventually complete anything that fits in a 32-bit int.
Takes input `$a`, and sets a new variable `$d` as a [[System.Collections.ArrayList]](https://msdn.microsoft.com/en-us/library/system.collections.arraylist(v=vs.110).aspx) object. This is done because, technically, arrays in PowerShell are immutable (further explained below in Extra Credit), and thus don't support arbitrary insertions or removals, which is needed for shifting. Then, we enter a `for` loop.
The initial condition is a trick I found -- if we concatenate the input together, split on `#`, and ignore empties, the second element of the resulting array will be equal to our number, regardless of wrapping. We set that to `$b`, and decrement `$b` each time until it's zero.
Each iteration, we set helper `$r` as the last element in the arraylist, remove that last element, and then insert the element onto the front ... effectively "shifting" the array to the right by one element.
Finally, we simply output with `-join$d` so that it's concatenated into one string.
---
### Extra Credit
If the problem was shifting the array *left* instead of *right*, we can do it significantly shorter using [*multiple assignment*](https://technet.microsoft.com/en-us/library/hh847875(v=wps.620).aspx). Basically, "If the assignment value contains more elements than variables, all the remaining values are assigned to the last variable."
In essence, this means something like `$c=@(1,2,3)` and `$a,$b=$c`  
will have `$a=1` an int and `$b=@(2,3)` an array.
### PowerShell, 90 bytes, does a left shift instead of a right shift
```
param($a)$b=+("$a$a"-split"#"-ne'')[1];$a=[char[]]$a;for(;$b;$b--){$r,$a=$a;$a+=$r}-join$a
```
Here we once again take input, and set `$b` as above. We re-cast `$a` as a char-array, and then enter the same `for` loop as above. This time, though, we've not needed to support arbitrary removal/insertion, so we don't need to use the costly `[System.Collections.ArrayList]` object, nor the expensive method calls. Instead we simply set `$r` to be the first element of `$a`, and the remaining elements are re-saved in `$a`. Then we `+=` to tack it back on to the end.
*(As I said, PowerShell arrays are technically immutable, but the `+=` operator here is overloaded - it takes an array and another object, mushes them together (technical term) into a new array, returns that and saves it as the variable name, and destroys the original array. Functionally, we've just added an element to the end of the array, but technically (and from a memory/garbage-cleanup perspective, etc.) it's a brand-new array. This can obviously become a costly operation if the array is large or complex. The flipside is that, since arrays are immutable, indexing into them or iterating over them is very cheap.)*
Output remains the same action, with a `-join` statement to turn it into a single string.
[Answer]
## Seriously, 21 bytes
```
,;;+'#@s`≈`MM@#@`/`nΣ
```
[Try it online!](http://seriously.tryitonline.net/#code=LDs7KycjQHNg4omIYE1NQCNAYC9gbs6j&input=JzEjIyMjMic)
Warning: this solution is very inefficient, so the larger test cases will time out on TIO. Use the local interpreter.
Explanation:
```
,;;+'#@s`≈`MM@#@`/`nΣ
,;;+                   make 3 copies of input, and concatenate two of them
    '#@s               split on #s
        `≈`MM          convert strings to ints, take maximum
             @#@       explode final copy of input
                `/`n   rotate to the right n times
                    Σ  join
```
[Answer]
# Mathematica, 69 Bytes
```
#~StringRotateRight~ToExpression[""<>Reverse@TextCases[#,"Number"]]&
```
Find sequences of numbers in the, if there are 2 then their order needs to be reversed. Concatenate the strings (if it's only one it just returns the number string). Convert string to numeric and rotate the string that number of times.
[Answer]
# Pyth, ~~22~~ 14 bytes
```
.>zs-.<zxz\#\#
```
[Try it here!](http://pyth.herokuapp.com/?code=.%3Ezs-.%3Czxz%5C%23%5C%23&input=%23026%23%23%23&test_suite=1&test_suite_input=%231%23%23%0A%23%234%23%23%0A1%23%23%23%231%0A1%23%23%23%232%0A%23026%23%23%23%0A%23000%23%23%23%0A%23%23%2382399%0A51379%2397%0A%2398%23%23%23%23%23%0A%23%23%23%23%23%23%234%23%23%0A60752%231183%0A%23%23%23%2399366800%23%23%0A%23%23%23%23%23%23%23%239%23%23%23%23%23%0A91%23%23%23%23%23515694837%0A%23%23%236114558%23%23%23%23%23%23%0A%23%23%23%23%23%23219088736090042%23%23%23%23%0A568375993099127531613012513406622393034741346840434468680494753262730615610086255892915828812820699971764142551702608639695081452206500085233149468399533981039485419872101852%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%233680&debug=1)
### Explanation
```
.>zs-.<zxz\#\#    # z=input
     .<z          # rotate z left by
        xz\#      # index of the first occurence of a hash
                  # this ensures that the integer is not wrapped around the end
    -       \#    # filter all hashes out
   s              # cast to an integer, also removes leading zeroes
.>z               # do the final roation of the input string and print it
```
This works for all testcases and also almosts finishes instantly for the very big numbers.
[Answer]
# JavaScript (ES6) 66
For once, the stupid negative `%` of javascript for negative numbers come useful
```
z=>(z+z).substr(-(l=z.length,[a,b]=z.match(/\d+/g),b?b+a:a)%l-l,l)
```
[Answer]
# Pyth, 10 bytes
```
.>zss_cz\#
```
[Try it online.](https://pyth.herokuapp.com/?code=.%3Ezss_cz%5C%23&input=%23%23%23%23%23%23219088736090042%23%23%23%23&debug=0) [Test suite.](https://pyth.herokuapp.com/?code=.%3Ezss_cz%5C%23&test_suite=1&test_suite_input=%231%23%23%0A%23%234%23%23%0A1%23%23%23%231%0A1%23%23%23%232%0A%23026%23%23%23%0A%23000%23%23%23%0A%23%23%2382399%0A51379%2397%0A%2398%23%23%23%23%23%0A%23%23%23%23%23%23%234%23%23%0A60752%231183%0A%23%23%23%2399366800%23%23%0A%23%23%23%23%23%23%23%239%23%23%23%23%23%0A91%23%23%23%23%23515694837%0A%23%23%236114558%23%23%23%23%23%23%0A%23%23%23%23%23%23219088736090042%23%23%23%23%0A%2346055080150577874656291186550000138168%23%23%23%23%23%23%23%23%23%23%23%0A568375993099127531613012513406622393034741346840434468680494753262730615610086255892915828812820699971764142551702608639695081452206500085233149468399533981039485419872101852%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%233680&debug=0)
This is a translation of [Dennis' CJam answer](https://codegolf.stackexchange.com/a/74106/30164). I'm making it a community wiki, since I didn't come up with it.
### Explanation
```
      cz\#   split input at #
     _       reverse
    s        join
   s         cast to integer
.>z          rotate input right
```
[Answer]
## JavaScript (ES6), ~~67~~ 64 bytes
```
s=>(l=s.length,s+s).substr(l-s.split(/#+/).reverse().join``%l,l)
```
Another port of Dennis's CJam answer.
Edit: Saved 3 bytes by appropriating the part of edc65's answer that he didn't draw attention to.
[Answer]
# Perl 5, 41 bytes
39 bytes plus two for the `-lF` flags (`-M5.01` is free): `perl -lF -M5.01 script.pl`
```
/#+/;map{unshift@F,pop@F}1..$'.$`;say@F
```
Explanation:
* `-lF` reads the input, removes the trailing newline, puts the remainder into the string `$_`, splits it up into characters, and puts that split into the array `@F`.
* `/#+/` finds the first string of `#`s in `$_` and sets `$`` equal to the stuff before it and `$'` equal to the stuff after it. If `$`` is empty then `$'` may contain more `#`s. However, `$'.$`` is a string whose initial substring is the number of times to rotate the array.
* Now we build the list `1..$'.$``, which treats `$'.$`` as an integer and thus numifies it, which strips any final `#`s, so the list is from `1` to the number of times to rotate the array.
* For each element in that list, we rotate the array (`pop` the last element and `unshift` it onto the beginning).
* Then `say` all the elements of the rotated array.
[Answer]
# Ruby - ~~68~~ ~~72~~ 70 bytes
```
s=ARGV[0]
p s.split(//).rotate(-(s+s).scan(/\d+/).map(&:to_i).max)*""
```
* `split` converts string into an array
* `(s+s).scan(/\d+/)` concatenate string to itself and get an array of numbers (as strings)
* `map(&:to_i)` convert strings to ints
* `max` pick the largest int
* `rotate` `max` times
* `*""` convert the array back into a string (shorthand for `join`)
Usage : `ruby scriptname.rb "[string]"`
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~14~~ 13 bytes
Well, the code is very unlikely to terminate for the numbers bigger than 100000, but if you're patient enough, there will be an output :). Code:
```
'#¡rJ¹sF¤rS\J
```
Explanation:
```
'#¡             # Split the input on '#'
   r            # Reverse the stack
    J           # Join the stack
     ¹          # Take the first input
      s         # Swap with the number
       F        # For N in range(0, number), do...
        ¤       #   Obtain the last character
         r      #   Reverse the stack
          S     #   Split everything to individual characters
           \    #   Delete the last character
            J   #   Join the stack
```
[Try it online!](http://05ab1e.tryitonline.net/#code=JyPCoXJKwrlzRsKkclNcSg&input=Izk4IyMjIyM)
Uses **CP-1252** encoding
[Answer]
**VBSCRIPT, 82  99 BYTES**
previous code didn't handle cases with number wrapped over the end
```
b=len(a):f=replace(a,"#","/",1,1):c=replace(split(f&f,"/")(1),"#",d) mod b:d=right(a,c)&left(a,b-c)
```
UNGOLFED
```
b=len(a)                                 -a->implicit input, get its length 
f=replace(a,"#","/",1,1)  -replace first instance of # so we can split later
c=replace(split(f&f,"/")(1),"#",d) mod b    -get the number and calc the mod
d=right(a,c)&left(a,b-c)                    -d->implicit output
```
this kinda sucks ... there's probably a better way to do it, even in VBscript 
[Answer]
# Mathematica, ~~73~~ 58 bytes
```
#~StringRotateRight~Max[FromDigits/@StringSplit[#<>#,"#"]]&
```
Much byte.
*15* *bytes* *saved* *thanks* *to* *IPoiler*
[Answer]
## Matlab(73)
```
  @(a)regexprep(a,'(\d*)#*(\d*)#*','${circshift($0,[0 str2num([$2 $1])])}')
```
* This is using another approach that i wonder if @luis used it, because refering to his description there is some points in common while (un)?fortunately i dont understand the cropped Matl language.
[Answer]
## matlab~~(86)~~72
```
 @(n)circshift(n,[0 str2num(circshift(n(n~='#'),[0,-find(n=='#',1)+1]))])
```
* The function totates the string two times, once for integer extraction, second for the desired task, it doesnt take too much time because matlab proceeds to rotate by `(Dim)modulus(Length)` to the exception that it falls in segmentation failure for bigger ranges.
* Will struggle how to golf it more ....
---
## (86)
```
  @(n)circshift(n,[0 str2num([strtok(n(find(n=='#',1,'last'):end),'#') strtok(n,'#')])])
```
* The difference between this function and the previous, this one does concatenate two distant occurences of integers way backwards, while the first one just rotates it.
]