# Jimmy needs a new pair of shoes!

Jimmy has had a busy last week with all these platforms and ropes, and poor Jimmy doesn't even have legs or feet to stand on!

Your job is to take a string containing multiple Jimmys and give them legs and shoes!

Get input in the form of a Jimmy String

Jimmy String => /o\ /o\ /o\

containing only /o\ and

give each Jimmy in the input a pair of feet that look like this:

 /o\
_/ \_


Turn the inputed floating head Jimmy string into Jimmy with feet string, like so:

// Input

/o\   /o\          /o\

// Output

/o\   /o\          /o\
_/ \_ _/ \_        _/ \_


If 2 Jimmys are close together they must move over to make room, Jimmys will always move towards the right to make room for other Jimmys.

// Input

/o\/o\

// Output

/o\  /o\
_/ \__/ \_


Other Jimmys that are further away must not be moved unless necessary

// Input

/o\/o\      /o\

// Output

/o\  /o\   /o\
_/ \__/ \_ _/ \_

// Input

/o\/o\    /o\

// Output

/o\  /o\  /o\
_/ \__/ \__/ \_


Standard rules and loopholes apply,

This is code-golf, so may the shortest answer win.

• Suggested test case: /o\<sp>/o\<sp><sp><sp><sp><sp><sp><sp><sp>/o\/o\, my current implementation fails because it moves the last two Jimmies towards the left instead of right.. All of your test cases succeed, though. Jul 25 '19 at 8:19

# Python 2, 131120115114121 118 bytes

o=1;W=[]
for g in map(len,input().split('/o\\')):W+=[' '*(g-o)];o=max(o-g,0)+2
for q in' /o\ ','_/ \_':print q.join(W)


Try it online!

4 bytes thx to movatica; 10 bytes lost for bug fix.

• o+=2-len(g) saves you a byte Jul 10 '19 at 20:17
• 118 bytes Jul 10 '19 at 20:29
• @movatica: there was a bug, but it was offset by your edits :). Jul 10 '19 at 20:47

# Charcoal, 28 bytes

 Ｆ⌕Ａθ/«Ｊ∧ι⊖ι¹ＷＫＫ→Ｐ_/ \_Ｍ↗/o\


Try it online! Link is to verbose version of code. Explanation:

 

Print a space to defeat Charcoal's automatic left margin.

Ｆ⌕Ａθ/«


Loop over all of the left arms.

Ｊ∧ι⊖ι¹


Jump to the desired left foot location. Note that Charcoal has no problem drawing at (-1, 1), but the question does not allow that, so we have to take care to avoid drawing at negative positions.

ＷＫＫ→


Move past any existing output.

Ｐ_/ \_Ｍ↗/o\


Output the feet and then move to output the Jimmy.

# Ruby-p, 77 75 bytes

The "don't move Jimmy if not needed" rule was quite an ordeal to work around but I think it worked out quite well. Shorter than Python by quite a bit (at time of writing), at least.

-2 bytes from recursive.

r=/(\\ ?|^)(\S+) ?/
gsub(r){"#$1 #$2"}while~r
puts$_ gsub(/ .o. ?/,'_/ \_')  Try it online! • Could you use \S+ in place of \/\S*? Jul 11 '19 at 3:32 # PowerShell, 96 bytes ($o=$args-split'/o.'|%{' '*($w=($l+=$_.Length-1)*($l-gt0));$l-=$w+1})-join' /o\ '$o-join'_/ \_'


Try it online!

Unrolled:

$o=$args-split'/o.'|%{
$len +=$_.Length-1
$width =$len*($len-gt0) # len or 0, if len < 0 ' '*$width
$len -=$width+1
}
# $o is array of space strings now$o-join' /o\ '
$o-join'_/ \_'  # Python 2, 152148 140 bytes o=[-4] for i,c in enumerate(input()):o+=[max(i,o[-1]+5)]*('/'==c) for s in' /o\ ','_/ \_':print''.join('%*s'%(b-a,s)for a,b in zip(o,o[1:]))  Try it online! # Retina, 40 37 bytes \+(^|\S.)(/\S*) ?$1 \$2
/o. ?
_/ \_


Try it online!

Thanks to Value Ink for golfing off 3 bytes.

• Enjoy your new shoes! Jul 10 '19 at 14:11
• Well, tried to pretend these challenges don't exists for a while. (No relation to that Jimmy.) Jul 10 '19 at 14:14
• I believe the pattern match I used in my Ruby answer (\\ ?|^)(/\S*) ? is shorter than the one in your first line and should give the same results (probably; I don't know Retina at all) Jul 10 '19 at 22:07

# Stax, 292824 25 bytes

¢▄▌ß╙EVäN»0►,δñï◙,Θ╙BÅhΓ?


Run and debug it

There was a bug in the 24 byte solution that caused some off-by-1 errors in some cases.

# JavaScript (ES6), 107 bytes

s=> /o\\
_/ \\_.replace(/.*/g,j=>s.split(/.o./).map(s=>s.slice(n,l=s.length,n=n>l?n-l+2:2),n=1).join(j))


Try it online!

# MATLAB, 111 bytes

Try it online

function J(s)
s=[' ' s];s=replace(s,{'\/','\ /'},'\  /');for k=find(s=='o')
o(k-2:k+2)='_/ \_';end
char(s,o)
`