Shifty-eyes ASCII guys like to shift ASCII Ii
's:
>_> <_< >_< <_>
Given a string of shifty-guys, spaced apart or separate lines, shift the Ii
's side to side, left the wall and right the skies:
Ii
The shortest shifter wins the prize.
Say What?
Write a program or function that takes in a string of an arbitrary list of these four ASCII emoticons, either space or newline separated (with an optional trailing newline):
>_>
<_<
>_<
<_>
For example, the input might be
>_> >_> <_>
or
>_> >_> <_>
(The method you support is up to you.)
Each emoticon performs a different action on the I
and i
characters, which always start like this:
Ii
>_>
shiftsI
to the right by one, if possible, and then shiftsi
to the right by one.<_<
shiftsI
to the left by one, if possible, and then shiftsi
to the left by one, if possible.>_<
shiftsI
to the right by one, if possible, and then shiftsi
to the left by one, if possible.<_>
shiftsI
to the left by one, if possible, and then shiftsi
to the right by one.
I
cannot be shifted left if it is at the left edge of the line (as it is initially), and cannot be shifted right if i
is directly to its right (as it is initially).
i
cannot be shifted left if I
is directly to its left (as it is initially), but can always be shifted right.
Note that with these rules, I
will always remain to the left of i
, and I
is attempted to be shifted before i
for all emoticons.
Your program or function needs to print or return a string of the final Ii
line after applying all the shifts in the order given, using spaces (
) or periods (.
) for empty space. Trailing spaces or periods and a single trailing newline are optionally allowed in the output. Don't mix spaces and periods.
For example, the input
>_> >_> <_>
has output
I...i
because the shifts apply like
start |Ii >_> |I.i >_> |.I.i <_> |I...i
The shortest code in bytes wins. Tiebreaker is higher voted answer.
Test Cases
#[id number]
[space separated input]
[output]
Using .
for clarity.
#0
[empty string]
Ii
#1
>_>
I.i
#2
<_<
Ii
#3
>_<
Ii
#4
<_>
I.i
#5
>_> >_>
.I.i
#6
>_> <_<
Ii
#7
>_> >_<
.Ii
#8
>_> <_>
I..i
#9
<_< >_>
I.i
#10
<_< <_<
Ii
#11
<_< >_<
Ii
#12
<_< <_>
I.i
#13
>_< >_>
I.i
#14
>_< <_<
Ii
#15
>_< >_<
Ii
#16
>_< <_>
I.i
#17
<_> >_>
.I.i
#18
<_> <_<
Ii
#19
<_> >_<
.Ii
#20
<_> <_>
I..i
#21
>_> >_> <_>
I...i
#22
<_> >_> >_> >_> <_> <_<
.I...i
#23
<_> >_> >_> >_> <_> <_< >_< <_< >_<
..Ii
#24
>_> >_< >_> >_> >_> >_> >_> >_> <_> <_> <_<
...I.....i