49
5
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
So the dots are optional, spaces can be there instead? – Rɪᴋᴇʀ – 2016-03-03T22:17:42.700
Are trailing spaces allowed in the output? – mbomb007 – 2016-03-03T22:32:44.413
Can the input be a 2D char array, with each shifty guy on a line? – Luis Mendo – 2016-03-03T22:34:20.353
2@RikerW - Yes. mbomb - Yes, that's mentioned. Don - No. – Calvin's Hobbies – 2016-03-03T22:46:29.487
15Watch Shifty Eyes become an esoteric language... – cat – 2016-03-04T00:58:12.613
You wrote "Note that with these rules,
I
is always shifted first". Now I get it but it's not so clear, asI
cannot move at all untili
is moved – edc65 – 2016-03-04T09:10:54.690@Helka You should put "Given a string of shifty-guy... and right the skies" in verse form :-) – Luis Mendo – 2016-03-04T11:42:01.193
@edc65 Clarified a bit. – Calvin's Hobbies – 2016-03-04T17:59:03.087