| Bytes | Lang | Time | Link |
|---|---|---|---|
| 029 | Raku Perl 6 rakudo | 250415T155607Z | xrs |
| 002 | Japt N | 200815T081652Z | Shaggy |
| 020 | CASIO BASIC CASIO fx9750GIII | 250409T142039Z | madeforl |
| 044 | AWK | 250327T205835Z | xrs |
| 260 | SAKO | 250327T175732Z | Acrimori |
| 006 | Uiua | 240130T214831Z | Joao-3 |
| nan | 240130T052017Z | RARE Kpo | |
| 002 | Thunno 2 | 230725T122628Z | The Thon |
| 070 | Desmos | 220503T165221Z | naffetS |
| 018 | K ngn/k | 220503T143236Z | doug |
| 089 | PHP | 220418T224132Z | Steve |
| 003 | Vyxal | 220418T004520Z | naffetS |
| 1678 | [Taxi] | 200817T154523Z | Engineer |
| 040 | Ruby | 200815T084621Z | Razetime |
| 2925 | K ngn/k | 220418T091158Z | zoomlogo |
| 058 | Lua 5.1 | 220418T033108Z | SurfedZ |
| 019 | Factor | 220416T123257Z | chunes |
| 014 | GolfScript | 200915T161524Z | 2014MELO |
| 010 | noncompeting L=tn | 200821T102045Z | Adam |
| 028 | Golfscript | 200819T192115Z | FedeWar |
| 106 | SimpleTemplate 0.84 | 200818T115755Z | Ismael M |
| 063 | [Excel/Google Sheets] | 200818T042428Z | Conor Ja |
| 057 | Haskell | 200817T234001Z | AZTECCO |
| 004 | APL Dyalog Extended | 200817T183411Z | Adá |
| 011 | V vim | 200817T162251Z | nmjcman1 |
| 051 | R | 200815T121054Z | Dominic |
| 047 | JavaScript V8 | 200817T130001Z | Yaroslav |
| 039 | Python 3 | 200815T201952Z | Jonathan |
| 006 | CJam | 200816T035351Z | Ethan Ch |
| 043 | PHP | 200816T083742Z | Hackinet |
| 004 | Pyth | 200815T100141Z | Mukundan |
| 045 | Jelly | 200815T214919Z | Jonathan |
| 040 | Python 3.8 prerelease | 200816T004234Z | d01 |
| 034 | Ruby nl | 200816T004446Z | Dingus |
| 055 | C gcclm | 200815T113139Z | Noodle9 |
| 036 | JavaScript ES6 | 200815T074849Z | Arnauld |
| 066 | Java JDK | 200815T152128Z | Olivier |
| 061 | Scala | 200815T150758Z | user |
| 007 | APL+WIN | 200815T073507Z | Graham |
| 026 | Perl 5 + pl | 200815T094439Z | Dom Hast |
| 047 | Python 3 | 200815T142508Z | Noodle9 |
| 009 | Charcoal | 200815T105520Z | Neil |
| 004 | 05AB1E | 200815T104033Z | Mukundan |
| 029 | Retina 0.8.2 | 200815T103359Z | Neil |
| 003 | MATL | 200815T101852Z | Mukundan |
| 089 | Io | 200815T072625Z | user9649 |
| 043 | Wolfram Language Mathematica | 200815T074200Z | ZaMoC |
| 011 | J | 200815T071238Z | xash |
| 057 | Python 3 | 200815T064741Z | Manish K |
| 011 | Keg | 200815T042228Z | lyxal |
Raku (Perl 6) (rakudo), 29 bytes
{+$^a.comb.rotate(-$^b).join}
{
+ # coerce int
$^a. # first positional
comb. # split digits
rotate(- # rotate right
$^b) # by second positional
.join # put back together
}
Japt -N, 2 bytes
Takes n as a string as the first input and V=m as an integer or string as the second input, outputs an integer.
Prepend s or ì for +1 byte if we have to take both as integers.
éV
CASIO BASIC (CASIO fx-9750GIII), 20 bytes
?→Str 1
?→M
Exp(StrRotate(Str 1,-M)
works wonderfully
AWK, 44 bytes
$0=int(substr($1$1,(y=length($1))-$2%y+1,y))
$0= # set output
int( # catch leading zeros
substr($1$1, # double string
(y=length($1)) # number of digits
-$2%y # where to start
+1, # one-indexed
y)) # till length of original
SAKO, 260 bytes
CALKOWITE:*L,I,K
BLOK(9):L
CZYTAJWIERSZ:L
CZYTAJ:M
I=-1
1)I=I+1
GDYL(I+1)=58:2,INACZEJ1
2)GDYI=0:4,INACZEJ3
3)GDYM=0:4,INACZEJ5
**5)C=L(K)
L(K)=L(K+1)
L(K+1)=C
POWTORZ:K=I-1(-1)0
POWTORZ:J=1(1)M
4)C=0
*)C=C×10+L(K)-48
POWTORZ:K=0(1)I
DRUKUJ(9,0):C
STOP1
KONIEC
SAKO is not a language made or fit for string manipulation.
Explanation:
- We read a number
Las a string, for ease of rotation. - We read
Mas a normal number. - We find where is the last digit of
Lvia a loop and stre it inI. (What index) - Now
2if statements to check eitherIorMis equal to0. If this code is possible to shorten, I would guess that this part is unoptimal. - Now he fun part: rotation. Using
2nested loops. - We turn the string into a number.
- And print it.
I didn't make a subroutine version, as it would be probably longer, because while it makes no difference to take a number or a string from STDIN, it would be unreasonable to take a string as an argument when a task is to rotate a number.
awk
awk '($++NF=(__=$++_)*(_!_)^((__=length(__))-$(_+_)%__)%((_!_)^__-_--))' FS=,
123 1 => 312 312
123 2 => 231 231
123 3 => 123 123
123 4 => 312 312
1 637 => 1 1
10 1 => 1 1
100 2 => 1 1
10 2 => 10 10
110 2 => 101 101
123 0 => 123 123
9998 2 => 9899 9899
Thunno 2, 2 bytes
ẒN
Explanation
# Implicit input
Ẓ # Rotate right that many times
N # Convert to integer to remove leading zeros
# Implicit output
Desmos, 76 70 bytes
f(n,m)=mod(n,t)10^d/t+floor(n/t)
d=floor(log(n+0^n))+1
t=10^{mod(m,d)}
Port of R answer.
-6 bytes thanks to Aiden Chow
PHP, 89 bytes
list($n,$m)=explode(",",$argn);while($m--){$n=$n[-1].substr($n,0,-1);}echo ltrim($n,"0");
Explanation: A PHP answer that works by looping m times through the given string n moving the last character of n to the beginning of the string.
[Taxi], 1698 1678 bytes
No need to wrap single-byte plan names in quote marks. 0.6% byte reduction!
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to Chop Suey.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Addition Alley.1 is waiting at Starchild Numerology.Go to Starchild Numerology:n 1 l 1 l 1 l 2 l. Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to The Underground.Go to Chop Suey:n 1 r 2 r.[1]Switch to plan 2 if no one is waiting.Pickup a passenger going to Narrow Path Park.Go to Narrow Path Park:n 1 l 1 r 1 l.Go to Chop Suey:e 1 r 1 l 1 r.Switch to plan 1.[2]Go to Narrow Path Park:n 1 l 1 r 1 l.Switch to plan 3 if no one is waiting.Pickup a passenger going to Chop Suey.Go to Chop Suey:e 1 r 1 l 1 r.Switch to plan 2.[3]Go to Chop Suey:e 1 r 1 l 1 r.[a]Go to The Underground:s 1 r 1 l.Switch to plan b if no one is waiting.Pickup a passenger going to The Underground.Go to Fueler Up:s.Go to Chop Suey:n 3 r 1 l.Pickup a passenger going to Chop Suey.Switch to plan a.[b]Go to Chop Suey:n 2 r 1 l.[4]Switch to plan 5 if no one is waiting.Pickup a passenger going to Narrow Path Park.Go to Narrow Path Park:n 1 l 1 r 1 l.Go to Chop Suey:e 1 r 1 l 1 r.Switch to plan 4.[5]Go to Narrow Path Park:n 1 l 1 r 1 l.[c]Switch to plan d if no one is waiting.Pickup a passenger going to KonKat's.Go to KonKat's:e 1 r.Pickup a passenger going to KonKat's.Go to Narrow Path Park:n 2 l.Switch to plan c.[d]Go to KonKat's:e 1 r.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s.Pickup a passenger going to The Babelfishery.Go to KonKat's:n.Go to The Babelfishery:s.Pickup a passenger going to Post Office.Go to Post Office:n 1 l 1 r.
I chose to get fired rather than sacrifice the bytes required to return to the garage at the end. I have checked both very long inputs and very long rotations and the net gain is positive so you never run out of gas.
Formatted for legibility and with comments:
[ Pick up the inputs, add 1 to the second, and chop the first into pieces. ]
Go to Post Office:w 1 l 1 r 1 l.
Pickup a passenger going to Chop Suey.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:s 1 l 1 r.
Pickup a passenger going to Addition Alley.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology:n 1 l 1 l 1 l 2 l.
Pickup a passenger going to Addition Alley.
Go to Addition Alley:w 1 r 3 r 1 r 1 r.
Pickup a passenger going to The Underground.
Go to Chop Suey:n 1 r 2 r.
[ Reverse the order the charaters are stored in so we can right-shift instead of left-shift. ]
[1]
Switch to plan 2 if no one is waiting.
Pickup a passenger going to Narrow Path Park.
Go to Narrow Path Park:n 1 l 1 r 1 l.
Go to Chop Suey:e 1 r 1 l 1 r.
Switch to plan 1.
[2]
Go to Narrow Path Park:n 1 l 1 r 1 l.
Switch to plan 3 if no one is waiting.
Pickup a passenger going to Chop Suey.
Go to Chop Suey:e 1 r 1 l 1 r.
Switch to plan 2.
[3]
Go to Chop Suey:e 1 r 1 l 1 r.
[ Loop the required times, rotating the passengers at Chop Suey each time. ]
[a]
Go to The Underground:s 1 r 1 l.
Switch to plan b if no one is waiting.
Pickup a passenger going to The Underground.
Go to Fueler Up:s.
Go to Chop Suey:n 3 r 1 l.
Pickup a passenger going to Chop Suey.
Switch to plan a.
[b]
Go to Chop Suey:n 2 r 1 l.
[ Reverse the character order again. ]
[4]
Switch to plan 5 if no one is waiting.
Pickup a passenger going to Narrow Path Park.
Go to Narrow Path Park:n 1 l 1 r 1 l.
Go to Chop Suey:e 1 r 1 l 1 r.
Switch to plan 4.
[5]
Go to Narrow Path Park:n 1 l 1 r 1 l.
[ Concatenate the passengers at Narrow Path Park. ]
[c]
Switch to plan d if no one is waiting.
Pickup a passenger going to KonKat's.
Go to KonKat's:e 1 r.
Pickup a passenger going to KonKat's.
Go to Narrow Path Park:n 2 l.
Switch to plan c.
[ Convert to a number to remove leading zeros and then back to a string so the Post Office can handle it. ]
[d]
Go to KonKat's:e 1 r.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:s.
Pickup a passenger going to The Babelfishery.
Go to KonKat's:n.
Go to The Babelfishery:s.
Pickup a passenger going to Post Office.
Go to Post Office:n 1 l 1 r.
Ruby, 44 40 bytes
->a,b{a.to_s.chars.rotate(-b).join.to_i}
-4 from Dingus.
Ruby, 19 bytes
->a,b{a.rotate(-b)}
taking a list of digits
Lua 5.1 (58 bytes)
n=n..""for _=1,m do n=n:sub(-1)..n:sub(1,-2)end print(n*1)
GolfScript, 14 bytes
~\`\{1/)\+}\*~
~ # Puts n and m on top of the stack as integers
\`\ # Parses n to string
{1/)\+} # This block goes to the top of the stack without being executed
\* # Executes previous block m times
~ # Parses the answer from string to integer, this removes the leading zeroes
What the block does:
1/ # Parses the string to an array of strings
)\ # Separates the last digit and puts it in the begining
+ # Concatenates them again
(non-competing) L=tn, 10
cα;θ2$cD=0
Explanation (in order of execution):
cα; - Turn first number into a list of digits
2$c - Fetch second number as a number
θ - Shift list from first step by number from second step
D=0 - Drop while equals to zero
It prints result as a string.
Note: The language is in progress and I did add stuff to code golf this. So it is not a competing submission.
Golfscript - 28 bytes
~:a;`{1/)\+}a*1/{(~:b!}do b\
- input:
10450 4 - output:
4501
Explanation
~:a;` # Parses the input "123 3" -> "123" on stack and a = 3
{1/)\+}a* # Pushes the last digit away and rejoins, repeat a times "123" -> "12" "3" -> "3" "12" -> "312" repeat
1/{(~:b!}do b\ # Discard the leading elements until a non-zero element is found
There's room for improvement.
SimpleTemplate 0.84, 106 bytes
This challenge really got my head spinning...
{@fnR N,T}{@forfrom Tto1}{@ifN matches"@(.+)(.)@"M}{@setN"#{M.2}#{M.1}"}{@/}{@/}{@set+N N,0}{@returnN}{@/}
This creates a function R that takes the Number and the amount of Times you want to swap the numbers around.
The way it works is by evaluating if the Number matches a regular expression ({@ifN matches"@(.+)(.)@"M}) and storing the Matched parts.
Then, it reconstructs the number with the last digit at the beginning ({@setN"#{M.2}#{M.1}"}).
To remove leading zeroes, I've simply stored the sum of whatever is the Number with 0, returning it after.
Ungolfed:
It is a lot easier to follow an ungolfed example:
{@fn rotate_n number, times}
{@for i from times to 1}
{@if number matches "@^(.+)(.)$@" matches}
{@set number "#{matches.2}#{matches.1}"}
{@/}
{@/}
{@set+ number number, 0}
{@return number}
{@/}
The i is totally useless there, but removing it is a golfing step.
You can try this on: http://sandbox.onlinephpfunctions.com/code/91d0d49d2f750022e21cc7b1c18e6beec55f9c8b
You can change the values on line 1071.
[Excel/Google Sheets], 63 bytes
With n and m in columns a and b, and this formula in column c
=VALUE(RIGHT(A4, MOD(B4,LEN(A4)))&LEFT(A4,LEN(A4)-MOD(B4,LEN(A4
Haskell, 57 bytes
f n m=read(foldr(\_ y->last y:init y)(show n)[1..m])::Int
f n m= - function expecting two integers
foldr ... [1..m] - folds `m` times..
.. (show n) - starting with `n` converted to string
. (\_ y->last y:init y) - moving the last element in head
read( ... )::Int - convert the result to Int
APL (Dyalog Extended), 4 bytes (SBCS)
Anonymous tacit infix function. Takes string n as right argument and number m as left argument.
⍎-⍛⌽
⍎ execute the result of
-⍛ negating the left argument, then using that to
⌽ cyclically rotate the right argument
V (vim), 11 bytes
Àñ$x0Pñó^0«
Àñ ñ # (M-@)rg number of times
$ # end of line
x # delete character (cut)
0 # beginning of line
P # paste character
ó # (M-s)ubsitute
^0« # ^0\+
# (implicitly) with nothing
R, 51 bytes
function(n,m,p=10^nchar(n))sum(n*p^(0:m))%/%10^m%%p
Numeric solution (that fails for combinations of n & m that cause it to exceed R's numeric range): chains the digits of n, m times (so: 123 => 123123123123 for m=4) and then calculates DIV 10^m (so: 12312312 for m=4) MOD 10^digits(n) (so: 312).
R, 61 53 bytes
Edit: -8 bytes thanks to Giuseppe
function(n,m,N=nchar(n),M=10^(m%%N))n%%M*10^N/M+n%/%M
Text-based function that Rotates by combining the two parts of the number together, so does not go out of numeric range: puts the last (m MOD digits(n)) digits of n first, followed by the other digits of n.
Python 3, 39 bytes
lambda n,m:int(((n*m)[-m:]+n)[:len(n)])
Try it online! Or see the test-suite.
How?
Rotating n right by m is the same as rotating n right by m modulo length n (m%len(n)), which is the concatenation of the last m%len(n) digits with the first len(n)-m%len(n) digits.
A simple slice would give us
lambda n,m:int(n[-m%len(n):]+n[:-m%len(n)])
for 43 bytes. To remove the need for the repeated -m% we can instead concatenate the last m%len(n) digits with all the digits of n and then take the first len(n) digits. This is
lambda n,m:int((n[-m%len(n):]+n)[:len(n)])
for 42 bytes. The n[-m%len(n):] can then be replaced with taking the rightmost m digits of m ns concatenated together, (n*m)[-m:] giving us the 39 byte solution.
CJam, 10 7 6 bytes
Saved 3 bytes by remembering that you can preform most array operations on strings.
-1 byte from @my pronoun is monicareinstate noting that m> takes arguments in either order.
rr~m>~
Explanation:
rr Read two string inputs
~ Parse m to number
m> Rotate n string right m times
~ Parse n to number to remove leading zeros
(implicit) output
Old version, 7 bytes:
q~\sm>~
Explanation:
q~ Take input as a string, evaluate to two numbers
\ Swap order
s Convert n to string
m> Rotate n string right m times
~ Parse n to number to remove leading zeros
(implicit) output
PHP, 45 43 bytes
Saved 2 bytes, realized we can shorten the variable names.
<?=(int)(substr($s,-$n).substr($s,0,-$n))?>
Explanation:
<?= ?> Shorthand for <?php echo ;?>
(int) Typecast string to int, removes 0s from prefix
substr() substr(string,start,[length]), returns part of string,
if range go out of bounds, starts again from the opposite end.
Basically returns part of from a 'circular' string.
Pyth, 4 bytes
v.>z
Explanation
v.>zQ
Q : first line of input evaluated
z : second line of input as string
.> : cyclically rotate second line right by number in first line
v : evaluate to remove leading 0s
Jelly, (4?) 5 bytes
4 if we may accept a list of digits (remove the leading D).
DṙN}Ḍ
How?
DṙN}Ḍ - Link: integer, n; integer, m
D - convert to base ten
} - use m as the input of:
N - negate
ṙ - rotate (n) left by (-m)
Ḍ - convert from base ten
Ruby -nl, 34 bytes
->m{($_*-~m*2)[~~/$/*m,~/$/].to_i}
Takes \$n\$ from STDIN and \$m\$ as an argument. Concatenates \$n\$ \$2(m+1)\$ times, then from this string takes the substring of length \$d\$ (where \$d\$ is the number of digits in \$n\$) that begins \$m(d+1)\$ characters from the end. In the code, $_ is \$n\$ and ~/$/ gives \$d\$.
Example
For \$n=123\$, \$m=2\$:
- Concatenate \$n\$ \$2(m+1)=6\$ times:
123123123123123123 - Count back from the end \$m(d+1)=8\$ characters:
123123123123123123 - Take substring of length \$d=3\$:
123123123123123123
C (gcc)-lm, 65 \$\cdots\$ 56 55 bytes
Saved a byte thanks to ceilingcat!!!
e;f(n,m){for(e=log10(n);m--;)n=n%10*exp10(e)+n/10;m=n;}
Inputs integers \$n\$ and \$m\$.
Base-10 digitally rotates \$n\$ right \$m\$-times and returns it.
JavaScript (ES6), 36 bytes
Expects (m)(n), where n is a string and m is either a string or an integer.
m=>g=n=>m--?g(n%10+n.slice(0,-1)):+n
Java (JDK), 66 bytes
(n,x)->new Long((""+n+n).substring(x=(n=(""+n).length())-x%n,x+n))
APL+WIN, 8 7 bytes
Prompts for n as integer and m as string:
⍎(-⎕)⌽⎕
Python 3, 47 bytes
f=lambda n,m:m and f(n[-1]+n[:-1],m-1)or int(n)
Inputs \$n\$ as a string and \$m\$ as an integer.
Returns rotated \$n\$ as an integer.
Charcoal, 9 bytes
II⭆θ§θ⁻κη
Try it online! Link is to verbose version of code. Explanation:
θ Input `n` as a string
⭆ Map over characters and join
κ Current index
⁻ Subtract
η Input `m`
§ Cyclically indexed into
θ Input `n` as a string
I Cast to integer
I Cast to string
Implicitly print
Conveniently if you try to Subtract an integer and a string then the string gets cast to integer.
05AB1E, 4 bytes
(._ï
Explanation
(._ï
( : get negative of m
._ : rotate n left negative m times
ï : remove leading zeros
Retina 0.8.2, 29 bytes
,.+
$*_
+`(.*)(\d)_
$2$1
^0+
Try it online! Link includes test cases. Takes input as n,m. Explanation:
,.+
$*_
Convert m to unary.
+`(.*)(\d)_
$2$1
Rotate n m times. This is O(m³) because of the way the regex backtracks trying to find a second match. Right-to-left matching, anchoring the match at the start, or rewriting the code to take input as m,n would reduce the time complexity (at a cost of a byte of course).
^0+
Delete leading zeros.
MATL, 3 bytes
YSU
Takes n as a string and m as an integer.
Explanation
YS % Shift first input second input number of times
U % Convert to integer to remove leading 0s
MATL, 5 bytes
ViYSU
This answer takes both the inputs as integers.
Io, 89 bytes
Uses a reduce trick to assign different lines of STDIN to variables.
File standardInput readLines reduce(a,b,a splitAt(-b asNumber)reverse join)asNumber print
Io, 56 bytes
method(a,b,doString(a splitAt(-b asNumber)reverse join))
J, 11 bytes
(".@|.":)~-
How it works
Uses @Bubbler's tacit trick for (F x) G (H y) = (G~F)~H.
(".@|.":)~-
- negate y to shift right
( )~ flip arguments, so ((-y) ".@|. (":x))
": convert x to string
|. shift that by negated y
".@ and convert back to number
Python 3, 61 57 bytes
i=input
n=i()
k=int(i())%len(n)
print(int(n[-k:]+n[:-k]))
Uses string slicing to move the last k digits at the beginning and converts it to an integer to remove the leading zeroes.
-4 bytes thanks to Lyxal
Keg, -hr, 11 bytes
÷(¿|")⑷⅍⑸⅀ℤ
Explained
÷(¿|")⑷⅍⑸⅀ℤ
÷ # Split m into individual numbers
(¿|") # n times, shift the stack right
⑷⅍⑸ # turn each character into a string
⅀ℤ # sum stack and convert to integer. `-hr` prints it as integer
