Jimmy needs a new pair of shoes!

12

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.

Quinn

Posted 2019-07-10T13:03:21.030

Reputation: 1 153

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. – Kevin Cruijssen – 2019-07-25T08:19:53.523

Answers

3

Python 2, 131 120 115 114 121 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.

Chas Brown

Posted 2019-07-10T13:03:21.030

Reputation: 8 959

1o+=2-len(g) saves you a byte – movatica – 2019-07-10T20:17:11.233

118 bytes – movatica – 2019-07-10T20:29:48.767

1@movatica: there was a bug, but it was offset by your edits :). – Chas Brown – 2019-07-10T20:47:41.307

3

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!

Value Ink

Posted 2019-07-10T13:03:21.030

Reputation: 10 608

Could you use \S+ in place of \/\S*? – recursive – 2019-07-11T03:32:12.303

3

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'_/ \_'

mazzy

Posted 2019-07-10T13:03:21.030

Reputation: 4 832

2

Python 2, 152 148 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!

TFeld

Posted 2019-07-10T13:03:21.030

Reputation: 19 246

2

Retina, 40 37 bytes

\+`(^|\S.)(/\S*) ?
$1 $2
 /o. ?
_/ \_

Try it online!

Thanks to Value Ink for golfing off 3 bytes.

jimmy23013

Posted 2019-07-10T13:03:21.030

Reputation: 34 042

4Enjoy your new shoes! – Quinn – 2019-07-10T14:11:43.727

1Well, tried to pretend these challenges don't exists for a while. (No relation to that Jimmy.) – jimmy23013 – 2019-07-10T14:14:28.897

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) – Value Ink – 2019-07-10T22:07:55.947

2

Charcoal, 28 bytes

 F⌕Aθ/«J∧ι⊖ι¹WKK→P_/ \_M↗/o\

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

 

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

F⌕Aθ/«

Loop over all of the left arms.

J∧ι⊖ι¹

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.

WKK→

Move past any existing output.

P_/ \_M↗/o\

Output the feet and then move to output the Jimmy.

Neil

Posted 2019-07-10T13:03:21.030

Reputation: 95 035

2

Stax, 29 28 24 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.

recursive

Posted 2019-07-10T13:03:21.030

Reputation: 8 616

1

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!

Arnauld

Posted 2019-07-10T13:03:21.030

Reputation: 111 334